I was tinkering around with different options for generating sound and I thought I would share this. It executes Music Macro Language scripts and will play them on the speaker. Ideal for a music track in your RETRO game…
@ Architect - I would be interested in comparing notes. For my games I am submitting I have a 4 channel sound effecs engine, at most I am only using 2 channels. I fiddled with many different approaches, will be nice to see some other ideas.
Hi @ taylorza - I just tried it out and your example works great!
However, when trying it in my current project, I did notice noise coming from the speaker when not playing music. Still figuring out what causes that (and replacing some older code).
(BTW: to compare it with other code, I also tried the PwmSound library by Paul Griffith on the Retro, but the test program I couldn’t get to work on the Retro. Unfortunately I have no time to debug or try others)
To silence the speaker I am setting the PWM duty cycle and period to 0, but there still seems to be a hum on the speaker. I have not looked at the PWM implementation in any detail to understand the best way to eliminate the hum, but what might do the trick is to just change the pin function to GPIO and back to PWM when needed. I will give it a shot when I get home this evening. Thanks.
@ wilgeorge - I sleep far too little, I feel it every morning
I compared the code to the pong sample. One way to succesfully stop the humming:
I guess the silencing is executed when reinitializing, as the write does the same as the assignment you have in your code. Unfortunately combining this with my code gave unwanted clicks. For now best silencing was obtained by adding this code to the constructor and to the executeCommand() method of the MusicEngine class: