I had the issue that the 24 bit output via A2DP was not working, but the corresponding 32 bit example was just working fine.
So I decided to double check the I2S output with the help of a logical analyzer.
Checking 16 bits
First I was double checking how the working 16 bit is showing up. So I used the following Arduino Sketch which was just outputting some unique numbers per byte:
#include "AudioTools.h"
AudioInfo info{44100, 2, 16};
I2SStream i2s;
uint8_t data[] = {0x01,0x02,0x03,0x04};
void setup() {
auto cfg = i2s.defaultConfig(TX_MODE);
cfg.copyFrom(info);
i2s.begin(cfg);
}
void loop() {
i2s.write(data, sizeof(data));
}
This is showing up in PulseView as follows, with the byte sequence reversed:
Checking 24 bits
So it is time now to check the output of 24 bits:
#include "AudioTools.h"
AudioInfo info{44100, 2, 24};
I2SStream i2s;
uint8_t data[] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
void setup() {
auto cfg = i2s.defaultConfig(TX_MODE);
cfg.copyFrom(info);
i2s.begin(cfg);
}
void loop() {
i2s.write(data, sizeof(data));
}
So as indicated in the documentation, the least significant (and in this case the first) byte gets ignored:
So this is working as expected.
Further Tests
Then I executed the test with a 24 bit sine tone and one with a 16 bit sine, that gets converted to 24 bits. All w/o any issues: so there is no problem in my 24 bit functionality in the AudioTools and it is working properly.
But it still remains a mistery to me why the very same thing generated from A2DP is not working and generates noise. This does not make any sense!
5 Comments
LuckyWinner · 23. January 2025 at 22:13
I have more or less an identical problem, thats why i read the discribtion of the libery of espressif. I remember that somewhere its was disribed that if 24-bit is used the MCLK should be at a multiple of 3 to avoid errors.
For me it would be of interessed how to convert a 16-bit and 44100Hz stereo signal to something that is ether 32-bit or 88200Hz to double the output BCLK to be at minimum 2.048 MHz, because i am needing that for the communication to a Amplifier. But the AudioTools are to big to fit with the A2DP onto the ESP32 i am using, is there an other way?
pschatzmann · 23. January 2025 at 22:23
Your comments about the memory doesn’t make any sense: please open a discussion on github:
Sketch uses 1944545 bytes (48%) of program storage space. Maximum is 4038656 bytes.
Please also read the Wiki of the AudioTools: there is a chapter about format changes
James · 18. December 2024 at 22:15
Wowwie, very cool
JyS · 16. November 2024 at 13:05
Interesting problem. I dont have answer, but I have general finding due to working with I2S ADCs and DACs. There is no such thing as 24 bit audio format. Only 16 bit and 32 bit. 24 bit audio data always transferred by 32 bit frame and 8 least significant bits are zero.
pschatzmann · 16. November 2024 at 13:09
I agree: The AudioTools uses the int24_4bytes_t to exactly implement it like this and the tests confirm that this is working as expected.