Problem of clicks and pops using Audio over IP receive example #1184
-
Hi, first of all, thanks for your great work! I'm trying to create a project using an ESP32-ADF to stream audio over IP. I copied your example of receiving audio over IP from the communication examples. Then on the computer I use FFMPEG to compress audio and stream it to the ESP32 using this command:
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Not sure what exactly the problem is, but my guess would be that the data is not posted fast enough so that the playback is running out of data. I suggest to investigate if you can increase the buffer for ffmpeg |
Beta Was this translation helpful? Give feedback.
-
Thanks for the answer i managed to get it to work! And sorry again because i'm brand new in coding in CPP Anyway now i have another issue, on top of the streaming i wanted to trigger some samples sometimes, The first streaming is doing this: AudioOverIP(mp3) --> CopierToDecoder --> CallbackStream--> CopierToMixer --> AudioKitOut The second streaming is doing this: FileWAV-->Decoder-->CopierToMixer-->AudioKitOut Probably i'm not understanding correctly how to use callbacks(if necessary) and the output mixer... I managed to get to work both of the code indipendently without callbacks or mixer and in this attachment you can find the working code for playing 8 Wav files from SD and another code for receiving an MP3 streaming over IP: When I tried to merge them this is the result that is not working: /**
* @file streams-sd-audiokit.ino
* @author Phil Schatzmann
* @brief Just a small demo, how to use files with the SD library
* @version 0.1
* @date 2022-10-09
*
* @copyright Copyright (c) 2022
*
*/
#include <SPI.h>
#include <SD.h>
#include "AudioTools.h"
#include "AudioLibs/AudioKit.h"
#include "AudioCodecs/CodecWAV.h"
#include "AudioCodecs/CodecMP3Helix.h"
#ifdef ESP8266
#include <ESP8266WiFi.h>
#else
#include <WiFi.h>
#endif
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCBundle.h>
#include <OSCData.h>
char ssid[] = "ssid"; // your network SSID (name)
char pass[] = "pass"; // your network password
// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
const unsigned int localPort = 8888; // local port to listen for UDP packets (here's where we send the packets)
OSCErrorCode error;
unsigned int playPause=0;
unsigned int stopPlay=1;
unsigned int sample_1=0;
unsigned int sample_2=0;
unsigned int sample_3=0;
unsigned int sample_4=0;
unsigned int sample_5=0;
unsigned int sample_6=0;
unsigned int sample_7=0;
unsigned int sample_8=0;
int volumeState=90;
const int chipSelect=PIN_AUDIO_KIT_SD_CARD_CS;
uint16_t port = 8000;
WiFiServer server(port);
WiFiClient client;
AudioKitStream i2s; // final output of decoded stream
OutputMixer<int16_t> mixer(i2s,2); // output mixer with 2 outputs mixing to AudioKitStream
VolumeStream callback1(mixer);
VolumeStream callback2(mixer);
EncodedAudioStream decoder(&callback1, new WAVDecoder()); // Decoding audioFile
EncodedAudioStream dec(&callback2, new MP3DecoderHelix()); // Decoding mp3 stream
StreamCopy copier1(mixer, decoder);
StreamCopy copier2(dec, client);
StreamCopy copier3(mixer,callback1);
StreamCopy copier4(mixer,callback2);
File audioFile;
void setup(){
Serial.begin(115200);
//AudioLogger::instance().begin(Serial, AudioLogger::Error);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Starting UDP");
Udp.begin(localPort);
Serial.print("Local port: ");
#ifdef ESP32
Serial.println(localPort);
#else
Serial.println(Udp.localPort());
#endif
// setup audiokit before SD!
auto config = i2s.defaultConfig(TX_MODE);
config.sd_active = true;
config.buffer_size= 1024;
// setup file
SD.begin(chipSelect);
// setup I2S based on sampling rate provided by decoder
server.begin();
dec.begin();
decoder.begin();
// begin copy
copier1.setCheckAvailableForWrite(false);
copier1.begin(decoder, audioFile);
i2s.begin(config);
callback1.begin(config);
callback1.setVolume(1.0);
callback2.begin(config);
mixer.begin(1024,RAM);
}
void sample1 (OSCMessage &msg){
sample_1 = msg.getInt(0);
if (sample_1==1){
Serial.println("Playing sample 1");
audioFile = SD.open("/01.wav");
}
}
void sample2 (OSCMessage &msg){
sample_2 = msg.getInt(0);
if (sample_2==1){
Serial.println("Playing sample 2");
audioFile = SD.open("/02.wav");
}
}
void sample3 (OSCMessage &msg){
sample_3 = msg.getInt(0);
if (sample_3==1){
Serial.println("Playing sample 3");
audioFile = SD.open("/03.wav");
}
}
void sample4 (OSCMessage &msg){
sample_4 = msg.getInt(0);
if (sample_4==1){
Serial.println("Playing sample 4");
audioFile = SD.open("/04.wav");
}
}
void sample5 (OSCMessage &msg){
sample_5 = msg.getInt(0);
if (sample_5==1){
Serial.println("Playing sample 5");
audioFile = SD.open("/05.wav");
}
}
void sample6 (OSCMessage &msg){
sample_6 = msg.getInt(0);
if (sample_6==1){
Serial.println("Playing sample 6");
audioFile = SD.open("/06.wav");
}
}
void sample7 (OSCMessage &msg){
sample_7 = msg.getInt(0);
if (sample_7==1){
Serial.println("Playing sample 7");
audioFile = SD.open("/07.wav");
}
}
void sample8 (OSCMessage &msg){
sample_8 = msg.getInt(0);
if (sample_8==1){
Serial.println("Playing sample 8");
audioFile = SD.open("/08.wav");
}
}
void volume(OSCMessage &msg) {
volumeState = msg.getInt(0);
i2s.setVolume(volumeState);
Serial.print("Volume: ");
Serial.println(volumeState);
}
void loop(){
OSCMessage msg;
int size = Udp.parsePacket();
if (size > 0) {
while (size--) {
msg.fill(Udp.read());
}
if (!msg.hasError()) {
msg.dispatch("/sample1", sample1);
msg.dispatch("/sample2", sample2);
msg.dispatch("/sample3", sample3);
msg.dispatch("/sample4", sample4);
msg.dispatch("/sample5", sample5);
msg.dispatch("/sample6", sample6);
msg.dispatch("/sample7", sample7);
msg.dispatch("/sample8", sample8);
msg.dispatch("/volume", volume);
} else {
error = msg.getError();
Serial.print("error: ");
Serial.println(error);
}
}
copier1.copy();
// get a new connection if necessary
if (!client){
client = server.available();
}
// copy data if we are connected
if (client.connected()){
copier2.copy();
} else {
// feed the dog
delay(100);
}
copier3.copy();
copier4.copy();
mixer.flushMixer();
} |
Beta Was this translation helpful? Give feedback.
-
If you look at the chain: you are reading from the EncodedAudioStream so you need to define the source which is file that you want to process! |
Beta Was this translation helpful? Give feedback.
Not sure what exactly the problem is, but my guess would be that the data is not posted fast enough so that the playback is running out of data.
I suggest to investigate if you can increase the buffer for ffmpeg
I would also recommend to specify the sampling rate in ffmpeg