Shop OBEX P1 Docs P2 Docs Learn Events
Music — Parallax Forums

Music

AImanAIman Posts: 531
edited 2006-07-26 03:27 in Robotics
Why are my pauses screwing up? I can't seem to get the note·lengths correct. Does anyone know how long it should be between notes? The code isn't complete in the sense that the song isn't finished, however it should be ready to run for those who want to hear it. Note length for things like quater notes, half notes and so on are easy to figure out for duration, but how long should each not be seperated by silence to make it sound like a clear tune?

The biggest problem is that I can't get a distinct break in the notes without a pause. At this point I am not worried so much about shortcuts as getting the notes to be the right length and have a clean break. The Pause 15 makes a pretty clean break but it still sounds kind of wierd to me and I am having trouble pinpointing why. (I don't mean incorrect notes, I mean the rests for the music).

' {$STAMP BS2}
' {$PBASIC 2.5}

FREQOUT 9,500,1047··· ' C6
FREQOUT 9,250,1175··· ' D6
PAUSE 15
FREQOUT 9,500,1319··· ' E6
PAUSE 15
FREQOUT 9,250,1175··· ' D6
PAUSE 15
FREQOUT 9,350,1319··· ' E6
PAUSE 15
FREQOUT 9,350,1175··· ' D6
PAUSE 15
FREQOUT 9,500,1319··· ' E6
PAUSE 50

FREQOUT 9,500,1175··· ' D6
PAUSE 5
FREQOUT 9,250,1319··· ' E6
PAUSE 15
FREQOUT 9,200,1396··· ' F6
PAUSE 15
FREQOUT 9,200,1396··· ' F6
PAUSE 15
FREQOUT 9,300,1319··· ' E6
PAUSE 15
FREQOUT 9,300,1175··· ' D6
PAUSE 15
FREQOUT 9,500,1396··· ' F6
PAUSE 100

FREQOUT 9,500,1319··· ' E6
PAUSE 15
FREQOUT 9,250,1396··· ' F6
PAUSE 15
FREQOUT 9,300,1568··· ' G6
PAUSE 15
FREQOUT 9,200,1319··· ' E6
PAUSE 15
FREQOUT 9,250,1568··· ' G6
PAUSE 15
FREQOUT 9,250,1319··· ' E6
PAUSE 15
FREQOUT 9,450,1568··· ' G6
PAUSE 50

Thoughts?
·

Comments

  • Kevin WoodKevin Wood Posts: 1,266
    edited 2006-07-24 04:34
    You'll probably need to try different values untill it starts sounding right, but PAUSE 15 only pauses 15/1000th of a second. Try starting with 100-150.

    Also, try setting your pauses as constants:

    ShortPause CON 50
    MediumPause CON 150
    LongPause CON 450

    Then you can write your code as:

    FREQOUT 9,250,1568 ' G6
    PAUSE ShortPause
    FREQOUT 9,250,1319 ' E6
    PAUSE MediumPause
    FREQOUT 9,450,1568 ' G6
    PAUSE LongPause

    This way, changing the value at the CON statement will update all of your values at once.

    You could set up timing constants for your notes & rests, and insert the constant names in the FREQOUT statements.

    So this:

    FREQOUT 9,450,1568 ' G6
    PAUSE 50


    Becomes:

    '---- Rest Durations ----
    QtrRest CON 450

    '---- Note Durations ----
    QtrNote CON 450

    '---- Note Pitches ----
    G6 CON 1568

    ' ---- Fur Elise by Beethoven ----
    ' ---- Format is FREQOUT Pin,Note Duration,Note Pitch ----

    FREQOUT 9,QtrNote,G6
    PAUSE QtrRest


    Doing this helps to make your code self documenting, and it reads much easier:

    On Pin 9, play a quarter note of G6, pause for a quarter rest...
  • SSteveSSteve Posts: 808
    edited 2006-07-24 04:38
    AIman said...
    how long should each not be seperated by silence to make it sound like a clear tune?
    It depends on the tune. Rests have durations the same as notes. If a quarter note in your tune lasts XX milliseconds then a quarter rest will last the same. I'm not set up to run your code at the moment, but from the pitches I'm guessing it's "Doe a Deer...". If so, the timings don't look right. The first and third notes should be three times as long as the second and fourth notes. (It's dotted-quarter, eighth, dotted-quarter, eighth).

    Try this:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    ' Note timings. Change "eighth" to make the song play faster or slower
    eighth    CON    250
    quarter    CON    eighth*2
    d_quarter    CON    eighth*3
    half        CON    eighth*4
    
    ' Pitches
    C6        CON    1047
    D6        CON    1175
    E6        CON    1319
    F6        CON    1396
    G6        CON    1568
    
    speakerPin  PIN  9
    
    FREQOUT speakerpin, d_quarter, C6
    FREQOUT speakerpin, eighth, D6
    FREQOUT speakerpin, d_quarter, E6
    FREQOUT speakerpin, eighth, D6
    FREQOUT speakerpin, quarter, E6
    FREQOUT speakerpin, quarter, D6
    FREQOUT speakerpin, d_quarter, E6
    PAUSE eighth
    
    FREQOUT speakerpin, d_quarter, D6
    FREQOUT speakerpin, eighth, E6
    FREQOUT speakerpin, eighth, F6
    FREQOUT speakerpin, eighth, F6
    FREQOUT speakerpin, eighth, E6
    FREQOUT speakerpin, eighth, D6
    FREQOUT speakerpin, half, F6
    PAUSE half
    
    FREQOUT speakerpin, d_quarter, E6
    FREQOUT speakerpin, eighth, F6
    FREQOUT speakerpin, d_quarter, G6
    FREQOUT speakerpin, eighth, E6
    FREQOUT speakerpin, quarter, G6
    FREQOUT speakerpin, quarter, E6
    FREQOUT speakerpin, d_quarter, G6
    
    



    Edit: It looks like Kevin and I were typing at the same time and thinking the same thing. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • AImanAIman Posts: 531
    edited 2006-07-25 21:27
    Thanks for the info. I sat back and worked out some timing based off human reaction times and pause 100 works pretty close to most of the time. There are still a few issues to work out but I think getting the sheet music and going off that will solve the note duration.
    Now if I can figure out how to get it to read music...
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2006-07-25 21:57
    AIman, are you by chance using Chapter 8 of What's a Microcontroller?·It is about making .bs2 music with various coding structures for efficiency composing and program space.··In the program NotesAndDurations.bs2 in·Activity 4,·durations and rests are dealt with·specifically, using a FREQOUT with a frequency of 0 and the same duration arguments used for other notes in the sequence.

    The book is available for free download as a pdf at the bottom of this page:

    http://www.parallax.com/detail.asp?product_id=28152

    -Stephanie Lindsay
  • AImanAIman Posts: 531
    edited 2006-07-26 02:40
    You betchya!

    I have and am using the Whats a Microcontroller book. Appendix G does go into how to do a ring tone (ie song) however it relies on standard default times. I am trying to find as close to a human sound as I can get and even though the bood goes states "A note could have up to five characters between the commas; here is what each character specifies:··· ,Duration· note· sharp· dot· octave,·· For example: , 2g#.6," (P317 at the bottom).

    While this is very helpful I still have to recall my years in highschool band to remember that a flat is a sharp from the note below and that not playing is as important as playing. That aside, how do I do somthing like a tripelette(sp?).

    So for example lets say I want to play a stacato C that is a 1/32 note follwed by a B flat whole note. if I use straight computer sounds its going to sound inhumanly perfect·and the spaces will be distinct.·One thing that gives music character is the way we make small and mostly unnoticed errors in hold a note slighlty to long or cutting it fractionally short. Even professionals do this but do it much less then the rest of us.

    What I am after isn't just the pauses, but trying to get a human feel and trying to figure out the chromatic scale so that I can do more with the music, give it 'soul' so to speak. That being said, I have contemplated running a random generator set at between .09 seconds and .10 seconds (or perhpas just variants of .09) so that the notes will vary slightly and sound more human, however running a sub like that raises other concerns.

    Side note - The time interval was chosen because we passed a stop watch around work and most pepole get .07 to .11 of a second for timed reactions, so I figured split the difference and call .09 and .10 human reaction time.

    Lastly, I am intending to get several speakers together and run tones simaltanously on them so chords and different sounds can be used to generate the song more fully. It would be fun to be able to have speakers interconect, however just one speaker doing that would require studing Finite Machines and thats a whole different ball of wax which will have to be melted so to speak.

    jumpin.gif· Whew! that was a mouth full burger.gif
  • Robert KubichekRobert Kubichek Posts: 343
    edited 2006-07-26 03:19
    As far as using the .09 average, I think that you are using to great an average.
    I would halve that, for the simple reason, that it is one person playing a tune, and to have such a wide variance will make the melody change to much between notes.
    I would think that the variance in changing the attack/hold/decay of a note is more important than the accurate timing of a note being played...
    To play multi note chords, mix the ouputs into one amp/speaker...
    I remember using a 741 op amp to make some tubular bell sounds.
    I had enough boards made up for 3 full octaves, and I mixed the ouputs into a fet, then to a preamp-amp.
    They sounded like the real thing... smilewinkgrin.gif

    Bob scool.gif

    Post Edited (Robert Kubichek) : 7/26/2006 3:23:44 AM GMT
  • SSteveSSteve Posts: 808
    edited 2006-07-26 03:27
    A triplet is a duplet divided by three. So an eighth note triplet (three eighth notes in the time of a quarter note) is a quarter note duration divided by three (or an eighth note times two-thirds).

    If you're modeling singing or a breath-controlled instrument there won't be space between every note. The notes in a phrase will all run together and the spaces will come either where rests are explicitly written or at the end of a phrase. When singing, as a general rule, you breathe with the punctuation. If there is no rest at the end of a sentence, you'll take a breath. And the breath is in time musically (e.g. a sixteenth note or eighth note).

    Reaction time is different than musical timing. Reaction time measures how fast you can react to something in a situation where you don't know when it's coming. Musicians know when the downbeat is coming and can be exactly on time (or early or late if the style dictates). No decent musician will be a tenth of a second late. The "human" feel doesn't come from random errors--it comes from deliberate expression.

    Here's what I use for pitches:
    ' -----[noparse][[/noparse] Constants ]-------------------------------------------------------
    ' Frequencies given are for octave 8. Calculate lower octaves by
    ' shifting right one bit for each octave lower.
    
    R               CON      0                      ' rest
    C               CON     8372                    ' ideal is 8372.018
    Cs              CON     8870                    ' ideal is 8869.844
    D               CON     9397                    ' ideal is 9397.273
    Ds              CON     9956                    ' ideal is 9956.063
    E               CON     10548                   ' ideal is 10548.082
    F               CON     11175                   ' ideal is 11175.303
    Fs              CON     11840                   ' ideal is 11839.822
    G               CON     12544                   ' ideal is 12543.854
    Gs              CON     13290                   ' ideal is 13289.750
    A               CON     14080                   ' ideal is 14080
    As              CON     14917                   ' ideal is 14917.240
    B               CON     15804                   ' ideal is 15804.266
    
    



    I hope this helps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
Sign In or Register to comment.