Re: A2dp sink volume control?
Posted: Wed Aug 26, 2020 9:45 pm
Thanks so much for sharing! You were right, the issue had to do with the fact that the volume data is 8 MSB (instead of 16). Your fix worked, although we also have to change the code to only parse through one byte at a time (numBytesShifted = 1). Here's the volume change function with that fix:
There's a big jump from master_volume = 8 --> 7. I'm assuming that has to do with the data only being 8-bit though.
Setting .communication_format = I2S_COMM_FORMAT_I2S_MSB didn't seem to make a difference. Let me know if you think otherwise.
Thanks again!
- Steven
Code: Select all
//the following code changes the volume
uint8_t *volume_control_changeVolume(uint8_t *data, uint8_t *outputData, size_t size, uint8_t volume) {
const int numBytesShifted = 1;
int16_t pcmData;
bool isNegative;
memcpy(outputData, data, size);
size_t h = 0;
for (h = 0; h < size; h += numBytesShifted) {
pcmData = data[h];
isNegative = pcmData & 0x80;
if (isNegative)
pcmData = (~pcmData) + 0x1;
pcmData = pcmData >> (8 - volume);
if (isNegative)
pcmData = (~pcmData) + 0x1;
outputData[h] = pcmData;
}
return outputData;
}Setting .communication_format = I2S_COMM_FORMAT_I2S_MSB didn't seem to make a difference. Let me know if you think otherwise.
Thanks again!
- Steven