arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
vban.h
1/*
2 * This file is part of vban.
3 * Copyright (c) 2015 by Benoît Quiniou <quiniouben@yahoo.fr>
4 *
5 * vban is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * vban is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with vban. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
21//
22// MODIFIED by R. Kinnett, https://github.com/rkinnett, 2020
23//
25
26
27#ifndef __VBAN_H__
28#define __VBAN_H__
29
30#include <inttypes.h>
31
32
33#define VBAN_HEADER_SIZE (4 + 1 + 1 + 1 + 1 + 16)
34#define VBAN_STREAM_NAME_SIZE 16
35#define VBAN_PROTOCOL_MAX_SIZE 1464
36#define VBAN_DATA_MAX_SIZE (VBAN_PROTOCOL_MAX_SIZE - VBAN_HEADER_SIZE)
37#define VBAN_CHANNELS_MAX_NB 256
38#define VBAN_SAMPLES_MAX_NB 256
39
40
41
42#define VBAN_PACKET_NUM_SAMPLES 256
43#define VBAN_PACKET_MAX_SAMPLES 256
44#define VBAN_PACKET_HEADER_BYTES 24
45#define VBAN_PACKET_COUNTER_BYTES 4
46#define VBAN_PACKET_MAX_LEN_BYTES (VBAN_PACKET_HEADER_BYTES + VBAN_PACKET_COUNTER_BYTES + VBAN_PACKET_MAX_SAMPLES*2)
47
48
49typedef struct
50{
51 char preamble[4]; /* contains 'V' 'B', 'A', 'N' */
52 uint8_t sample_rate; /* SR index (see SRList above) */
53 uint8_t num_samples; /* nb sample per frame (1 to 256) */
54 uint8_t num_channels; /* nb channel (1 to 256) */
55 uint8_t sample_format; /* mask = 0x07 (nb Byte integer from 1 to 4) */
56 char stream_name[VBAN_STREAM_NAME_SIZE]; /* stream name */
58
59
60typedef struct {
61 VBanHeader* hdr;
62 uint32_t* packet_counter;
63 uint8_t* data_frame;
64 uint8_t packet[VBAN_PROTOCOL_MAX_SIZE];
65 uint16_t packet_data_bytes;
66 uint16_t packet_total_bytes;
67} VBan;
68
69
70
71
72#define VBAN_SR_MASK 0x1F
73#define VBAN_SR_MAXNUMBER 21
74static long const VBanSRList[VBAN_SR_MAXNUMBER]=
75{
76 6000, 12000, 24000, 48000, 96000, 192000, 384000,
77 8000, 16000, 32000, 64000, 128000, 256000, 512000,
78 11025, 22050, 44100, 88200, 176400, 352800, 705600
79};
80
81enum VBanSampleRates
82{
83 SAMPLE_RATE_6000_HZ,
84 SAMPLE_RATE_12000_HZ,
85 SAMPLE_RATE_24000_HZ,
86 SAMPLE_RATE_48000_HZ,
87 SAMPLE_RATE_96000_HZ,
88 SAMPLE_RATE_192000_HZ,
89 SAMPLE_RATE_384000_HZ,
90 SAMPLE_RATE_8000_HZ,
91 SAMPLE_RATE_16000_HZ,
92 SAMPLE_RATE_32000_HZ,
93 SAMPLE_RATE_64000_HZ,
94 SAMPLE_RATE_128000_HZ,
95 SAMPLE_RATE_256000_HZ,
96 SAMPLE_RATE_512000_HZ,
97 SAMPLE_RATE_11025_HZ,
98 SAMPLE_RATE_22050_HZ,
99 SAMPLE_RATE_44100_HZ,
100 SAMPLE_RATE_88200_HZ,
101 SAMPLE_RATE_176400_HZ,
102 SAMPLE_RATE_352800_HZ,
103 SAMPLE_RATE_705600_HZ
104};
105
106
107#define VBAN_PROTOCOL_MASK 0xE0
108enum VBanProtocol
109{
110 VBAN_PROTOCOL_AUDIO = 0x00,
111 VBAN_PROTOCOL_SERIAL = 0x20,
112 VBAN_PROTOCOL_TXT = 0x40,
113 VBAN_PROTOCOL_UNDEFINED_1 = 0x80,
114 VBAN_PROTOCOL_UNDEFINED_2 = 0xA0,
115 VBAN_PROTOCOL_UNDEFINED_3 = 0xC0,
116 VBAN_PROTOCOL_UNDEFINED_4 = 0xE0
117};
118
119#define VBAN_BIT_RESOLUTION_MASK 0x07
120enum VBanBitResolution
121{
122 VBAN_BITFMT_8_INT = 0,
123 VBAN_BITFMT_16_INT,
124 VBAN_BITFMT_24_INT,
125 VBAN_BITFMT_32_INT,
126 VBAN_BITFMT_32_FLOAT,
127 VBAN_BITFMT_64_FLOAT,
128 VBAN_BITFMT_12_INT,
129 VBAN_BITFMT_10_INT,
130 VBAN_BIT_RESOLUTION_MAX
131};
132
133static int const VBanBitResolutionSize[VBAN_BIT_RESOLUTION_MAX] =
134{
135 1, 2, 3, 4, 4, 8,
136};
137
138#define VBAN_RESERVED_MASK 0x08
139
140#define VBAN_CODEC_MASK 0xF0
141enum VBanCodec
142{
143 VBAN_CODEC_PCM = 0x00,
144 VBAN_CODEC_VBCA = 0x10,
145 VBAN_CODEC_VBCV = 0x20,
146 VBAN_CODEC_UNDEFINED_3 = 0x30,
147 VBAN_CODEC_UNDEFINED_4 = 0x40,
148 VBAN_CODEC_UNDEFINED_5 = 0x50,
149 VBAN_CODEC_UNDEFINED_6 = 0x60,
150 VBAN_CODEC_UNDEFINED_7 = 0x70,
151 VBAN_CODEC_UNDEFINED_8 = 0x80,
152 VBAN_CODEC_UNDEFINED_9 = 0x90,
153 VBAN_CODEC_UNDEFINED_10 = 0xA0,
154 VBAN_CODEC_UNDEFINED_11 = 0xB0,
155 VBAN_CODEC_UNDEFINED_12 = 0xC0,
156 VBAN_CODEC_UNDEFINED_13 = 0xD0,
157 VBAN_CODEC_UNDEFINED_14 = 0xE0,
158 VBAN_CODEC_USER = 0xF0
159};
160
161
162/********************************************************
163 * TEXT SUB PROTOCOL *
164 ********************************************************/
165
166#define VBAN_BPS_MASK 0xE0
167#define VBAN_BPS_MAXNUMBER 25
168static long const VBanBPSList[VBAN_BPS_MAXNUMBER] =
169{
170 0, 110, 150, 300, 600,
171 1200, 2400, 4800, 9600, 14400,
172 19200, 31250, 38400, 57600, 115200,
173 128000, 230400, 250000, 256000, 460800,
174 921600,1000000,1500000,2000000, 3000000
175};
176
177#define VBAN_DATATYPE_MASK 0x07
178#define VBAN_DATATYPE_MAXNUMBER 1
179enum VBanDataTypeList
180{
181 VBAN_DATATYPE_8BITS = 0
182};
183
184#define VBAN_STREAMTYPE_MASK 0xF0
185enum VBanStreamType
186{
187 VBAN_TXT_ASCII = 0x00,
188 VBAN_TXT_UTF8 = 0x10,
189 VBAN_TXT_WCHAR = 0x20,
190 VBAN_TXT_UNDEFINED_3 = 0x30,
191 VBAN_TXT_UNDEFINED_4 = 0x40,
192 VBAN_TXT_UNDEFINED_5 = 0x50,
193 VBAN_TXT_UNDEFINED_6 = 0x60,
194 VBAN_TXT_UNDEFINED_7 = 0x70,
195 VBAN_TXT_UNDEFINED_8 = 0x80,
196 VBAN_TXT_UNDEFINED_9 = 0x90,
197 VBAN_TXT_UNDEFINED_10 = 0xA0,
198 VBAN_TXT_UNDEFINED_11 = 0xB0,
199 VBAN_TXT_UNDEFINED_12 = 0xC0,
200 VBAN_TXT_UNDEFINED_13 = 0xD0,
201 VBAN_TXT_UNDEFINED_14 = 0xE0,
202 VBAN_TXT_USER = 0xF0
203};
204
205#endif /*__VBAN_H__*/
Definition vban.h:50
Definition vban.h:60