Musical Notes, Octaves, Durations & Dots from Sheet Music
DanNale7
Posts: 9
Can some one please lead me to the source code in SPIN that enables songs to be played on the Propeller. I have source code for the different frequencies but I am not sure how to get the Octave and Durations & Dots. I have the code for the BASIC STAMP but I am not sure how to convert it to the SPIN language.
Thanks in advance!
Dan
Thanks in advance!
Dan
Comments
Audio Signal Processing
on the Parallax Propeller
Multiprocessor Microcontroller
2.4 Musical Score Notation ........
http://petehemery.github.io/Final-Year-Project/Dissertation.pdf
Have a look at the attached code in this post:(HemPeter )
http://forums.parallax.com/showthread.php/140777-Audio-Signal-Processing-on-the-Propeller-Demo-Board?p=1105502#post1105502
http://forums.parallax.com/showthread.php/139362-Parallax-2x16-Serial-LCD-(27977)-Backlit-w-Spkr-Example-Prop-snd-SPIN-code
I pulled this off from someone's forum post. It looks like there's a few methods from BS2_Functions in it.
I know I added to it but I don't remember what's mine and what was originally in it.
I'm not sure, but I think I added the "note" array in the DAT section (or I might have just rearranged it).
A great resource for sound generation is the S2 GUI. I often just use the GUI to produce cool sounding effects and then cut and paste the generated Spin code into my program.
The most interesting item is that the Propeller has Log Base 2 tables and these can be useful in creating a musical scale with precise frequencies. If you ponder the scale, it is very closely related to Log Base 2.
Midi is a code convention. The Propeller can handle it quite well, but you really have to learn to think and use Midi. The biggest advantage is there are keyboards and software that conform to it. So you have more resources available to create, replicate, and input music.
Timing really remains independent of the music scale. Getting the right note is just half the battle. The other half is to provide the right duration with it all based on the correct underlying tempo.
And so, it seems that one either joins the Midi crowd.. which includes a lot of musicians OR one has to provide three items from scratch [a] tempo, scale, [c] timing of each note.
Much depends on your appetite for low level programming versus your desire to create music.
For instance after creating a music vocabulary each note and control is a word in the dictionary and this might be the way you would write the first part of Ode to Joy for instance.
& OdeToJoy E E F G G F E D C C D E . E ^ D o D |
The & is really just a : word while the | is equivalent to a ;
I can probably write a quick demo and post a video if anyone fancies that.
Thank you for the response and the spin code. I have attempted to use it and I am not exactly sure why I can not get it to work. Where do you set the piezospeaker PIN in the code?
Dan
Sorry, I didn't know your experience level.
The program I posted needs to be called from a parent object.
I'll post a short demo soon (it should be today).
This is more in line with what I am attempting to accomplish. Please post some of your progress in this area.
Thanks!
Dan
One of the methods I added to the Piezo object is "PlaySong".
I translated a few of my sound effect songs generated by the S2 GUI into a format used by "PlaySong".
The first number is the duration followed by the index number of the note array which contains the frequency.
You could easily define the index numbers with A1, C3 etc.
The note array doesn't include any sharps or flats. I don't think it would be very hard to add sharps or flats to the array. You'd need to adjust the index numbers used in the songs if you did so.
The "songs" listed above are played with the code:
As others have mentioned, there are a lot of really good objects for playing sounds on the Propeller. I wouldn't include the attached program in the list of "good" sound programs for the Propeller the attached program will probably be easier to understand than the more advanced programs. The only PASM is in the serial driver.
Make sure and change the constant "PIEZO_PIN" to match your setup.
Wow!
That's a lot of great information.
Thank you for the links.
That is truly amazing! I wanted to program some Christmas Songs and Lights for a project and I need to get through the SPIN source code programing first. Let me know if you decide to put in the sharps and the flatsand the durations of the notes.
Thank you again! Very impressive!
Dan
The code I posted earlier had a total of 25 notes and didn't include any sharps or flats.
The code attached to this post has 108 notes and includes all the notes listed on this webpage. Since the page listed the frequencies to a tenth of a Hertz, I multiplied the given frequency by ten so this extra precision could hopefully be included. I really doubt the extra precision matters when playing the note through a piezo speaker.
There's the new note array:
The array "majorScale" is used to skip the sharps and flats when playing a scale.
To make it easier to enter music in the DAT section, I used constant names for each of the notes. I also included constant names for the note duration.
The duration can still be listed in milliseconds but now there's also the option of using one of the timing names.
Here's how one of the songs looks using constants to set duration and notes.
The constant "T4" is used to indicate a quarter note. The constant "T1_" is a dotted whole note. I used the underscore to indicate a duration is to be half again as long as the duration of the denoted by the constant without an underscore.
The duration of a quarter note defaults to 250ms but this duration can be changed with the "SetQuarterNoteTime" method. The duration times are also changed when the method is called.
I've included a way to enter notes using the keyboard as an input device.
When the keyboard mode is entered (either by pressing "k" at the beginning of the program or by pressing "x" and then "k" once the demo loop has started), the following text will be displayed in the terminal window.
The note corresponding to the above listed keys will continue to play until a different note is selected or is any other key on the keyboard is pressed.
As I previously mentioned, there are 108 notes in the array. Not all of these 108 notes are appropriate for use with a piezo speaker. Some of the notes sound more like clicking than a tone on my piezo speaker.
This is one of those projects I do when I'm avoiding some other project. There are lots of really great sound programs for the Propeller, I think this particular program fills a need that never existed. If you want to make music by pressing keys on your computer's keyboard, there are a lot of better ways to do it than by using the attached program.
The program does make it pretty easy to enter music into the DAT section for later playback.
Let me know if anyone has any questions about this monstrosity.
Edit: I just noticed a bug in the way the notes are displayed with the keyboard chart. I'll fix and and upload the fixed version in a bit. If you download this version (e) make sure and come back the fixed version.
Edit again: The bug has been fixed. I changed the output display above to show what the corrected code displays.
Edit(3/11/15): Warning, the code attached is an old version. There are likely better options available.
I plan to upload this program or an improved version to my GitHub account
If there isn't code similar to what is attached here on my on GitHub, send me a message and I'll make and check for any improved versions of the code.