How do I get my music to play?..... and how to turn pong game into OOP

justin

il y a 5 ans

I have a sound .wav file within the file location of my game.

I want the music to start as the game sets up, so I did

void setup (){

gb.begin();

gb.sound.play("songname.wav");

}


when I do this the music doesn't play.

could I please get help.

Also how can i turn the pong game into OOP pong game. Please and thank you


jicehel

NEW il y a 5 ans

First thing, you have to be sure that your mp3 file is at the good format. You can use ffmpeg to convet it for example with a line code: ffmpeg -i  in.mp3 -acodec pcm_u8 -ar 44.1k -ac 1 out.wav (with in.mp3 as name of the name of the file to convert and out.wav as the name of the converted file you'll play with your META)

justin

NEW il y a 5 ans

I did that and the sound still wont play

jicehel

NEW il y a 5 ans

ok, else, in setup you can try to keep only:

void setup() {     

gb.begin(); 

}

and to put the play sound in the loop

void loop() {

gb.sound.play("songname.wav");

}


and of couse check in the menu that the sound is turned on, but i think you have alredy checked it

deeph

NEW il y a 5 ans

You probably need to add gb.update() somewhere, as it handles the sound. Try this :

void setup (){
  gb.begin();
  gb.sound.play("songname.wav");
}

void loop(){
  while(!gb.update());
}

Also, if you struggle with white noise after converting your .wav, you can try to use SoX instead of FFmpeg, and disable dithering like this :

sox -V -D in.mp3 -r 44.1k -e unsigned-integer -b 8 -c 1 out.wav rate 44.1k

You can also lower the sampling frequency to 22.05kHz or even 11.025kHz, depending of the sound quality you want to achieve.

justin

NEW il y a 5 ans

I put in loop. I have converted it also. it is within file location. it does compile. volume on the gamebuino set to max. however the sound does not want to play. 


other games sound works but not my one.

deeph

NEW il y a 5 ans

I don't know if you're supposed to hear anything like that, as it would play your melody from the start over and over and at a very fast rate...

Try this :

void setup(){
  gb.begin();
  int music = gb.sound.play("melody.wav", true);
}

void loop(){
  while(!gb.update());
}

Also, you should keep track of the music id, to be able to stop it using gb.sound.stop(music);

Sorunome

NEW il y a 5 ans

Are you 100% sure your wav file is 8-bit, single channel, unsigned?

justin

NEW il y a 5 ans

yeah I changed it via audacity

d97

NEW il y a 5 ans

I don't know if this will help or not, but in order to get my audio files to play, I have had to embed the path into the gb.sound.play function (i.e. gb.sound.play(/folder_with_the_game_in_it/song_title.wav,true);

D.


Sorunome

NEW il y a 5 ans

Huh it should cd automatically into /folder_with_the_game_in, so that you should be able to use relative paths. This sounds odd