end2endzone / nonblockingrtttl Goto Github PK
View Code? Open in Web Editor NEWNonBlockingRTTTL is a non-blocking arduino library for playing RTTTL melodies.
License: MIT License
NonBlockingRTTTL is a non-blocking arduino library for playing RTTTL melodies.
License: MIT License
I've been struggling to get a tune to sound right, and eventually realised that NonBlockingRTTTL doesn't parse RTTTL in the way I expected.
The problem occurs with dotted notes that are not in the default octave, which I thought should be written as a4.
but this library expects a.4
The confusion seems to arise because the 'language' is poorly specified. I don't know if there's a canonical definition anywhere, but I found a Backus-Naur specification which includes:
<note> := [<duration>] <note> [<scale>] [<special-duration>] <delimiter>
That puts the dot (the 'special-duration') at the end. But the same document includes g.6
in its example, cleverly contradicting itself.
Wikipedia says 'Dotted rhythm patterns can be formed by appending a period (".") character to the end of a duration/beat/octave element.'
I suggest that NonBlockingRTTTL should allow for either dot position -- simply by repeating the short bit of code that consumes the dot and extends the note's duration after the section that deals with the octave. That would avoid breaking anyone's existing tunes, and make it easier for people to get new tunes to work.
Cheers,
Chris
RTX ringtones are superset of RTTTL. It adds style and loops option. I've implemented it to my library (before I discovered there are much more Arduino RTTTL libs on the internet).
See migration notes:
https://docs.espressif.com/projects/arduino-esp32/en/latest/migration_guides/2.x_to_3.0.html
Scroll down to LEDC:
"ledcAttach used to set up the LEDC pin (merged ledcSetup and ledcAttachPin functions)."
GitHub automatically generates .zip files of the repository contents. Moving the library to the root of the repository would allow that file to be used for installation, rather than requiring this complex deployment process. This will allow users to follow the same installation process as they would use for any other Arduino library hosted on GitHub, rather than a non-standard process.
This repository structure is also required if you want to add your library to the Arduino Library Manager index, which provides an even easier installation and update process for the users.
My proposed repository structure is:
NonBlockingRTTL (repository root)
|_library.properties
|_keywords.txt
|_examples
|_src
|_NonBlockingRtttl.h
|_NonBlockingRtttl.cpp
That is the Arduino Library Format 1.5. If you prefer the 1.0 format then the source files can be placed in the repository root instead of in the src subfolder.
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:
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
}
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.