How to set sample_rate in i2s_config_t to not be updated automatically by A2DP #602
-
I am working with an esp32 pico mini to collect Bluetooth from a phone and pass that data via I2S to another device. I am setting the sample_rate to 48000 in the i2s_config_t, however, once my phone connects, the rate drops down to 44100. Our second device is not compatible with 44100, so I need a way to ensure that it will continue to transmit on the correct rate. This is how my code looks currently: ` Serial.begin(115200); //Set I2S parameters i2s_pin_config_t I2S_devKit_pin_config = { a2dp_sink.set_pin_config(I2S_devKit_pin_config); |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 5 replies
-
The sample rate is defined by the ESP32 A2DP and can't be changed. I don't understand what you mean with second device, but if your output DAC only supports 48000, you need to resample. The AudioTools library provides the functionality and documentation how to do this! |
Beta Was this translation helpful? Give feedback.
-
You need to use the sample rate that the data is provided by A2DP! Did you test if you get a good I2S connection between 2 different microcontrollers ? |
Beta Was this translation helpful? Give feedback.
-
You can use the AudioTools to test this independently of the A2DP |
Beta Was this translation helpful? Give feedback.
-
I am having difficulty getting the resample working and outputting to the I2S stream, would you be able to provide an example that does this? Or even just how to set the input to be the audio data received via Bluetooth. |
Beta Was this translation helpful? Give feedback.
-
With the actual version it is pretty easy: just send the output to a ResampleStream instead of an I2SStream and don't forget to start all objects: #include "AudioTools.h"
#include "BluetoothA2DPSink.h"
AudioInfo from_info(44100, 2, 16);
AudioInfo to_info(48000, 2, 16);
I2SStream out;
ResampleStream resample(out);
BluetoothA2DPSink a2dp_sink(resample);
void setup() {
// setup i2s with 48000
auto cfg = out.defaultConfig();
cfg.copyFrom(to_info);
cfg.pin_bck = 12;
cfg.pin_ws = 13;
cfg.pin_data = 15;
cfg.is_master = true; // or false for slave
out.begin(cfg);
// setup resample from 42100 to 48000
resample.begin(from_info, to_info.sample_rate);
// start a2dp
a2dp_sink.start("Esp Device");
}
void loop() {
delay(1000); // do nothing
} |
Beta Was this translation helpful? Give feedback.
-
So, the performance has improved, I can now hear the music playing, it is just accompanied by lots of static and some volume changes. I believe part of my issue is because on the other end I have a differing slot width and word size (slot_width = 32 and word_size = 24) is there a way to accommodate that in your code while formatting the data to align to the left? |
Beta Was this translation helpful? Give feedback.
The sample rate is defined by the ESP32 A2DP and can't be changed.
I don't understand what you mean with second device, but if your output DAC only supports 48000, you need to resample. The AudioTools library provides the functionality and documentation how to do this!