32bit sound on PCM5102A with new librarys. #541
-
Code from "bt_music_receiver_32bits.ino" give me strange compilation error for DOITESP32 DEVKIT V1 board ? Using library audio-tools at version 0.9.6 in folder: C:\Users\ccc\Documents\Arduino\libraries\arduino-audio-tools-main Compilation error: text section exceeds available space in board |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments 27 replies
-
Just connect the default pins as documented in the Readme or define the pins that you used in the sketch |
Beta Was this translation helpful? Give feedback.
-
In old library i use trick for prevent PCM5102 DAC from audio "0" detecting with add small static error (pcmLeft+1) :
where in new lib i manage this ? |
Beta Was this translation helpful? Give feedback.
-
I am not sure if your formula makes any sense. But that's your responsibility! This has not been tested, but to give some directions: Alternative 1Adapting the old example: class BluetoothA2DPSink32 : public BluetoothA2DPSink {
protected:
void audio_data_callback(const uint8_t *data, uint32_t len) {
ESP_LOGD(BT_AV_TAG, "%s", __PRETTY_FUNCTION__);
// update volume
volume_control()->update_audio_data((Frame*)data, len/4);
// data is provided as array of int16
int sample_count = len / sizeof(int16_t);
int16_t* data16 = static_cast<int16_t*>(data);
for (int j=0; j<sample_count; j++){
// convert to 32 bit data
int32_t sample32 = static_cast<int32_t>(data16[j]) << 16;
// add your special logic here
// output 32 bits to DAC
out->write((uint8_t*)&sample32, sizeof(sample32);
}
};
AudioInfo info(44100, 2, 32);
I2SStream out;
BluetoothA2DPSink32 a2dp_sink(out);
void setup() {
Serial.begin(115200);
// AudioLogger::instance().begin(Serial, AudioLogger::Info);
// Configure i2s to use 32 bits
auto cfg = out.defaultConfig();
cfg.copyFrom(info);
out.begin(cfg);
// start a2dp
a2dp_sink.start("AudioKit");
}
void loop() {
delay(1000); // do nothing
} Alternative 2Use the latest AudioTools you can add a formula to a converter #include "AudioTools.h"
#include "AudioLibs/AudioBoardStream.h" // install https://github.com/pschatzmann/arduino-audio-driver
#include "BluetoothA2DPSink.h"
AudioInfo info(44100, 2, 32);
I2SStream out;
// just add 1 to the output
CallbackConverterT<int32_t> converter([](int32_t in, int channel) { return in+1; });
ConverterStream cs(out, converter);
NumberFormatConverterStream convert32(cs);
BluetoothA2DPSink a2dp_sink(convert32);
void setup() {
Serial.begin(115200);
// AudioLogger::instance().begin(Serial, AudioLogger::Info);
// Configure i2s to use 32 bits
auto cfg = out.defaultConfig();
cfg.copyFrom(info);
out.begin(cfg);
// Convert from 16 to 32 bits
convert.begin(16, 32);
// start converter stream
cs.begin();
// start a2dp
a2dp_sink.start("AudioKit");
}
void loop() {
delay(1000); // do nothing
} Alternative 3Just use the callback method #include "BluetoothA2DPSink.h"
AudioInfo info(44100, 2, 32);
I2SStream out;
BluetoothA2DPSink a2dp_sink(out);
// callback
void get_audio_data(const uint8_t *data, uint32_t len) {
// data is provided as array of int16
int sample_count = len / sizeof(int16_t);
int16_t* data16 = static_cast<int16_t*>(data);
for (int j=0; j<sample_count; j++){
// convert to 32 bit data
int32_t sample32 = static_cast<int32_t>(data16[j]) << 16;
// add your special logic here
// output 32 bits to DAC
out.write((uint8_t*)&sample32, sizeof(sample32);
}
void setup() {
// Configure i2s to use 32 bits
auto cfg = out.defaultConfig();
cfg.copyFrom(info);
out.begin(cfg);
a2dp_source.start_raw("MyMusic", get_audio_data, false);
}
|
Beta Was this translation helpful? Give feedback.
-
I did not try the whole example, but the line CallbackConverterT<int32_t> converter([](int32_t in, int channel) { return in+1; }); only compiles |
Beta Was this translation helpful? Give feedback.
-
In A2DPVolumeControl.h is the very similar code like in BluetoothA2DPSink32.h
Why do not use A2DPVolumeControl for my needs? This is very important, otherwise classical music cannot be heard even in 32-bit mode with the PCM5102A! In any way second problem is about volume managing, because min volume from iPHONE is very loud. |
Beta Was this translation helpful? Give feedback.
-
I talk about last v3 code, which is not compile : #include "AudioTools.h" AudioInfo info(44100, 2, 32); // callback void setup() { // Configure i2s to use 32 bits a2dp_source.start_raw("MyMusic", get_audio_data, false); |
Beta Was this translation helpful? Give feedback.
-
The following corrected code does not give any compile errors: #include "AudioTools.h"
#include "BluetoothA2DPSink.h"
AudioInfo info(44100, 2, 32);
I2SStream out;
BluetoothA2DPSink a2dp_sink(out);
// callback
void get_audio_data(const uint8_t *data, uint32_t len) {
// data is provided as array of int16
int sample_count = len / sizeof(int16_t);
int16_t* data16 = (int16_t*) data;
for (int j = 0; j < sample_count; j++) {
// convert to 32 bit data
int32_t sample32 = static_cast<int32_t>(data16[j]) << 16;
// add your special logic here
// output 32 bits to DAC
out.write((uint8_t*)&sample32, sizeof(sample32));
}
}
void setup() {
// Configure i2s to use 32 bits
auto cfg = out.defaultConfig();
cfg.copyFrom(info);
out.begin(cfg);
// data callback with no output
a2dp_sink.set_stream_reader(get_audio_data, false);
a2dp_sink.start("MyMusic");
}
void loop(){}
|
Beta Was this translation helpful? Give feedback.
-
Thank you very much Phil, now the sound from the PCM5102A is excellent, of course as much as the self-noise of the chip allows. |
Beta Was this translation helpful? Give feedback.
-
I see it that way : A2DPSimpleExponentialVolumeControl volumeControl; uint8_t volumeLevel = 0; volumeControl.set_volume(volumeLevel); int32_t volumeFactor = volumeControl.get_volume_factor(); int32_t maxVolumeFactor = volumeControl.get_volume_factor_max(); |
Beta Was this translation helpful? Give feedback.
-
No, these methods are called by the sink. You just follow the documentation! |
Beta Was this translation helpful? Give feedback.
-
Here is my version of adaptable exponential volume control : /**
class A2DPSimpleExponentialVolumeControl2 : public A2DPVolumeControl { Here is curves, yellow is rbruelma, blue is my: |
Beta Was this translation helpful? Give feedback.
RTFM