arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros 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#include <stdint.h>
26#include <string.h>
27
28#ifndef __VBAN_H__
29#define __VBAN_H__
30
31#include <inttypes.h>
32
33
34#define VBAN_HEADER_SIZE (4 + 1 + 1 + 1 + 1 + 16)
35#define VBAN_STREAM_NAME_SIZE 16
36#define VBAN_PROTOCOL_MAX_SIZE 1464
37#define VBAN_DATA_MAX_SIZE (VBAN_PROTOCOL_MAX_SIZE - VBAN_HEADER_SIZE)
38#define VBAN_CHANNELS_MAX_NB 256
39#define VBAN_SAMPLES_MAX_NB 256
40
41
42
43#define VBAN_PACKET_NUM_SAMPLES 256
44#define VBAN_PACKET_MAX_SAMPLES 256
45#define VBAN_PACKET_HEADER_BYTES 24
46#define VBAN_PACKET_COUNTER_BYTES 4
47#define VBAN_PACKET_MAX_LEN_BYTES (VBAN_PACKET_HEADER_BYTES + VBAN_PACKET_COUNTER_BYTES + VBAN_PACKET_MAX_SAMPLES*2)
48
49
50typedef struct
51{
52 char preamble[4]; /* contains 'V' 'B', 'A', 'N' */
53 uint8_t sample_rate; /* SR index (see SRList above) */
54 uint8_t num_samples; /* nb sample per frame (1 to 256) */
55 uint8_t num_channels; /* nb channel (1 to 256) */
56 uint8_t sample_format; /* mask = 0x07 (nb Byte integer from 1 to 4) */
57 char stream_name[VBAN_STREAM_NAME_SIZE]; /* stream name */
59
60
61typedef struct {
62 VBanHeader* hdr;
63 uint32_t* packet_counter;
64 uint8_t* data_frame;
65 uint8_t packet[VBAN_PROTOCOL_MAX_SIZE];
66 uint16_t packet_data_bytes;
67 uint16_t packet_total_bytes;
68} VBan;
69
70
71
72
73#define VBAN_SR_MASK 0x1F
74#define VBAN_SR_MAXNUMBER 21
75static long const VBanSRList[VBAN_SR_MAXNUMBER]=
76{
77 6000, 12000, 24000, 48000, 96000, 192000, 384000,
78 8000, 16000, 32000, 64000, 128000, 256000, 512000,
79 11025, 22050, 44100, 88200, 176400, 352800, 705600
80};
81
82enum VBanSampleRates
83{
84 SAMPLE_RATE_6000_HZ,
85 SAMPLE_RATE_12000_HZ,
86 SAMPLE_RATE_24000_HZ,
87 SAMPLE_RATE_48000_HZ,
88 SAMPLE_RATE_96000_HZ,
89 SAMPLE_RATE_192000_HZ,
90 SAMPLE_RATE_384000_HZ,
91 SAMPLE_RATE_8000_HZ,
92 SAMPLE_RATE_16000_HZ,
93 SAMPLE_RATE_32000_HZ,
94 SAMPLE_RATE_64000_HZ,
95 SAMPLE_RATE_128000_HZ,
96 SAMPLE_RATE_256000_HZ,
97 SAMPLE_RATE_512000_HZ,
98 SAMPLE_RATE_11025_HZ,
99 SAMPLE_RATE_22050_HZ,
100 SAMPLE_RATE_44100_HZ,
101 SAMPLE_RATE_88200_HZ,
102 SAMPLE_RATE_176400_HZ,
103 SAMPLE_RATE_352800_HZ,
104 SAMPLE_RATE_705600_HZ
105};
106
107
108#define VBAN_PROTOCOL_MASK 0xE0
109enum VBanProtocol
110{
111 VBAN_PROTOCOL_AUDIO = 0x00,
112 VBAN_PROTOCOL_SERIAL = 0x20,
113 VBAN_PROTOCOL_TXT = 0x40,
114 VBAN_PROTOCOL_UNDEFINED_1 = 0x80,
115 VBAN_PROTOCOL_UNDEFINED_2 = 0xA0,
116 VBAN_PROTOCOL_UNDEFINED_3 = 0xC0,
117 VBAN_PROTOCOL_UNDEFINED_4 = 0xE0
118};
119
120#define VBAN_BIT_RESOLUTION_MASK 0x07
121enum VBanBitResolution
122{
123 VBAN_BITFMT_8_INT = 0,
124 VBAN_BITFMT_16_INT,
125 VBAN_BITFMT_24_INT,
126 VBAN_BITFMT_32_INT,
127 VBAN_BITFMT_32_FLOAT,
128 VBAN_BITFMT_64_FLOAT,
129 VBAN_BITFMT_12_INT,
130 VBAN_BITFMT_10_INT,
131 VBAN_BIT_RESOLUTION_MAX
132};
133
134static int const VBanBitResolutionSize[VBAN_BIT_RESOLUTION_MAX] =
135{
136 1, 2, 3, 4, 4, 8,
137};
138
139#define VBAN_RESERVED_MASK 0x08
140
141#define VBAN_CODEC_MASK 0xF0
142enum VBanCodec
143{
144 VBAN_CODEC_PCM = 0x00,
145 VBAN_CODEC_VBCA = 0x10,
146 VBAN_CODEC_VBCV = 0x20,
147 VBAN_CODEC_UNDEFINED_3 = 0x30,
148 VBAN_CODEC_UNDEFINED_4 = 0x40,
149 VBAN_CODEC_UNDEFINED_5 = 0x50,
150 VBAN_CODEC_UNDEFINED_6 = 0x60,
151 VBAN_CODEC_UNDEFINED_7 = 0x70,
152 VBAN_CODEC_UNDEFINED_8 = 0x80,
153 VBAN_CODEC_UNDEFINED_9 = 0x90,
154 VBAN_CODEC_UNDEFINED_10 = 0xA0,
155 VBAN_CODEC_UNDEFINED_11 = 0xB0,
156 VBAN_CODEC_UNDEFINED_12 = 0xC0,
157 VBAN_CODEC_UNDEFINED_13 = 0xD0,
158 VBAN_CODEC_UNDEFINED_14 = 0xE0,
159 VBAN_CODEC_USER = 0xF0
160};
161
162
163/********************************************************
164 * SERVICE SUB PROTOCOL *
165 ********************************************************/
166// VBAN SERVICE PROTOCOL definitions
167#define VBAN_PROTOCOL_SERVICE 0x60
168
169// Service Types (format_nbc)
170#define VBAN_SERVICE_IDENTIFICATION 0x00
171#define VBAN_SERVICE_CHATUTF8 0x01
172#define VBAN_SERVICE_RTPACKETREGISTER 0x20
173#define VBAN_SERVICE_RTPACKET 0x21
174
175// Service Functions (format_nbs)
176#define VBAN_SERVICE_FNCT_PING0 0x00
177#define VBAN_SERVICE_FNCT_REPLY 0x80
178
180 uint32_t bitType;
181 uint32_t bitfeature;
182 uint32_t bitfeatureEx;
183 uint32_t PreferedRate;
184 uint32_t MinRate;
185 uint32_t MaxRate;
186 uint32_t color_rgb;
187 uint8_t nVersion[4];
188 char GPS_Position[8]; // Keep empty (all zero)
189 char USER_Position[8];
190 char LangCode_ascii[8];
191 char reserved_ascii[8];
192 char reservedEx[64];
193 char DistantIP_ascii[32];
194 uint16_t DistantPort;
195 uint16_t DistantReserved;
196 char DeviceName_ascii[64];
197 char ManufacturerName_ascii[64];
198 char ApplicationName_ascii[64];
199 char HostName_ascii[64];
200 char UserName_utf8[128];
201 char UserComment_utf8[128];
202} __attribute__((packed));
203/********************************************************
204 * TEXT SUB PROTOCOL *
205 ********************************************************/
206
207#define VBAN_BPS_MASK 0xE0
208#define VBAN_BPS_MAXNUMBER 25
209static long const VBanBPSList[VBAN_BPS_MAXNUMBER] =
210{
211 0, 110, 150, 300, 600,
212 1200, 2400, 4800, 9600, 14400,
213 19200, 31250, 38400, 57600, 115200,
214 128000, 230400, 250000, 256000, 460800,
215 921600,1000000,1500000,2000000, 3000000
216};
217
218#define VBAN_DATATYPE_MASK 0x07
219#define VBAN_DATATYPE_MAXNUMBER 1
220enum VBanDataTypeList
221{
222 VBAN_DATATYPE_8BITS = 0
223};
224
225#define VBAN_STREAMTYPE_MASK 0xF0
226enum VBanStreamType
227{
228 VBAN_TXT_ASCII = 0x00,
229 VBAN_TXT_UTF8 = 0x10,
230 VBAN_TXT_WCHAR = 0x20,
231 VBAN_TXT_UNDEFINED_3 = 0x30,
232 VBAN_TXT_UNDEFINED_4 = 0x40,
233 VBAN_TXT_UNDEFINED_5 = 0x50,
234 VBAN_TXT_UNDEFINED_6 = 0x60,
235 VBAN_TXT_UNDEFINED_7 = 0x70,
236 VBAN_TXT_UNDEFINED_8 = 0x80,
237 VBAN_TXT_UNDEFINED_9 = 0x90,
238 VBAN_TXT_UNDEFINED_10 = 0xA0,
239 VBAN_TXT_UNDEFINED_11 = 0xB0,
240 VBAN_TXT_UNDEFINED_12 = 0xC0,
241 VBAN_TXT_UNDEFINED_13 = 0xD0,
242 VBAN_TXT_UNDEFINED_14 = 0xE0,
243 VBAN_TXT_USER = 0xF0
244};
245
246#endif /*__VBAN_H__*/
Definition vban.h:179
Definition vban.h:51
Definition vban.h:61