Fix u8 upsampling and mono mode for AudioGeneratorWAV (#802)
For AudioGeneratorWAV, the upsample from u8 to i16 bits has been fixed. Previously, playback of wav files with u8 encoding resulted in silence. The data was read, but not used in calculations. Additionally, in mono mode, I removed the unnecessary resolution increase for the second channel and implemented simple duplication. Now, when playing mono wav files, the audio will be in both the left and right channels.
This commit is contained in:
1 parent
3450935a2a
commit
70defdb6c6
1 file changed
+9
-10
@@ -87,22 +87,21 @@ bool AudioGeneratorWAV::loop() {
|
||||
// Try and stuff the buffer one sample at a time
|
||||
do {
|
||||
if (bitsPerSample == 8) {
|
||||
uint8_t l, r;
|
||||
if (!GetBufferedData(1, &l)) {
|
||||
uint8_t u8s; // For read u8 sample
|
||||
if (!GetBufferedData(1, &u8s)) {
|
||||
stop();
|
||||
}
|
||||
// Upsample from unsigned 8 bits to signed 16 bits
|
||||
lastSample[AudioOutput::LEFTCHANNEL] = ((int16_t)u8s - 128) << 8;
|
||||
if (channels == 2) {
|
||||
if (!GetBufferedData(1, &r)) {
|
||||
if (!GetBufferedData(1, &u8s)) {
|
||||
stop();
|
||||
}
|
||||
// Upsample from unsigned 8 bits to signed 16 bits
|
||||
lastSample[AudioOutput::RIGHTCHANNEL] = ((int16_t)u8s - 128) << 8;
|
||||
} else {
|
||||
r = 0;
|
||||
lastSample[AudioOutput::RIGHTCHANNEL] = lastSample[AudioOutput::LEFTCHANNEL];
|
||||
}
|
||||
|
||||
// Upsample from unsigned 8 bits to signed 16 bits
|
||||
lastSample[AudioOutput::LEFTCHANNEL] = (((int16_t)(lastSample[AudioOutput::LEFTCHANNEL] & 0xff)) - 128) << 8;
|
||||
lastSample[AudioOutput::RIGHTCHANNEL] = (((int16_t)(lastSample[AudioOutput::RIGHTCHANNEL] & 0xff)) - 128) << 8;
|
||||
|
||||
} else if (bitsPerSample == 16) {
|
||||
if (!GetBufferedData(2, &lastSample[AudioOutput::LEFTCHANNEL])) {
|
||||
stop();
|
||||
@@ -112,7 +111,7 @@ bool AudioGeneratorWAV::loop() {
|
||||
stop();
|
||||
}
|
||||
} else {
|
||||
lastSample[AudioOutput::RIGHTCHANNEL] = 0;
|
||||
lastSample[AudioOutput::RIGHTCHANNEL] = lastSample[AudioOutput::LEFTCHANNEL];
|
||||
}
|
||||
}
|
||||
} while (running && output->ConsumeSample(lastSample));
|
||||
|
||||
Reference in new issue
Block a user