Nokia melody player #2292
-
|
I am trying to create a Nokia melody (old ringtone) player using SineWaveGenerator and StreamCopy. I can get the notes to play but they all roll into a constant playback with no rests between notes. I am setting up the sinewave output as follows: and Then play the note as follows: There is then a delay of 20mS before then next note is played. Is there a way of stopping the audio output or playing silence for the 20mS ? |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 2 replies
-
|
Why don't you just use the RTTTLOutput class for this ? You can also use the apprach used by that class which is just setting the frequency to 0 to switch off the tone. |
Beta Was this translation helpful? Give feedback.
-
|
I totally miissed that class, I will give it a try, thank you. |
Beta Was this translation helpful? Give feedback.
-
|
Okay, used the example to get it working but Sax was just too buzzy but managed to get the SineWaveGenerator working with it. Only issue I have is changing the output amplitude. I have tried a GeneratedSoundStream and VolumeStream but the RTTTLOutput class will not take the VolumeStream object. How can I chnage the amplitude before playing. Currently using: and |
Beta Was this translation helpful? Give feedback.
-
|
In the SineWaveGenerator you currently define an amplitude of 32000 which might be a bit loud: why don't you just decrease this value ? You can also just add a VolumeOutput (or VolumeStream) to the chain: I2SStream i2s;
VolumeOutput vol(i2s);
SineWaveGenerator<int16_t> sineWave(32000);
RTTTLOutput<int16_t> rtttl(sineWave, vol);
|
Beta Was this translation helpful? Give feedback.
-
|
Okay, the VolumeStream on the i2s object worked well I can now change the volume on the fly. One final question is it possible to stop and restart the playback. I have tried undertaking a rtttl.end() and sineWave.end(); before starting things off again, as above, but I just get clicks in time with the duration of the current playback followed by the new playback so it sounds llike the rtttl.end() is not releasing from the play_notes() function in RTTTLOutput.h |
Beta Was this translation helpful? Give feedback.
-
|
Not sure what you mean with stop: If you want to abort playing a longer tune, you would just write out the tune (in the loop) in smaller pieces. I recommend to call begin() before replaying the same or another tune, though in most cases it might do this automtically. |
Beta Was this translation helpful? Give feedback.
-
|
A mechanism that allows the currently playing tune to stop playback. So what you would recommend is to break the tune down into shorter sections and feed this to rtttl.print() in chunks, seems like a way around it if thats waht you mean. |
Beta Was this translation helpful? Give feedback.
-
|
I have tried breaking the tune down into the first configuration section + one note and then individual notes with each one as a note + comma and rtttl.print() each of these and it does not work, I get the first note and then nothing is played. |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for your help, I will try it out. |
Beta Was this translation helpful? Give feedback.
Why don't you just use the RTTTLOutput class for this ?
You can also use the apprach used by that class which is just setting the frequency to 0 to switch off the tone.
Don't use millis(), but the calculated number of samples to drive your processing: e.g. you could use the StreamCopy copyMs() for this.