Skip to content

Commit

Permalink
vban support
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Oct 10, 2023
1 parent 9d4f3eb commit fbd9edf
Show file tree
Hide file tree
Showing 6 changed files with 648 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @file streams-i2s-vban.ino
* @author Phil Schatzmann
* @brief sends signal from i2s (using an AudioKit) to VBAN Receptor App
*/

#include "AudioTools.h"
#include "AudioLibs/VBANStream.h"
#include "AudioLibs/AudioKit.h" // comment out when not using AudioKit

AudioInfo info(44100, 2, 16);
AudioKitStream in; // Audio source e.g. replace with I2SStream
VBANStream out;
StreamCopy copier(out, in, 2048); // copies sound into i2s

// Arduino Setup
void setup(void) {
// Open Serial
Serial.begin(115200);
while(!Serial);
AudioLogger::instance().begin(Serial, AudioLogger::Info);

// setup output
auto cfg = out.defaultConfig(TX_MODE);
cfg.copyFrom(info);
cfg.ssid = "ssid";
cfg.password = "password";
cfg.stream_name = "Stream1";
cfg.target_ip = IPAddress{192,168,1,37}; // comment out to broadcast
cfg.throttle_active = false; // generator is much too fast, we need to stall
if (!out.begin(cfg)) stop();

// Setup input from mic
// setup input
auto cfg_in = in.defaultConfig(RX_MODE);
cfg_in.sd_active = false;
cfg_in.buffer_size = 256;
cfg_in.buffer_count = 4;
cfg_in.copyFrom(info);
cfg_in.input_device = AUDIO_HAL_ADC_INPUT_LINE2; // microphone
in.begin(cfg_in);
}

// Arduino loop - copy sound to out
void loop() {
copier.copy();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @file streams-generator-vban.ino
* @author Phil Schatzmann
* @brief sends sine test signal to VBAN Receptor App
*/

#include "AudioTools.h"
#include "AudioLibs/VBANStream.h"

AudioInfo info(44100, 2, 16);
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
VBANStream out;
StreamCopy copier(out, sound, 2048); // 44100 needs 2048

// Arduino Setup
void setup(void) {
// Open Serial
Serial.begin(115200);
while(!Serial);
AudioLogger::instance().begin(Serial, AudioLogger::Info);

// setup output
auto cfg = out.defaultConfig(TX_MODE);
cfg.copyFrom(info);
cfg.ssid = "ssid";
cfg.password = "password";
cfg.stream_name = "Stream1";
cfg.target_ip = IPAddress{192,168,1,37};
cfg.throttle_active = true;
cfg.throttle_correction_ms = -4; // optimize overload and underrun
if (!out.begin(cfg)) stop();

// Setup sine wave
sineWave.begin(info, N_B4);
Serial.println("started...");
}

// Arduino loop - copy sound to out
void loop() {
copier.copy();
}
1 change: 1 addition & 0 deletions src/AudioLibs/Communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ class Throttle {
int durationMsEff = millis() - start_time;
int durationToBe = (samples * 1000) / info.sample_rate;
int waitMs = durationToBe - durationMsEff + info.correction_ms;
LOGI("wait: %d", waitMs);
if (waitMs > 0) {
delay(waitMs);
}
Expand Down
Loading

0 comments on commit fbd9edf

Please sign in to comment.