From 898e9603195ea6fc737790d5b75282b72b17e62b Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Tue, 27 Mar 2018 06:41:43 -0700 Subject: [PATCH] Use plain square wave, 8192 amplitude (25%) volume An I2S bug in core ESP8266 Arduino was causing the square wave to fail, not an I2S DAC problem. Move back to the square wave and save some PROGMEM space and make it simpler and faster. --- src/AudioGeneratorRTTTL.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/AudioGeneratorRTTTL.cpp b/src/AudioGeneratorRTTTL.cpp index 1845949..b45254b 100644 --- a/src/AudioGeneratorRTTTL.cpp +++ b/src/AudioGeneratorRTTTL.cpp @@ -51,16 +51,6 @@ bool AudioGeneratorRTTTL::isRunning() return running; } -// Can't do pure square wave, the I2S DACs don't like being fed them -static int16_t period[64] PROGMEM = { - 250, 500, 1000, 2000, 4000, 8000, 16000, 32000, 32000, 31000, 32000, 31000, - 32000, 31000, 32000, 31000, 32000, 31000, 32000, 32100, 32000, 31000, 32000, - 31000, 32000, 32000, 16000, 8000, 4000, 2000, 1000, 500, - -250, -500, -1000, -2000, -4000, -8000, -16000, -32000, -32000, -31000, - -32000, -31000, -32000, -31000, -32000, -31000, -32000, -31000, -32000, - -32100, -32000, -31000, -32000, -31000, -32000, -32000, -16000, -8000, - -4000, -2000, -1000, -500 }; - bool AudioGeneratorRTTTL::loop() { if (!running) goto done; // Nothing to do here! @@ -84,8 +74,7 @@ bool AudioGeneratorRTTTL::loop() while (samplesSent < ttlSamples) { int samplesSentFP10 = samplesSent << 10; int rem = samplesSentFP10 % ttlSamplesPerWaveFP10; - rem = (64 * rem) / ttlSamplesPerWaveFP10; - int16_t val = pgm_read_word(&period[rem]); + int16_t val = (rem > ttlSamplesPerWaveFP10/2) ? 8192:-8192; int16_t s[2] = { val, val }; if (!output->ConsumeSample(s)) goto done; samplesSent++;