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