Last active
February 8, 2022 01:26
-
-
Save TheStaticTurtle/4b80ab968b36a6c8b5431e6d465b3db5 to your computer and use it in GitHub Desktop.
Nodered VBAN header decoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input_buffer = msg.payload | |
msg.payload = { | |
fourcc: input_buffer.slice(0, 4).toString(), | |
sample_rate: VBAN_SR_LIST[input_buffer[4] & VBAN_SR_MASK], | |
sub_protocol: VBAN_PROTOOLS[input_buffer[4] & VBAN_PROTOCOL_MASK], | |
samples: input_buffer[5], | |
channels: input_buffer[6], | |
format: VBAN_BIT_FMTS[input_buffer[7] & VBAN_BIT_RESOLUTION_MASK], | |
codec: VBAN_CODECS[input_buffer[7] & VBAN_CODEC_MASK], | |
stream_name: input_buffer.slice(8, 22).toString(), | |
frame_counter: input_buffer.readInt32LE(23), | |
data: input_buffer.slice(28) | |
} | |
return msg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VBAN_SR_MASK = 0x1F | |
VBAN_SR_MAXNUMBER = 21 | |
VBAN_SR_LIST = [ | |
6000, 12000, 24000, 48000, 96000, 192000, 384000, | |
8000, 16000, 32000, 64000, 128000, 256000, 512000, | |
11025, 22050, 44100, 88200, 176400, 352800, 705600 | |
]; | |
VBAN_PROTOCOL_MASK = 0xE0 | |
VBAN_PROTOOLS = { | |
0x00: "audio", | |
0x20: "serial", | |
0x40: "txt", | |
0x80: "undefined1", | |
0xA0: "undefined2", | |
0xC0: "undefined3", | |
0xE0: "undefined4", | |
} | |
VBAN_BIT_RESOLUTION_MASK = 0x07 | |
VBAN_BIT_FMTS = { | |
0: "int8", | |
1: "int16", | |
2: "int24", | |
3: "int32", | |
4: "float32", | |
5: "float64", | |
6: "int12", | |
7: "int10", | |
} | |
VBAN_BIT_RESOLUTIONSS = { | |
0: 1, | |
1: 2, | |
2: 3, | |
3: 4, | |
4: 4, | |
5: 8, | |
} | |
VBAN_RESERVED_MASK = 0x08 | |
VBAN_CODEC_MASK = 0xF0 | |
VBAN_CODECS = { | |
0x00: "pcm", | |
0x10: "vbca", | |
0x20: "vbcv", | |
0x30: "undefined3", | |
0x40: "undefined4", | |
0x50: "undefined5", | |
0x60: "undefined6", | |
0x70: "undefined7", | |
0x80: "undefined8", | |
0x90: "undefined9", | |
0xA0: "undefined10", | |
0xB0: "undefined11", | |
0xC0: "undefined12", | |
0xD0: "undefined13", | |
0xE0: "undefined14", | |
0xF0: "user", | |
} | |
/******************************************************** | |
* TEXT SUB PROTOCOL * | |
********************************************************/ | |
VBAN_BPS_MASK = 0xE0 | |
VBAN_BPS_MAXNUMBER = 25 | |
VBAN_BPS_LIST = [ | |
0, 110, 150, 300, 600, | |
1200, 2400, 4800, 9600, 14400, | |
19200, 31250, 38400, 57600, 115200, | |
128000, 230400, 250000, 256000, 460800, | |
921600,1000000,1500000,2000000, 3000000 | |
]; | |
VBAN_DATATYPE_MASK = 0x07 | |
VBAN_DATATYPE_MAXNUMBER = 1 | |
VBAN_DATA_TYPE_LIST = { | |
0x00: "8bits" | |
} | |
VBAN_STREAMTYPE_MASK = 0xF0 | |
VBAN_STREAM_TYPE_LIST = { | |
0x00: "ASCII", | |
0x10: "UTF8", | |
0x20: "WCHAR", | |
0x30: "UNDEFINED_3", | |
0x40: "UNDEFINED_4", | |
0x50: "UNDEFINED_5", | |
0x60: "UNDEFINED_6", | |
0x70: "UNDEFINED_7", | |
0x80: "UNDEFINED_8", | |
0x90: "UNDEFINED_9", | |
0xA0: "UNDEFINED_10", | |
0xB0: "UNDEFINED_11", | |
0xC0: "UNDEFINED_12", | |
0xD0: "UNDEFINED_13", | |
0xE0: "UNDEFINED_14", | |
0xF0: "USER", | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let buf = Buffer.allocUnsafe(28); | |
let offset = 0 | |
offset = buf.write("VBAN", offset); | |
offset = buf.writeUInt8( | |
VBAN_SR_LIST.indexOf(msg.payload.sample_rate) + | |
VBAN_PROTOOLS[msg.payload.sub_protocol] | |
, offset); | |
offset = buf.writeUInt8(msg.payload.samples, offset); | |
offset = buf.writeUInt8(msg.payload.channels, offset); | |
offset = buf.writeUInt8( | |
VBAN_CODECS[msg.payload.codec] + | |
VBAN_BIT_FMTS[msg.payload.format] | |
, offset); | |
buf.write(msg.payload.stream_name, offset); | |
offset += 16 | |
offset = buf.writeInt32LE(msg.payload.frame_counter, offset); | |
msg.origin = msg.payload | |
msg.payload = Buffer.concat([buf, msg.payload.data]) | |
msg.size = msg.payload.length | |
return msg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VBAN_SR_MASK = 0x1F | |
VBAN_SR_MAXNUMBER = 21 | |
VBAN_SR_LIST = [ | |
6000, 12000, 24000, 48000, 96000, 192000, 384000, | |
8000, 16000, 32000, 64000, 128000, 256000, 512000, | |
11025, 22050, 44100, 88200, 176400, 352800, 705600 | |
]; | |
VBAN_PROTOCOL_MASK = 0xE0 | |
VBAN_PROTOOLS = { | |
"audio": 0x00, | |
"serial": 0x20, | |
"txt": 0x40, | |
"undefined1": 0x80, | |
"undefined2": 0xA0, | |
"undefined3": 0xC0, | |
"undefined4": 0xE0, | |
} | |
VBAN_BIT_RESOLUTION_MASK = 0x07 | |
VBAN_BIT_FMTS = { | |
"int8": 0, | |
"int16": 1, | |
"int24": 2, | |
"int32": 3, | |
"float32": 4, | |
"float64": 5, | |
"int12": 6, | |
"int10": 7, | |
} | |
VBAN_BIT_RESOLUTIONSS = { | |
1: 0, | |
2: 1, | |
3: 2, | |
// 4: 3, | |
4: 4, | |
8: 5, | |
} | |
VBAN_RESERVED_MASK = 0x08 | |
VBAN_CODEC_MASK = 0xF0 | |
VBAN_CODECS = { | |
"pcm": 0x00, | |
"vbca": 0x10, | |
"vbcv": 0x20, | |
"undefined3": 0x30, | |
"undefined4": 0x40, | |
"undefined5": 0x50, | |
"undefined6": 0x60, | |
"undefined7": 0x70, | |
"undefined8": 0x80, | |
"undefined9": 0x90, | |
"undefined10": 0xA0, | |
"undefined11": 0xB0, | |
"undefined12": 0xC0, | |
"undefined13": 0xD0, | |
"undefined14": 0xE0, | |
"user": 0xF0, | |
} | |
/******************************************************** | |
* TEXT SUB PROTOCOL * | |
********************************************************/ | |
VBAN_BPS_MASK = 0xE0 | |
VBAN_BPS_MAXNUMBER = 25 | |
VBAN_BPS_LIST = [ | |
0, 110, 150, 300, 600, | |
1200, 2400, 4800, 9600, 14400, | |
19200, 31250, 38400, 57600, 115200, | |
128000, 230400, 250000, 256000, 460800, | |
921600,1000000,1500000,2000000, 3000000 | |
]; | |
VBAN_DATATYPE_MASK = 0x07 | |
VBAN_DATATYPE_MAXNUMBER = 1 | |
VBAN_DATA_TYPE_LIST = { | |
0x00: "8bits" | |
} | |
VBAN_STREAMTYPE_MASK = 0xF0 | |
VBAN_STREAM_TYPE_LIST = { | |
0x00: "ASCII", | |
0x10: "UTF8", | |
0x20: "WCHAR", | |
0x30: "UNDEFINED_3", | |
0x40: "UNDEFINED_4", | |
0x50: "UNDEFINED_5", | |
0x60: "UNDEFINED_6", | |
0x70: "UNDEFINED_7", | |
0x80: "UNDEFINED_8", | |
0x90: "UNDEFINED_9", | |
0xA0: "UNDEFINED_10", | |
0xB0: "UNDEFINED_11", | |
0xC0: "UNDEFINED_12", | |
0xD0: "UNDEFINED_13", | |
0xE0: "UNDEFINED_14", | |
0xF0: "USER", | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id":"be58fd5f.d896b", | |
"type":"tab", | |
"label":"Flow 1", | |
"disabled":false, | |
"info":"" | |
}, | |
{ | |
"id":"69f55d544641b3e0", | |
"type":"udp in", | |
"z":"be58fd5f.d896b", | |
"name":"", | |
"iface":"", | |
"port":"8753", | |
"ipv":"udp4", | |
"multicast":"false", | |
"group":"", | |
"datatype":"buffer", | |
"x":360, | |
"y":280, | |
"wires":[ | |
[ | |
"1c6dca5d1920b6c2" | |
] | |
] | |
}, | |
{ | |
"id":"98dd74aa64b98ac7", | |
"type":"udp out", | |
"z":"be58fd5f.d896b", | |
"name":"", | |
"addr":"127.0.0.1", | |
"iface":"", | |
"port":"6980", | |
"ipv":"udp4", | |
"outport":"", | |
"base64":false, | |
"multicast":"false", | |
"x":1030, | |
"y":280, | |
"wires":[ | |
] | |
}, | |
{ | |
"id":"0370748bbbb11a52", | |
"type":"debug", | |
"z":"be58fd5f.d896b", | |
"name":"", | |
"active":false, | |
"tosidebar":true, | |
"console":false, | |
"tostatus":false, | |
"complete":"payload", | |
"targetType":"msg", | |
"statusVal":"", | |
"statusType":"auto", | |
"x":810, | |
"y":340, | |
"wires":[ | |
] | |
}, | |
{ | |
"id":"1c6dca5d1920b6c2", | |
"type":"function", | |
"z":"be58fd5f.d896b", | |
"name":"Decode Header", | |
"func":"\ninput_buffer = msg.payload\n\nmsg.payload = {\n fourcc: input_buffer.slice(0, 4).toString(),\n sample_rate: VBAN_SR_LIST[input_buffer[4] & VBAN_SR_MASK],\n sub_protocol: VBAN_PROTOOLS[input_buffer[4] & VBAN_PROTOCOL_MASK],\n samples: input_buffer[5],\n channels: input_buffer[6],\n format: VBAN_BIT_FMTS[input_buffer[7] & VBAN_BIT_RESOLUTION_MASK],\n codec: VBAN_CODECS[input_buffer[7] & VBAN_CODEC_MASK],\n stream_name: input_buffer.slice(8, 22).toString(),\n frame_counter: input_buffer.readInt32LE(23),\n data: input_buffer.slice(28)\n}\n\nreturn msg;", | |
"outputs":1, | |
"noerr":0, | |
"initialize":"\n\nVBAN_SR_MASK = 0x1F\nVBAN_SR_MAXNUMBER = 21\n\nVBAN_SR_LIST = [\n 6000, 12000, 24000, 48000, 96000, 192000, 384000,\n 8000, 16000, 32000, 64000, 128000, 256000, 512000,\n 11025, 22050, 44100, 88200, 176400, 352800, 705600\n];\n\nVBAN_PROTOCOL_MASK = 0xE0\nVBAN_PROTOOLS = {\n 0x00: \"audio\",\n 0x20: \"serial\",\n 0x40: \"txt\",\n 0x80: \"undefined1\",\n 0xA0: \"undefined2\",\n 0xC0: \"undefined3\",\n 0xE0: \"undefined4\",\n}\n\nVBAN_BIT_RESOLUTION_MASK = 0x07\nVBAN_BIT_FMTS = {\n 0: \"int8\",\n 1: \"int16\",\n 2: \"int24\",\n 3: \"int32\",\n 4: \"float32\",\n 5: \"float64\",\n 6: \"int12\",\n 7: \"int10\",\n}\n\nVBAN_BIT_RESOLUTIONSS = {\n 0: 1,\n 1: 2,\n 2: 3,\n 3: 4,\n 4: 4,\n 5: 8,\n}\n\nVBAN_RESERVED_MASK = 0x08\n\nVBAN_CODEC_MASK = 0xF0\nVBAN_CODECS = {\n 0x00: \"pcm\",\n 0x10: \"vbca\",\n 0x20: \"vbcv\",\n 0x30: \"undefined3\",\n 0x40: \"undefined4\",\n 0x50: \"undefined5\",\n 0x60: \"undefined6\",\n 0x70: \"undefined7\",\n 0x80: \"undefined8\",\n 0x90: \"undefined9\",\n 0xA0: \"undefined10\",\n 0xB0: \"undefined11\",\n 0xC0: \"undefined12\",\n 0xD0: \"undefined13\",\n 0xE0: \"undefined14\",\n 0xF0: \"user\",\n}\n\n/********************************************************\n * TEXT SUB PROTOCOL *\n ********************************************************/\n \nVBAN_BPS_MASK = 0xE0\nVBAN_BPS_MAXNUMBER = 25\nVBAN_BPS_LIST = [\n 0, 110, 150, 300, 600,\n 1200, 2400, 4800, 9600, 14400,\n 19200, 31250, 38400, 57600, 115200,\n 128000, 230400, 250000, 256000, 460800,\n 921600,1000000,1500000,2000000, 3000000\n];\n\nVBAN_DATATYPE_MASK = 0x07\nVBAN_DATATYPE_MAXNUMBER = 1\n\nVBAN_DATA_TYPE_LIST = {\n 0x00: \"8bits\"\n}\n\n\nVBAN_STREAMTYPE_MASK = 0xF0\nVBAN_STREAM_TYPE_LIST = {\n 0x00: \"ASCII\",\n 0x10: \"UTF8\",\n 0x20: \"WCHAR\",\n 0x30: \"UNDEFINED_3\",\n 0x40: \"UNDEFINED_4\",\n 0x50: \"UNDEFINED_5\",\n 0x60: \"UNDEFINED_6\",\n 0x70: \"UNDEFINED_7\",\n 0x80: \"UNDEFINED_8\",\n 0x90: \"UNDEFINED_9\",\n 0xA0: \"UNDEFINED_10\",\n 0xB0: \"UNDEFINED_11\",\n 0xC0: \"UNDEFINED_12\",\n 0xD0: \"UNDEFINED_13\",\n 0xE0: \"UNDEFINED_14\",\n 0xF0: \"USER\",\n}", | |
"finalize":"", | |
"libs":[ | |
], | |
"x":560, | |
"y":280, | |
"wires":[ | |
[ | |
"0370748bbbb11a52", | |
"d095c3c38b6b53dd" | |
] | |
] | |
}, | |
{ | |
"id":"d095c3c38b6b53dd", | |
"type":"function", | |
"z":"be58fd5f.d896b", | |
"name":"Encode Header", | |
"func":"let buf = Buffer.allocUnsafe(28);\nlet offset = 0\n\noffset = buf.write(\"VBAN\", offset);\n\noffset = buf.writeUInt8(\n VBAN_SR_LIST.indexOf(msg.payload.sample_rate) +\n VBAN_PROTOOLS[msg.payload.sub_protocol]\n, offset);\n\noffset = buf.writeUInt8(msg.payload.samples, offset);\n\noffset = buf.writeUInt8(msg.payload.channels, offset);\n\noffset = buf.writeUInt8(\n VBAN_CODECS[msg.payload.codec] +\n VBAN_BIT_FMTS[msg.payload.format]\n, offset);\n\nbuf.write(msg.payload.stream_name, offset);\noffset += 16\n\noffset = buf.writeInt32LE(msg.payload.frame_counter, offset);\n\n\nmsg.origin = msg.payload\nmsg.payload = Buffer.concat([buf, msg.payload.data])\nmsg.size = msg.payload.length\n\nreturn msg;", | |
"outputs":1, | |
"noerr":0, | |
"initialize":"\n\nVBAN_SR_MASK = 0x1F\nVBAN_SR_MAXNUMBER = 21\n\nVBAN_SR_LIST = [\n 6000, 12000, 24000, 48000, 96000, 192000, 384000,\n 8000, 16000, 32000, 64000, 128000, 256000, 512000,\n 11025, 22050, 44100, 88200, 176400, 352800, 705600\n];\n\n\nVBAN_PROTOCOL_MASK = 0xE0\nVBAN_PROTOOLS = {\n \"audio\": 0x00,\n \"serial\": 0x20,\n \"txt\": 0x40,\n \"undefined1\": 0x80,\n \"undefined2\": 0xA0,\n \"undefined3\": 0xC0,\n \"undefined4\": 0xE0,\n}\n\nVBAN_BIT_RESOLUTION_MASK = 0x07\nVBAN_BIT_FMTS = {\n \"int8\": 0,\n \"int16\": 1,\n \"int24\": 2,\n \"int32\": 3,\n \"float32\": 4,\n \"float64\": 5,\n \"int12\": 6,\n \"int10\": 7,\n}\n\nVBAN_BIT_RESOLUTIONSS = {\n 1: 0,\n 2: 1,\n 3: 2,\n// 4: 3,\n 4: 4,\n 8: 5,\n}\n\nVBAN_RESERVED_MASK = 0x08\n\nVBAN_CODEC_MASK = 0xF0\nVBAN_CODECS = {\n \"pcm\": 0x00,\n \"vbca\": 0x10,\n \"vbcv\": 0x20,\n \"undefined3\": 0x30,\n \"undefined4\": 0x40,\n \"undefined5\": 0x50,\n \"undefined6\": 0x60,\n \"undefined7\": 0x70,\n \"undefined8\": 0x80,\n \"undefined9\": 0x90,\n \"undefined10\": 0xA0,\n \"undefined11\": 0xB0,\n \"undefined12\": 0xC0,\n \"undefined13\": 0xD0,\n \"undefined14\": 0xE0,\n \"user\": 0xF0,\n}\n\n/********************************************************\n * TEXT SUB PROTOCOL *\n ********************************************************/\n \nVBAN_BPS_MASK = 0xE0\nVBAN_BPS_MAXNUMBER = 25\nVBAN_BPS_LIST = [\n 0, 110, 150, 300, 600,\n 1200, 2400, 4800, 9600, 14400,\n 19200, 31250, 38400, 57600, 115200,\n 128000, 230400, 250000, 256000, 460800,\n 921600,1000000,1500000,2000000, 3000000\n];\n\nVBAN_DATATYPE_MASK = 0x07\nVBAN_DATATYPE_MAXNUMBER = 1\n\nVBAN_DATA_TYPE_LIST = {\n 0x00: \"8bits\"\n}\n\n\nVBAN_STREAMTYPE_MASK = 0xF0\nVBAN_STREAM_TYPE_LIST = {\n 0x00: \"ASCII\",\n 0x10: \"UTF8\",\n 0x20: \"WCHAR\",\n 0x30: \"UNDEFINED_3\",\n 0x40: \"UNDEFINED_4\",\n 0x50: \"UNDEFINED_5\",\n 0x60: \"UNDEFINED_6\",\n 0x70: \"UNDEFINED_7\",\n 0x80: \"UNDEFINED_8\",\n 0x90: \"UNDEFINED_9\",\n 0xA0: \"UNDEFINED_10\",\n 0xB0: \"UNDEFINED_11\",\n 0xC0: \"UNDEFINED_12\",\n 0xD0: \"UNDEFINED_13\",\n 0xE0: \"UNDEFINED_14\",\n 0xF0: \"USER\",\n}", | |
"finalize":"", | |
"libs":[ | |
], | |
"x":820, | |
"y":280, | |
"wires":[ | |
[ | |
"98dd74aa64b98ac7" | |
] | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment