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!
3 Comments
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.