Cannot get wav_play to work in it's own COG?
GeeksGoneBad
Posts: 100
hey guys I am trying to control a few servos, steppers, and play a wav file from the SD card - everything works except for the playing of the wav file - it will work if I don't try to run it in it's own COG but then I have to wait for all the audio to play until the motors start working and that's not good
any ideas? Here's my code so far.... Initially I had all of the wav playing stuff in the "PlayAudio" function but that didn't work either
any ideas? Here's my code so far.... Initially I had all of the wav playing stuff in the "PlayAudio" function but that didn't work either
#include "simpletools.h" #include "servo.h" #include "wavplayer.h" void nodHead(); void moveEyes(); void turnHead(); void openCloseJaw(); void PlayAudio(); void lookLeft(); void lookRight(); void lookStraight(); unsigned int stack1[65]; unsigned int stack2[65]; unsigned int stack3[85]; unsigned int stack4[65]; const char zombie[] = {"zombie.wav"}; int main() { int DO = 22, CLK = 23, DI = 24, CS = 25; sd_mount(DO, CLK, DI, CS); cogstart(&moveEyes, NULL, stack1, sizeof(stack1)); cogstart(&PlayAudio, NULL, stack3, sizeof(stack3)); cogstart(&openCloseJaw, NULL, stack2, sizeof(stack2)); cogstart(&nodHead, NULL, stack4, sizeof(stack4)); //pause(5000); //cogstart(&openCloseJaw, NULL, stack1, sizeof(stack1)); //pause(6000); //servo_stop(); pause(6000); }; void moveEyes() { lookStraight(); servo_setramp(1, 5); lookLeft(); pause(4000); lookRight(); pause(4000); lookStraight(); } void nodHead() { for(int a = 0; a < 5000; a++) { high(0); pause(1); low(0); pause(1); } } void turnHead() { for(int a = 0; a < 2300; a++) { high(3); pause(1); low(3); pause(1); } } void lookLeft() { servo_angle(1, 0); } void lookRight() { servo_angle(1, 900); } void lookStraight() { servo_angle(1, 450); } void openCloseJaw() { servo_angle(2, 900); servo_setramp(2, 10); servo_angle(2, 550); pause(1000); servo_angle(2, 900); } void PlayAudio() { wav_volume(10); wav_play(zombie); pause(3500); wav_stop(); }
Comments
unfortunately I don't think it's completely related to the sound at all - I moved all of the SD card stuff back into the function and initially it didn't work and then I took out a few things to see what the problem might be and the sound will run in a COG but it doesn't seem to want to if I have 4 things running already - further investigation shows that I can get about three things to run and the forth does not - but what's weird is sometimes the fifth one will
I'm going to try and combine some of the effects and hopefully I can end up with three COGs that all work
I will post back success or failure!
Jamie
now I can get nearly everything to work by combining a few things into functions - but in my "talking" function the wav file plays the first time I call it - but not the second - the servo moves so I know it's going through the function - but the wav does not play
close
The cogstart function does not attempt to stop a cog. It returns a cogid though, and you can use that to stop the previously started cog before starting a new one.
Great
Any chance of posting your latest code?
Regards,
Brian (BTL24)
I see how you stop the talking function by using talkingCog variable that lets you know which cog is playing wav file.
I will try your structure in my code and see if I can get my wav file to play indefinitely....
Thanks again.
Brian (BTL24)