This guide is outdated as of v3.1. You can use the built in function instead. Note that .wav sound effects take a considerable amount of space in the ROM.
Once you have your .wav file you want to use ready (4 seconds or less), you have to convert it to 8kHz mono, Unsigned 8-bit PCM (unless it already is in that format) with your preferred audio editor. In Audacity, you can do this with Tracks > Mix Stereo Down to Mono, Tracks > Resample > 8000, and File > Export As WAV and choose "Unsigned 8-bit PCM" where it says "Encoding."
Download the below cvtsample.py
file and put it into the same folder as your .wav file. You will need Python to run this. To run it, first cd
to the directory where cvtsample.py
is in, then use the command py cvtsample.py wav_name.wav
where wav_name
is the name of your .wav file. A wav_name.c
file will be created in this directory.
To insert wav_name.c
file into your project, open your project in GB Studio and press Game > Advanced > Eject Engine. Once the assets/engine
folder has been created, insert wav_name.c
into assets/engine/src/data
.
Now, select the scene where you want to play the .wav sound. Add the event named "GBVM Script." Inside the text box, type the command
VM_WAVE_PLAY FRAMES, ___bank_wav_name, _wav_name, ___size_wav_name
where FRAMES
is the amount of frames you want to play the sound for before it can be overridden. If you want to string together multiple sound effects, add a Wait 3.9 seconds event between them.