Skip to content

Commit 4d9e40f

Browse files
committed
VBANStream
1 parent 5bb77b5 commit 4d9e40f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

examples/examples-communication/vban/streams-vban-audiokit/streams-vban-audiokit.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ void setup(void) {
2323
auto cfg_out = out.defaultConfig(TX_MODE);
2424
if (!out.begin(cfg_out)) stop();
2525

26+
// format changes in vban must change the output as well
27+
in.setNotifyAudioChange(out);
28+
2629
// setup input from vban
2730
auto cfg_in = in.defaultConfig(RX_MODE);
2831
cfg_in.ssid = "ssid";

src/AudioLibs/VBANStream.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,18 +377,25 @@ class VBANStream : public AudioStream {
377377
uint8_t vbanSampleRateIdx = udpIncomingPacket[4] & VBAN_SR_MASK;
378378
uint8_t vbchannels = udpIncomingPacket[6] + 1;
379379
uint8_t vbframes = udpIncomingPacket[5] + 1;
380-
uint8_t vbformat = udpIncomingPacket[4] & VBAN_PROTOCOL_MASK;;
380+
uint8_t vbformat = udpIncomingPacket[7] & VBAN_PROTOCOL_MASK;;
381+
uint8_t vbformat_bits = udpIncomingPacket[7] & VBAN_BIT_RESOLUTION_MASK;;
381382
uint32_t vbanSampleRate = VBanSRList[vbanSampleRateIdx];
382383

383384
LOGD("sample_count: %d - frames: %d", vban_rx_sample_count, vbframes);
384385
assert (vban_rx_sample_count == vbframes*vbchannels);
385386

386-
387+
// E.g. do not process any text
387388
if (vbformat != cfg.format){
388389
LOGE("Format ignored: 0x%x", vbformat);
389390
return;
390391
}
391392

393+
// Currently we support only 16 bits.
394+
if (vbformat_bits != VBAN_BITFMT_16_INT){
395+
LOGE("Format only 16 bits supported");
396+
return;
397+
}
398+
392399
// Just to be safe, re-check sample count against max sample count to
393400
// avoid overrunning outBuf later
394401
if (vban_rx_sample_count > VBAN_PACKET_MAX_SAMPLES) {
@@ -398,9 +405,13 @@ class VBANStream : public AudioStream {
398405

399406
// update sample rate
400407
if (cfg.sample_rate != vbanSampleRate || cfg.channels != vbchannels) {
408+
// update audio info
401409
cfg.sample_rate = vbanSampleRate;
402410
cfg.channels = vbchannels;
403411
setAudioInfo(cfg);
412+
// remove any buffered data
413+
rx_buffer.reset();
414+
available_active = false;
404415
}
405416

406417
if (p_out!=nullptr){
@@ -412,7 +423,6 @@ class VBANStream : public AudioStream {
412423
}
413424

414425
// write data to buffer
415-
TRACED();
416426
int size_written = rx_buffer.writeArray((uint8_t*)vban_rx_data, vban_rx_data_bytes);
417427
if (size_written != vban_rx_data_bytes) {
418428
LOGE("buffer overflow %d -> %d", vban_rx_data_bytes, size_written);

0 commit comments

Comments
 (0)