Audio What's your approach to audio?

ceaselessly

Member
So, you've got the basics of playing, stopping, fading, and crossfading audio. These are fairly simple concepts, not difficult to master.

Your next task is to decide how you are going to implement these concepts into your game. How do you manage your audio? Do you have a master audio management object, which checks for relevant inputs and plays sounds, or do you couple it with the event itself?

For example: footsteps. Do you play the audio file in the same script as the player's movement code, or do you check for the player's movement from a separate object and then play the audio?

Interested in the different ways you all approach this. :)
 

Kezarus

Endless Game Maker
I have an object that run playlists on certain rooms and make transitions and continuous playing.

Regarding to sound, specially if it's animation, I slap it on the object. I have no shame of it. =]
 

Yal

🐧 *penguin noises*
GMC Elder
I have convenience scripts to play background music (stopping the previously playing BGM, unless it's the same track as I want to play now, in which case I keep it playing) and sound effects (including being able to randomize the pitch or set it explicitly - sounds that are repeated a lot in quick succession like attack whooshes sound a lot more natural if you alter the pitch a bit every time), and then just run those scripts whenever an action that should have a sound is taken - basically playing sounds from various points in the entire code base, mostly in step and collision events of every object.
 

Khao

Member
I'm using custom scripts too, to have volume control and 3D sound working easily, as well as automating some layering systems for certain specific combinations of actions.

In my game, different bullets produce different sounds. Different "strength" values for each bullet produce different sounds. Different characters hitting bullets produces different sounds. So whenever a character hits a bullet, I run a single script that just automatically grabs the bullet's strength value, the specific character, and the specific bullet, and plays two sounds simultaneously (for the bullet getting hit and the object hitting the bullet), each with a slightly random pitch depending on the specific values. There's three variations of each sound depending on the bullet's strength, and they're picked automatically depending on all those variables. And the volume for each of these sounds is calculated using the global variables for volume (sfx_volume*master_volume).

Something else I did specifically for character voices, is a scripts that stores the specific instance of the sound in a variable, to know which specific voiceline the character is currently using. If for whatever reason the same character uses the same script once again, the voiceline in that variable gets interrupted so that the character doesn't just throw two voicelines at the same time, while letting other player characters use the same voicelines at the same time (in the case multiple players choose the same characters). Again, this is done automatically by just calling the "play_voiceline" script.

That's basically my idea for everything. Everything I want to do in a semi-complicated manner, I reduce to a script so I can just call it once if I want to play a sound. The script handles everything and I don't have to copy-paste code anywhere. And yes, I have minor sound effects added to character code when it's convenient, but since they sill use one of my sound scripts, they still fall into the same sound system. So everytime I change the system in the script, even those sounds hidden away in weird parts are affected.

Also, very important. If something goes wrong (a specific sound is missing, or something returns the wrong value) the default sound effect in the script is literally just a recording of the sound designer's cat meowing. It's almost impossible to miss even when a lot of other sounds are playing, because nothing else in the game has a similar sound. This means that errors are easy to find, because whenever we hear a cat in-game, we know that we're missing a sound effect or that something's glitching out and not returning the right sound. If you're using a system that dynamically chooses sound files depending on certain variables I definitely recommend this. Even just for placeholders, using ridiculous/annoying sounds is a good idea because then you'll always remember you have to add proper ones later.
 

Yal

🐧 *penguin noises*
GMC Elder
Also, very important. If something goes wrong (a specific sound is missing, or something returns the wrong value) the default sound effect in the script is literally just a recording of the sound designer's cat meowing. It's almost impossible to miss even when a lot of other sounds are playing, because nothing else in the game has a similar sound. This means that errors are easy to find, because whenever we hear a cat in-game, we know that we're missing a sound effect or that something's glitching out and not returning the right sound. If you're using a system that dynamically chooses sound files depending on certain variables I definitely recommend this. Even just for placeholders, using ridiculous/annoying sounds is a good idea because then you'll always remember you have to add proper ones later.
I second this, but with the addition to print a log message using show_debug_message so you also can instantly tell what went wrong (when test-playing the game in GM, at least). The game crashing also instantly tells you something went wrong, but there's a lot of potential places to search through before you can find the actual cause. (I recently had a problem like that where the game silently closed at the start of the room - I thought some new code that looped to create a vertex buffer procedurally had an infinite loop, spent a lot of time debugging that, and much later realized that I was calling vertex_buffer_submit with an asset reference instead of a texture reference. Knowing where to start looking saves you a lot of tedium when debugging)
 
R

relic1882

Guest
I call sound effects as needed for my objects within the objects. Seems to work fine for me.

As far as music, I'm doing a Castlevania inspired side scroller, so I have a main room initialization object that gets placed in every room of the game. I use Variables on the object that I can manipulate in the room editor to choose whatever music I want playing for that area. If the music in the variable is different than what is currently playing, the create event takes care of the change in music for me. This works well and it's easy to use anywhere in the game.
 
Top