snapshot
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* @file player-sdmmc-vban.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief decodes mp3 to vban: We need to use a queue to prevent delays to get too big.
|
||||
* We try to keep the queue filled, so that we can always provide pcm data to vban
|
||||
*/
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
|
||||
#include "AudioTools/Communication/VBANStream.h"
|
||||
#include "AudioTools/Disk/AudioSourceSDMMC.h" // or AudioSourceIdxSDMMC.h
|
||||
|
||||
const char *startFilePath="/";
|
||||
const char* ext="mp3";
|
||||
const int mp3_pcm_size = 14000;
|
||||
AudioInfo info(44100,2,16);
|
||||
AudioSourceSDMMC source(startFilePath, ext);
|
||||
RingBuffer<uint8_t> ring_buffer(mp3_pcm_size*3);
|
||||
QueueStream<uint8_t> queue(ring_buffer);
|
||||
MP3DecoderHelix decoder; // or change to MP3DecoderMAD
|
||||
AudioPlayer player(source, queue, decoder);
|
||||
|
||||
VBANStream out;
|
||||
StreamCopy copier(out, queue, 2048); // 44100 needs 2048
|
||||
|
||||
|
||||
void fillQueue(){
|
||||
// fill queue when smaller then limit
|
||||
if(ring_buffer.availableForWrite() >= mp3_pcm_size){
|
||||
player.copy();
|
||||
// activate copy when limit is reached
|
||||
if (!copier.isActive() && ring_buffer.available()>=23000){
|
||||
copier.setActive(true);
|
||||
LOGI("copier active");
|
||||
}
|
||||
}
|
||||
LOGI("available: %d - avail to write: %d", ring_buffer.available(), ring_buffer.availableForWrite());
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::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;
|
||||
if (!out.begin(cfg)) stop();
|
||||
|
||||
// setup player
|
||||
player.setVolume(0.7);
|
||||
player.begin();
|
||||
|
||||
// select file with setPath() or setIndex()
|
||||
//player.setPath("/ZZ Top/Unknown Album/Lowrider.mp3");
|
||||
//player.setIndex(1); // 2nd file
|
||||
|
||||
queue.begin(); // start queue
|
||||
copier.setActive(false); // deactivate copy
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
fillQueue();
|
||||
// output from queue
|
||||
copier.copy();
|
||||
}
|
||||
@@ -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 "AudioTools/Communication/VBANStream.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h" // comment out when not using AudioKit
|
||||
|
||||
AudioInfo info(44100, 2, 16);
|
||||
AudioBoardStream in(AudioKitEs8388V1); // 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);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::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 = ADC_INPUT_LINE2; // microphone
|
||||
in.begin(cfg_in);
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -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 "AudioTools/Communication/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);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::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_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();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @file streams-i2s-vban.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief sends signal from i2s (using an AudioKit) to VBAN Receptor App
|
||||
*/
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/Communication/VBANStream.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h" // comment out when not using AudioKit
|
||||
|
||||
AudioBoardStream out(AudioKitEs8388V1); // Audio source e.g. replace with I2SStream
|
||||
VBANStream in;
|
||||
StreamCopy copier(out, in); // copies sound into i2s
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
while(!Serial);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// setup output
|
||||
auto cfg_out = out.defaultConfig(TX_MODE);
|
||||
if (!out.begin(cfg_out)) stop();
|
||||
|
||||
// format changes in vban must change the output as well
|
||||
in.addNotifyAudioChange(out);
|
||||
|
||||
// setup input from vban
|
||||
auto cfg_in = in.defaultConfig(RX_MODE);
|
||||
cfg_in.ssid = "ssid";
|
||||
cfg_in.password = "password";
|
||||
cfg_in.stream_name = "Talkie";
|
||||
|
||||
// set parameters for reply to discovery VBAN PING0 packet (So the voicemeter can correctly identify your device)
|
||||
//cfg_in.device_flags = 0x00000001; //reciever only
|
||||
//cfg_in.bitfeature = 0x00000001; // audio only
|
||||
//cfg_in.device_color = 0x00FF00;
|
||||
//cfg_in.device_name = nullptr; // or "MyDeviceName" if empty replaced with MAC
|
||||
//cfg_in.manufacturer_name = "Your Name";
|
||||
//cfg_in.application_name = "Your App Name";
|
||||
//cfg_in.host_name = nullptr; // if empty replaced with hostname
|
||||
//cfg_in.user_name = "User";
|
||||
//cfg_in.user_comment = "ESP32 VBAN Audio Device"; //bascially anything goes - just keep under 64 bytes see VBAN docs for more
|
||||
|
||||
in.begin(cfg_in);
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
Reference in New Issue
Block a user