I was wondering if the Raperry Pico 2W can be used with my Arduino Snapclient Library. A related discussion was hinting that it is just not powerful enough.
In the beginning was stuggeling quite a bit and the audio with Opus was just not working and I could bareliy make it work with PCM/WAV with a sample rate of only 8000.
The solution was to split up the Wifi and the audio decoding to the different cores, so I implemented a new SnapProcessorRP2040
class.
The sketch that uses this class now looks as follows
#include "AudioTools.h"
#include "AudioTools/AudioCodecs/CodecOpus.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#include "SnapClient.h"
#include "api/SnapProcessorRP2040.h"
#define ARDUINO_LOOP_STACK_SIZE (10 * 1024)
I2SStream out;
OpusAudioDecoder opus;
WiFiClient wifi;
SnapTimeSyncDynamic synch(172, 10); // optional configuratioin
CopyDecoder copy;
SnapClient client(wifi, out, opus);
SnapProcessorRP2040 processor_rp2040(1024*10); // define queue with 10 kbytes
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
while(!Serial);
Serial.println("starting...");
// login to wifi -> Define values in SnapConfig.h or replace them here
WiFi.begin("ssid", "pwd");
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
// print ip address
Serial.println();
Serial.println(WiFi.localIP());
// Define CONFIG_SNAPCAST_SERVER_HOST in SnapConfig.h or here
//client.setServerIP(IPAddress(192,168,1,44));
client.setSnapProcessor(processor_rp2040);
// start snap client
client.begin(synch);
Serial.println("started");
}
void loop() {
client.doLoop();
}
void setup1(){
// setup I2S to define custom pins
auto cfg = out.defaultConfig();
//cfg.pin_bck = 14;
//cfg.pin_ws = 15;
//cfg.pin_data = 22;
cfg.sample_rate = 48000;
cfg.buffer_size = 1024;
cfg.buffer_count = 4;
out.begin(cfg);
}
void loop1(){
client.snapProcessor().doLoop1();
}
I think the audio is not perfect yet, but it is much better now!
If you plan to use this sketch, I suggest to use the version that is provided in the examples directory.
0 Comments