Retro Gadgets

Retro Gadgets

Not enough ratings
How to play a music/sound file
By 반딧불 세레
A quick guide on how to import and play/stop a music or sound file
   
Award
Favorite
Favorited
Unfavorite
How To
Make your way to the title screen and press the FOLDER button. This will open up the folder for you to import your sound file into. (this is where you can also put custom images as well!)
In the pictures I've highlighted the code we'll be using. Please disregard the other code as it's part of a project I'm working on. (feel free to use it if you want to though!)


Next we put the file we want to use into this folder. I know for sure that .mp3 and .wav files work for audio. I can't be certain on other file types.


Now we navigate into our project and to the import screen. Our sound file should show up. Click on it the press CONFIRM. I'm using a file called MMR.mp3


NOTE: Make sure you have an Audio Chip and a ROM chip installed on your gadget!
Next we go into our code and at the very top (or ABOVE the update function at least) we do these 2 things:


Code:
local sound = gdt.AudioChip0
local aud: AudioSample = gdt.ROM.User.AudioSamples ["MMR.mp3"]

So firstly we are naming the Audio Chip "sound".
Next, we're naming our music file "aud" and making sure the code knows it exists.

If you haven't already, make sure you place 2 buttons onto your gadget. We'll use one of these to play the sound and the other one to stop the sound.

Now we need to write some simple code in the UPDATE function.


Code:
if gdt.LedButton1.ButtonDown
then
sound.Play(sound,aud,1)
end
if gdt.LedButton0.ButtonDown
then
sound.Stop(sound,1)
end

So we're just going to use a simple "if" statement to make this work. Substitute LedButton for whatever your buttons are.

We use ButtonDown so it only plays the sound ONCE. If you don't use ButtonDown then the sound might keep playing over and over and give you hearing aids.

sound.Play is us calling the Audio Chip (which we named "sound") and making it play.

(sound,aud,1) is us calling the Audio Chip, calling the audio file (which we named "aud"), and then choosing what channel to play the sound on. If you're making lots of sound buttons then you'll want to put each sound on a different channel. So the next one would be 2, and then 3 etc...

The next part of the code is just hooking up a second button to STOP the sound. This is handy if you're making a music player and want to stop the music playing. You could also swap this out with .Pause if you only want it to pause instead of stopping entirely.

Now you can power on your gadget and play a sound or a song!

Leave me a comment if something was unclear.
Hope this helps :)
7 Comments
pasulj 22 Jul, 2023 @ 11:55pm 
alr i fixed to problem but when i press the play button it doesnt activate
pasulj 22 Jul, 2023 @ 11:46pm 
it makes compile error
pasulj 22 Jul, 2023 @ 11:30pm 
hey ummm but when i turn it on it gives me an error
its something about the cpu
반딧불 세레  [author] 22 Jul, 2023 @ 2:51pm 
@Shayrin If it's no longer on the title screen then I have no idea. Sorry bro, I haven't played this in like a year so it's possibly gone through many updates
pasulj 22 Jul, 2023 @ 2:30pm 
bro where is the folder thing you talk about
Bodhi DoubleWodkovich 5 Dec, 2022 @ 1:53pm 
Just found out about this game today and really excited. Unfortunately, developer is apparently a man of few words, so thx bro for the guide, really helped
반딧불 세레  [author] 5 Dec, 2022 @ 12:13am 
Ok when I say naming I mean caching variables but you get the idea XD