For quite some time I was looking for an easy way to send some audio to some mobile devices w/o having to write my own mobile application. That’s when I found VBAN. They have some free app (and some payed ones that are reasonably priced) and publish their protocol.
So I added the support for VBAN to my AudioTools library and tested the functionality with an ESP32. Here is the basic test sketch:
Arduino Sketch
#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, 1024);
// Arduino Setup
void setup(void) {
// Open Serial
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
// 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_us = 0; // 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();
}
In this test I was sending out just some generated sine tone.
- As expected you can just write your data to an instance of the VBANStream class.
-
The sketch needs the Wifi to work, so I made the setup and login part of the functionality, but you can set up the Wifi also the usual way.
-
The target ip address specifies the device to which you want to send the audio. If you leave it empty, then the data is broadcasted.
-
Because the sine generator is generating the data much too fast, we need to slow the sending down to the indicated sample rate. This is done with the help of
cfg.throttle_active = true;
. If you would use e.g. a microphone as data source, this is not necessary!
Dependencies
You need to have the following libraries installed:
VBAN Settings
Set the audio quality to a value below Fast to prevent overloads and underruns.
Updated Source Code
This and other VBAN examples can be found on Github.
0 Comments