Fix overflow for 256x oversampling

Fixes #55
This commit is contained in:
Earle F. Philhower, III committed 2018-02-08 17:39:51 -08:00
1 parent 0bb859037b
commit 54498a21a0
2 files changed
+5 -4

No files matched your search

+1
View File
@@ -65,6 +65,7 @@ AudioOutputI2S::AudioOutputI2S(int port, bool builtInDAC, int use_apll)
i2s_zero_dma_buffer((i2s_port_t)portNo);
}
#else
(void) use_apll;
if (!i2sOn) {
i2s_begin();
}
+4 -4
View File
@@ -47,9 +47,9 @@ bool AudioOutputI2SNoDAC::SetOversampling(int os) {
return SetRate(hertz);
}
void AudioOutputI2SNoDAC::DeltaSigma(int16_t sample[2], uint32_t dsBuff[4])
void AudioOutputI2SNoDAC::DeltaSigma(int16_t sample[2], uint32_t dsBuff[8])
{
// // Not shift 8 because addition takes care of one mult x 2
// Not shift 8 because addition takes care of one mult x 2
int32_t sum = (((int32_t)sample[0]) + ((int32_t)sample[1])) >> 1;
fixed24p8_t newSamp = ( (int32_t)Amplify(sum) ) << 8;
@@ -83,7 +83,7 @@ bool AudioOutputI2SNoDAC::ConsumeSample(int16_t sample[2])
MakeSampleStereo16( sample );
// Make delta-sigma filled buffer
uint32_t dsBuff[4];
uint32_t dsBuff[8];
DeltaSigma(sample, dsBuff);
// Either send complete pulse stream or nothing
@@ -92,7 +92,7 @@ bool AudioOutputI2SNoDAC::ConsumeSample(int16_t sample[2])
return false;
#else
if (!i2s_write_sample_nb(dsBuff[0])) return false; // No room at the inn
// At this point we've sent in first of possibly 4 32-bits, need to send
// At this point we've sent in first of possibly 8 32-bits, need to send
// remaining ones even if they block.
for (int i = 32; i < oversample; i+=32)
i2s_write_sample( dsBuff[i / 32]);