Help with multicog use
Oldbitcollector (Jeff)
Posts: 8,091
Ok, I need some help wrapping my one track brain around an eight track Propeller.
I'm continuing to work on Rayman's 8bit wav code, attempting to get multiple wav files to play at the same time
to generate chords. I can't seem to get more than three notes played after each other.
I've even tried to separate the "player" code from the main program. no dice.
My main code looks something like this:
play2 is simply another attempt by creating more than one copy of the player code.
I've tried cognew without success. I want it to start the first play. and quickly jump to the
next while it is playing. What am I misunderstanding?
Thanks
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard & Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
Post Edited (Oldbitcollector) : 12/10/2008 11:37:12 PM GMT
I'm continuing to work on Rayman's 8bit wav code, attempting to get multiple wav files to play at the same time
to generate chords. I can't seem to get more than three notes played after each other.
I've even tried to separate the "player" code from the main program. no dice.
My main code looks something like this:
play.Player(@Wav,17000) 'C
play2.Player(@Wav,15000) 'D
play.Player(@Wav,13400) 'E
play2 is simply another attempt by creating more than one copy of the player code.
I've tried cognew without success. I want it to start the first play. and quickly jump to the
next while it is playing. What am I misunderstanding?
Thanks
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard & Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
Post Edited (Oldbitcollector) : 12/10/2008 11:37:12 PM GMT

Comments
Here's the main program
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 '80 MHz '' Setting for stero audio channels '' Set left as unused pin if not connected right = 10 left = 11 VAR long stack[noparse][[/noparse]100] OBJ play : "player.spin" play2 : "player2.spin" PUB Main|n,i,j 'Set up the counters CTRA:= %00110 << 26 + 0<<9 + right CTRB:= %00110 << 26 + 0<<9 + left play.start play2.start 'Set pins to output mode DIRA[noparse][[/noparse]right]~~ 'Set Right Pin to output DIRA[noparse][[/noparse]left]~~ 'Set Left Pin to output 'Play a WAV File play.Player(@Wav,17000) 'C play2.Player(@Wav,15000) 'D play.Player(@Wav,13400) 'E 'play.Player(@Wav,12600) 'F 'Player(@Wav,11250) 'G 'Player(@Wav,10000) 'A 'Player(@Wav,9000) 'B 'Player(@Wav,8500) 'C DAT WAV byte 'File "pad.wav" ' <--- put your 8-bit PCM mono 8000 sample/second WAV 'File "strings.wav" ' <--- put your 8-bit PCM mono 8000 sample/second WAV 'File "piano.wav" ' <--- put your 8-bit PCM mono 8000 sample/second WAV File "leadsyn1.wav" ' <--- put your 8-bit PCM mono 8000 sample/second WAV.play and .play2 are identical.
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 '80 MHz '' Setting for stero audio channels '' Set left as unused pin if not connected right = 10 left = 11 PUB Start PUB Player(pWav,speed):bOK|n,i,nextCnt,rate,dcnt 'get length n:=long[noparse][[/noparse]pWav+40] 'get rate rate:=long[noparse][[/noparse]pWav+24] case rate 8000: dcnt:=speed other: return false pWav+=44 'Get ready for fast loop n-- i:=0 NextCnt:=cnt+15000 'Play loop repeat i from 0 to 2200 'n --Changed to create consistant notes NextCnt+=dcnt waitcnt(NextCnt) FRQA:=(byte[noparse][[/noparse]pWav+i])<<24 FRQB:=FRQA return trueOBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard & Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
Post Edited (Oldbitcollector) : 12/10/2008 11:48:53 PM GMT
To have them play in parallel you would have to have to do what graphics does; send the instruction, the graphics cog receives it, clears par, which allows the spin cog to continue while the graphics does the drawing. Graphics cannot execute a new command until finished. You would have to use multiple cogs running wav playing code.
Depending on what you want to do, it may be better to try a synthesizer approach rather than stacking wavs.
Post Edited (Jetfire) : 12/10/2008 11:54:38 PM GMT
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard & Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
One simple way is to read a single sample from each track and add the samples together. The one problem with this is that it is possible for the sum to overflow the output bit width.
One way around that is to clip the sum to a maximum value. Another way is to output the average of the samples (division by a constant reduces volume). There is a whole field of research around mixing sound with minimal perceived distortion.
I've not played with sound on a Propeller yet, so I don't know what if any mixing support there already is.
if you don't want to change the assembly-code you have to call the Pub Player from different cogs to get it parallel playing
this means:
you have to start 2-7 cogs by cognew each running a loop that is waiting for a command that sets up the parameters pWav and speed
setting up the paremeters pWav and speed does NOT start a call of PUB player
AFTER all paremeters have been setup for EVERY cog
you set a global variable "play" true
EACH cog is waiting for this global variable "play" to get true
and THEN each cog can start do the call for the PUB Player
you can imagine the paremeter setup like the countdown for a olympic sprint of the athlets
each athlet hears the "get into startblock - ready - GO!" from the "starter" person
"get into startblock - ready" sets up pwav and speed
all athlets still HAVE TO wait until the "GO!"
the "GO!" arrives at each athlet at the same time and then each athlet get's out of the startblock using his OWN body (own cog) running down to the target-line
best regards
Stefan