Shop OBEX P1 Docs P2 Docs Learn Events
Help w/ song for boe-bot — Parallax Forums

Help w/ song for boe-bot

edited 2008-05-02 05:49 in BASIC Stamp
I'm trying to program my boe-bot to "sing" greensleeves and i currently have four speakers on the bot. I have to be able to play achord of 3 notes on the bot. (peizospeakers)
I need help with creating and/or finding a program for this song or any song of that matter and i need to be able to understand it.
If anyone can help me I would really appreciate it.
Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-02 05:09
    You're going to have a difficult time doing multipart tones using a single Stamp. The problem is that a Stamp is a single threaded processor. It can only do one thing at a time, so, when it's outputting a tone with something like FREQOUT, it can't do anything else. In addition, the standard Stamp for the BoeBot is a BS2 which only executes roughly 4000 instructions per second. You could probably do multiple low tones (like 100Hz to maybe 400Hz by reading out samples from EEPROM as data using the READ statement and copying them to 3 outputs at fixed intervals.
  • edited 2008-05-02 05:11
    how would you do that though?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-02 05:37
    As a simple example, if you have 8 DATA bytes and you copy the lower 3 bits to 3 outputs, once every two milliseconds (and repeat the table every 16 milliseconds, you can get several different tones. "DATA 1,1,1,1,0,0,0,0" will produce a 62Hz tone. "DATA 1,0,1,0,1,0,1,0,1,0" will produce a 250Hz tone. You can combine them as "DATA 3,2,3,2,1,0,1,0" to produce a 62 Hz tone and a 250Hz tone on each of two output pins. If you use a faster Stamp, you could produce higher frequencies and use a longer table to get more frequencies.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-05-02 05:49
    Two-part harmony is easy enough with the FREQOUT command, since it allows two tones to be generated at once. However, the duration of both tones in each chord has to be the same. In other words, one note in a chord can't be tied while the other one changes. Three-part harmony will definitely be out of reach for any of the BASIC Stamps without additional hardware.*

    You will get the best sound continuity by using inline code — i.e. one FREQOUT after another — rather than reading data in a loop or computing notes on the fly. If your tune sequence is short, this shouldn't be a big issue. However, long sequences may require storing notes in EEPROM, reading them sequentially, and performing the FREQOUTs in a loop. The effect will be more staccato, though, since there will be gaps between notes. You will also have to shorten the notes proportionately to maintain the proper relative tempo.

    -Phil

    * Addendum: Hmm. Mike's approach could work, now that I see his explanation...
Sign In or Register to comment.