Skip to content

Bug for ESP8266 environment - noTone not called at end of sound #6

@jbrown123

Description

@jbrown123

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:

  1. Replace line 270 in the play() routine with a call to stop()
  //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
  }
  1. Add a call to noTone() in the stop() routine on line 295 where you are currently setting playing to 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions