PDA

View Full Version : sound command & music



trying
- 17th May 2006, 13:57
way back when I found a web site that had a lot of music code for using PBP and sound command . but I can no longer find it. Anybody know of a good site. trying to have fun with the grandkids.
thanks

Melanie
- 17th May 2006, 17:02
Here's a sound demo (yankeedoodle) for 12F675...

http://www.picbasic.co.uk/forum/showthread.php?t=64

trying
- 18th May 2006, 14:10
Thanks Melanie the kids loveed it just wondering it a LCDOUT command "yankie doodle xxxxxxxx"could be put at the beginning and another one after Data $01,$52,$4E,$20"stuck a feather in his capxxxxxx"
to show the words

Acetronics2
- 18th May 2006, 14:17
May be here also ...

http://www.rc-float-flying.rchomepage.com/RCWeb/PIC/Sound.htm

héhé,

Alain

Melanie
- 18th May 2006, 16:44
It's a tiny little music routrine that reads four Bytes from EEPROM and acts on it. If you changed it say to FIVE bytes, then use Byte5 (if say non-zero) to indicate what you want to display. Kinda tough on a 12F chip, because lack of pins means you're having to drive a Serial LCD to send your message, and the Serial LCD will take time (even at 9600 baud), so it will impact on the music giving you an abnormal pause between notes. Better if you choose a PIC with more pins.

trying
- 18th May 2006, 21:11
Sorry Melanie
I was going to use a 16f630. and not use the words in real time
lcdout $FE,1 "yankiexxxxxxxx"
lcdout $FE, $C0 "xxxxxxpony"
displayed then start the music
but I not sure how to insert the second
lcdout $FE,1 "stuckxxxxxxxx"
lcdout $FE, $C0 "xxxxxxmacorone?"
after the $20 Gf7
this is for 5 years olds it can miss a beat or two. LAL
thanks for anyhelp

Melanie
- 19th May 2006, 01:03
That's really simple, tear the code appart and you discover that variable CounterA is a pointer into EEPROM starting at Address location 1 (for the first line)...

CounterA=1

Then after each note is played, we increment it by four...

CounterA=CounterA+4

So CounterA is pointing to the note currently being played... simply do something like this...



MusicalLoop:
If CounterA=1 then LCDOut $FE,1,"Yankee Doodle"
If CounterA=17 then LCDOut $FE,$C0,"went to town"
If CounterA=33 then LCDOut $FE,1,"A-riding on",$FE,$C0," a pony"
If CounterA=57 then LCDOut $FE,1,"Stuck a feather"
If CounterA=73 then LCDOut $FE,$C0," in his hat"
If CounterA=85 then LCDOut $FE,1,"And called it",$FE,$C0," macaroni.
Read CounterA,NotePeriod.Highbyte
If NotePeriod.Highbyte=$FF then
LCDOut $FE,1
Pause 2000
Goto RestartLoop
endif
Read CounterA+1,NotePeriod.Lowbyte
Read CounterA+2,CounterB
NoteRepeat=CounterB*10
Read CounterA+3,CounterB
MessagePrompt=MessagePrompt+1
NotePause=CounterB*10
CounterA=CounterA+4
MessageNote
Gosub PlayNote
Goto MusicalLoop


Only on this forum... rocket science for 5-year-olds (by five year olds!!).

If you want to go more advanced... you can have the words appearing prior to every note...



If CounterA=1 then LCDOut $FE,1,"Yan"
If CounterA=5 then LCDOut "kee "
If CounterA=9 then LCDOut "Doo"
If CounterA=13 then LCDOut "dle"
If CounterA=17 then LCDOut $FE,$C0,"went "
If CounterA=21 then LCDOut "to "
If CounterA=25 then LCDOut "town"
etc etc

trying
- 19th May 2006, 13:51
Melanie your wonderful (bet you get told that a lot) it worked like charm!
Now the grand kids will have there very own Karoke machine
made by Papa

mister_e
- 19th May 2006, 13:57
And now, if you want to do a 'little' improvement, you may use a PIC with a HPWM module and, if possible, use this module to generate the tone. This may avoid some unwanted 'distortion' in the tones. HPWM will continue to play the tone, while sending your info to the LCD. BUT as i'd didn't heard the actual result, i can't say if it's going to be a real improvement.

trying
- 24th May 2006, 14:02
As I study the "Yankee" code more I understand CounterA is READing the DATA but I am still not sure how take the note from a frequency to DATA
grand kids say more music papa
can some one explain this were a newbie can understand it
thanks.

' Musical Note/Frequency/Period/Cycles for 250mS
' Cs means C Sharp
' Df means D Flat
'
' There are four Data statements per Note...
' Byte 1 is the MSB of half the Period Frequency
' Byte 2 is the LSB of above
' Byte 3 is the number of cycles the note will play for
' (divided by ten). All the notes have been calculated
' to Beep for approx 250mS except the last two notes
' of each line which are twice as long.
' Byte 4 is the time delay in mS (divided by ten)
' that follows any given played note.

Data $01,$3F,$27,$10 ' G7 - 1567.98Hz 638uS 390c
Data $01,$3F,$27,$10 ' G7
Data $01,$1C,$2C,$10 ' A7 - 1760.00Hz 568uS 440c

peterdeco1
- 26th May 2006, 11:15
Hi Trying. Hi Steve. Using the PWM module is a BIG improvement as each note will be perfectly on key. I converted some tunes into HPWM commands to play music on one of the PWM ports on a 16F818. The 818 can hold about 2 or 3 songs, the 16F819 can hold about 5 and a 16F88 that I used holds 8 different tunes. Below are 2 of them. If you want more volume, output the CCP1 pin to the gate of a FET. Source to ground and speaker from drain to B+. It will be painfully loud. I used a logic-level IRLZ44N at 3 Volts for this. Add the command CCP1CON = 0 and make the port LOW at the end of the song otherwise the FET may be left ON and kill the battery. CAUTION - writing songs and playing them on a PIC can be addicting! Be prepared to spend countless hours writing code.

BABABLACKSHEEP:
HPwm 1,127,262:Pause 320
HPwm 1,127,262:Pause 320
HPwm 1,127,392:Pause 320
HPwm 1,127,392:Pause 320
HPwm 1,127,440:Pause 160
HPwm 1,127,494:Pause 160
HPwm 1,127,523:Pause 160
HPwm 1,127,440:Pause 160
HPwm 1,127,392:Pause 320
HPwm 1,127,000:Pause 320
HPwm 1,127,349:Pause 320
HPwm 1,127,349:Pause 320
HPwm 1,127,330:Pause 320
HPwm 1,127,330:Pause 320
HPwm 1,127,294:Pause 320
HPwm 1,127,294:Pause 320
HPwm 1,127,262:Pause 320
Pause 1000
GoTo BABABLACKSHEEP

STARSPANGLEDBANNER:
HPwm 1,127,698:Pause 320
HPwm 1,127,587:Pause 320
HPwm 1,127,466:Pause 640
HPwm 1,127,587:Pause 640
HPwm 1,127,698:Pause 640
HPwm 1,127,932:Pause 640
HPwm 1,127,000:Pause 640
HPwm 1,127,1175:Pause 320
HPwm 1,127,1047:Pause 320
HPwm 1,127,932:Pause 640
HPwm 1,127,587:Pause 640
HPwm 1,127,659:Pause 640
HPwm 1,127,698:Pause 640
HPwm 1,127,000:Pause 320
HPwm 1,127,698:Pause 320
HPwm 1,127,698:Pause 320
HPwm 1,127,1175:Pause 640
HPwm 1,127,1047:Pause 320
HPwm 1,127,932:Pause 640
HPwm 1,127,880:Pause 640
HPwm 1,127,000:Pause 640
HPwm 1,127,784:Pause 320
HPwm 1,127,880:Pause 320
HPwm 1,127,932:Pause 640
HPwm 1,127,932:Pause 640
HPwm 1,127,698:Pause 640
HPwm 1,127,587:Pause 640
HPwm 1,127,466:Pause 640
Pause 1000
GOTO STARSPANGLEDBANNER

mister_e
- 26th May 2006, 11:48
Funny things amuse grand kids here!
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=881&stc=1&d=1148640458">

Now if there's any existing software to convert music sheet or MIDI sequence to note/duration table it could be just much easy... i'm sure it exist.

Acetronics2
- 26th May 2006, 13:10
Hi, Steve,

In my old papers (Electronique pratique 277 )... i've found something interesting !!!

See a 16F84 reading a 24C256 gives 4 sec of sound.

...output on portB with a R -2R ladder ... amp is a LM386.

Buuuuuut, where it becomes interesting ... is you can load the EEPROM using the Windows sound recorder ... aha !!!

now, the Wave file has 58 bytes at top to config ...to wipe off !!!

in the Wav-bin.exe, that's done automatically.

then just have to load the EEPROM...

Listen, that's all !!!

Alain

Problem ... the 200Kb limit is widely exploded !!! ... have an address to post that ???

mister_e
- 26th May 2006, 13:33
Dropped in your PM !

Interesting but there's some additionnal hardware. Even some ISDXXX chipcoder would do the job as well. Let's see what we can with your suggestion. Will report something here... one day... when i'll found time to play 'round.

trying
- 26th May 2006, 14:14
Funny things amuse grand kids here!
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=881&stc=1&d=1148640458">

Now if there's any existing software to convert music sheet or MIDI sequence to note/duration table it could be just much easy... i'm sure it exist.

thats great guys but thats wayyyyyy over my head (right now)
ok mister_e I just finished a spead sheet with excel that has 4 octaves of notes gives you the note freq,period time,note repete time and other things
for 1/16,1/4,1/2 and whole notes. but I'm stuck on how to use this with
MSB, LSB, in data the way Melanie used it in "Yankee doodle" for give me for not knowing how to ask the right ?'s but I sure need help on this in simple terms.
thanks trying