-
Notifications
You must be signed in to change notification settings - Fork 10
Description
There is a bug at the end of playing a sound with respect to the ESP8266 environment. I don't know if this also is an issue on other processors.
The issue is that the library does not explicitly call noTone() at the end of playback. This leaves the sound pin active and in the case of the 8266 it creates 'noise' on the pin as the CPU executes other code. It is particularly noticeable during uploads of code over serial.
The fix is as follows. In file NonBlockingRtttl.cpp do the following:
- Replace line 270 in the
play()routine with a call tostop()
//ready to play the next note
if (*buffer == '\0')
{
//no more notes. Reached the end of the last note
#ifdef RTTTL_NONBLOCKING_DEBUG
Serial.println("end of note...");
#endif
270:-> stop(); // playing = false; // replace this line with a call to stop();
return; //end of the song
}- Add a call to
noTone()in thestop()routine on line 295 where you are currently settingplayingto false.
void stop()
{
if (playing)
{
//increase song buffer until the end
while (*buffer != '\0')
{
buffer++;
}
295:-> noTone(pin); // add a call to noTone() here
playing = false;
}
}These two changes actually fix 2 bugs. First, it fixes a bug where the sound isn't disabled at the end of normal playback. Second, it fixes a bug where sound isn't disabled if you abort playback using the stop() command.
If desired, I can submit this as a pull request. Otherwise, just make these two one line changes and call it good.