Remove 8-bit handling in output, promote WAV/FLAC to 16 (#782)

Only the WAV and FLAC generators can generate 8-bit values, so it is
more efficient and sane to just have those generators upscale to 16-bit
signed (if necessary) in generation and simplify all the other
Generators and Outputs.
This commit is contained in:
Earle F. Philhower, III authored and GitHub committed 2025-10-13 09:56:39 -07:00
1 parent 724b6d606e
commit 058e131b26
29 files changed
+43 -163

No files matched your search

+7 -12
View File
@@ -65,15 +65,10 @@ bool AudioOutputSPIFFSWAV::begin() {
bool AudioOutputSPIFFSWAV::ConsumeSample(int16_t sample[2]) {
for (int i = 0; i < channels; i++) {
if (bps == 8) {
uint8_t l = sample[i] & 0xff;
f.write(&l, sizeof(l));
} else {
uint8_t l = sample[i] & 0xff;
uint8_t h = (sample[i] >> 8) & 0xff;
f.write(&l, sizeof(l));
f.write(&h, sizeof(h));
}
uint8_t l = sample[i] & 0xff;
uint8_t h = (sample[i] >> 8) & 0xff;
f.write(&l, sizeof(l));
f.write(&h, sizeof(h));
}
return true;
}
@@ -97,14 +92,14 @@ bool AudioOutputSPIFFSWAV::stop() {
wavHeader[25] = (hertz >> 8) & 0xff;
wavHeader[26] = (hertz >> 16) & 0xff;
wavHeader[27] = (hertz >> 24) & 0xff;
int byteRate = hertz * bps * channels / 8;
int byteRate = hertz * 16 * channels / 8;
wavHeader[28] = byteRate & 0xff;
wavHeader[29] = (byteRate >> 8) & 0xff;
wavHeader[30] = (byteRate >> 16) & 0xff;
wavHeader[31] = (byteRate >> 24) & 0xff;
wavHeader[32] = channels * bps / 8;
wavHeader[32] = channels * 16 / 8;
wavHeader[33] = 0;
wavHeader[34] = bps;
wavHeader[34] = 16;
wavHeader[35] = 0;
int datasize = f.size() - sizeof(wavHeader);