Skip to content

Commit

Permalink
Use plain square wave, 8192 amplitude (25%) volume
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
earlephilhower committed Mar 27, 2018
1 parent 66d1f37 commit 898e960
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions src/AudioGeneratorRTTTL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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++;
Expand Down

0 comments on commit 898e960

Please sign in to comment.