Sound FX in shmups... how its done???

A place for people with an interest in developing new shmups.
Post Reply
User avatar
nasty_wolverine
Posts: 1371
Joined: Sun Oct 09, 2011 11:44 pm

Sound FX in shmups... how its done???

Post by nasty_wolverine »

Not about creating sound fx (for that i have sfxr and audacity)...
How you guys play sound fx?
when two explosion happen on screen, you play the first explosion... now assuming the first explosion is still playing, for the second explosion do you stop the first explosion sound and play the second explosion? or do you just play the second explosion on top of the first one (i am getting muddled sound with sdl_mixer)? or just skip the second explosion?
also how do you handle player bullet firing sound???

any help is appreciated :)
thanks
Elysian Door - Naraka (my WIP PC STG) in development hell for the moment
User avatar
n0rtygames
Posts: 1001
Joined: Thu Mar 15, 2012 11:46 pm
Contact:

Re: Sound FX in shmups... how its done???

Post by n0rtygames »

Explosions:
I create an array of sound effect instances and then with a bit of code I'll randomly pick one from that group and play it. If it's playing I'll proceed to the next available one. Basically play on top. If all the explosion sounds are playing, then the request to play an explosion simply doesn't get heard.

Only problem I will say is that playing on top - things start to get a little bit loud at times, but hey.. if you think that's a bad thing...

Image
Take it up with her!

Gunfire:
A short loop of the players gun plays persistently in the background. When the player presses fire, I bring the volume up to maximum with a timer set long enough to give the feeling of firing a hail of bullets. As long as the player is holding fire, this timer is kept at maximum. After the timer expires, the sound gets faded out to silence again.

Recommend that you use a nice simple sound for the gunfire - See DDP's gunfire sound for instance :)

Hope that helps!
facebook: Facebook
User avatar
nasty_wolverine
Posts: 1371
Joined: Sun Oct 09, 2011 11:44 pm

Re: Sound FX in shmups... how its done???

Post by nasty_wolverine »

n0rtygames wrote: pic of milla jovovich
she is my fav actress (in terms of looks) :mrgreen:

any way... thats what i have been doing with explosions, and gunfire too(for every round of shots fired, i play a fx)
for explosions each type of enemy will have a different explosion fx attached (right now i only have one, which sits in the middle of the screen and spams aimed shots)
and for now, no fx is skipped, so as u said it does get loud...
but sdl mixer is being a bitch. volume range is 0-128 but its not linear but more or less geometric so its hard to figure out what volume to exactly play at.
thanks for the help.
Elysian Door - Naraka (my WIP PC STG) in development hell for the moment
User avatar
n0rtygames
Posts: 1001
Joined: Thu Mar 15, 2012 11:46 pm
Contact:

Re: Sound FX in shmups... how its done???

Post by n0rtygames »

nasty_wolverine wrote: and for now, no fx is skipped, so as u said it does get loud...
A lot of it has to do with the sounds you're using of course, things with less crunch that stack on top of each other nicely tend to do it.

thanks for the help.
It's the least I could do after the thrashing you received on Akku Gallet.....

....

..:(
facebook: Facebook
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: Sound FX in shmups... how its done???

Post by BPzeBanshee »

I let mine play over eachother in Game Maker and as a result when too many sounds are playing some stuff gets cut off. I've been considering making enemies stop and then play bullet sounds but I quite liked the original rollover effect along with the filtering I used to do although others didn't agree with me so things are a bit different now.
User avatar
nasty_wolverine
Posts: 1371
Joined: Sun Oct 09, 2011 11:44 pm

Re: Sound FX in shmups... how its done???

Post by nasty_wolverine »

BPzeBanshee wrote:I let mine play over eachother in Game Maker and as a result when too many sounds are playing some stuff gets cut off. I've been considering making enemies stop and then play bullet sounds but I quite liked the original rollover effect along with the filtering I used to do although others didn't agree with me so things are a bit different now.
wow... i do like how the sound fx is handled in that, reminds of something i cant remember... :(
how are you doing that afterimage thing with the ship? I dont know game maker at all or i would have looked at the source...

any advise on balance, i.e. volume levelling for fx and music... ?
Elysian Door - Naraka (my WIP PC STG) in development hell for the moment
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: Sound FX in shmups... how its done???

Post by BPzeBanshee »

The afterimages are currently separate sprites with their own animation. I was considering trying to use the existing sprite of the ship blended blue but so far it hasn't looked that nice so I've stuck with it.

For balance, I think if you can listen to it at "max" volume (ie. if your game has an audio setting, have that at max) and not have your ears blown out on the same Windows volume setting as most other games you should be fine. I usually like to have the music and voices be audible over the bullet sounds, although in practice so far that hasn't really been the case. Still working on that.
User avatar
nasty_wolverine
Posts: 1371
Joined: Sun Oct 09, 2011 11:44 pm

Re: Sound FX in shmups... how its done???

Post by nasty_wolverine »

BPzeBanshee wrote:The afterimages are currently separate sprites with their own animation. I was considering trying to use the existing sprite of the ship blended blue but so far it hasn't looked that nice so I've stuck with it.
So i am guessing you are keeping track of previous positions of the ship and create a snake like effect... atleast thats how i would do it..
BPzeBanshee wrote:For balance, I think if you can listen to it at "max" volume (ie. if your game has an audio setting, have that at max) and not have your ears blown out on the same Windows volume setting as most other games you should be fine. I usually like to have the music and voices be audible over the bullet sounds, although in practice so far that hasn't really been the case. Still working on that.
Thats what i am doing, essentially balancing by ear.... my dad was a big audiophile, he trained me how to hear sounds and judge different equipment quality, so thanks dad...

short video of the engine demo... http://youtu.be/DG6gveX8_TQ
Elysian Door - Naraka (my WIP PC STG) in development hell for the moment
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: Sound FX in shmups... how its done???

Post by BPzeBanshee »

nasty_wolverine wrote:
BPzeBanshee wrote:The afterimages are currently separate sprites with their own animation. I was considering trying to use the existing sprite of the ship blended blue but so far it hasn't looked that nice so I've stuck with it.
So i am guessing you are keeping track of previous positions of the ship and create a snake like effect... atleast thats how i would do it..
Well technically speaking I keep it very simple. The afterimage sprite is an animation, and itself is many objects layered together: when the animation is finished, it dies. When SHIFT (or starting from MK-VII whatever key you assign to 'FOCUS') is pressed it just creates them.

GM makes things like that quite easy.
User avatar
nasty_wolverine
Posts: 1371
Joined: Sun Oct 09, 2011 11:44 pm

Re: Sound FX in shmups... how its done???

Post by nasty_wolverine »

I have a problem...

http://youtu.be/0MbNxqSQFcQ (right around the end when the weird following enemies, named chaser, show up)

When the same explosion is getting layered (playing on top of each other) its getting too loud...
I was playing DOJ, noticed even when I blow up bunch of enemies together it doesnt get louder..
Does anyone have any idea how does DOJ handle it???
Elysian Door - Naraka (my WIP PC STG) in development hell for the moment
User avatar
n0rtygames
Posts: 1001
Joined: Thu Mar 15, 2012 11:46 pm
Contact:

Re: Sound FX in shmups... how its done???

Post by n0rtygames »

nasty_wolverine wrote:I have a problem...

http://youtu.be/0MbNxqSQFcQ (right around the end when the weird following enemies, named chaser, show up)

When the same explosion is getting layered (playing on top of each other) its getting too loud...
I was playing DOJ, noticed even when I blow up bunch of enemies together it doesnt get louder..
Does anyone have any idea how does DOJ handle it???
You'd probably be best asking someone like Trap15 if you want to know *exactly* how DOJ does it - but I don't seem to recall that DOJ has overlapping sounds. It always felt like the sample was being restarted with each new explosion. For larger boss explosions, I think you only had one sample playing at a time..

I don't think there was much overlap, anyway.. it never felt that way.

btw - that's looking really nice :)
facebook: Facebook
User avatar
trap15
Posts: 7835
Joined: Mon Aug 31, 2009 4:13 am
Location: 東京都杉並区
Contact:

Re: Sound FX in shmups... how its done???

Post by trap15 »

Almost all games I know on arcades have allocated channels for each sound effect. So, all explosion sound effects are on PCM channel 0, for example. Thus, when a new effect starts playing, it stops the first and starts the second simultaneously. The way I do this in my engine is I have a certain amount of audio channels, and then I have a few functions to allocate those channels.

I have the "allocate this specific channel", which will only allow the channel you specify, and allocate it to a stream until it's over (I used this pretty much only for the music, on channel 0). Then I also have a "allocate any channel", which allocates from the list of free channels, except if one of the channels is playing the specified stream, in which case it will return that one instead.

So, an example sound effect function would be:

Code: Select all

void SFX_Explode1(void)
{
  int chan = Audio_Allocate(AUDID_EXPLODE1);
  Audio_PlayStream(chan, AUDID_EXPLODE1);
}
and an example music function would be:

Code: Select all

void MUSIC_Stage1(void)
{
  int chan = Audio_AllocateFixed(0);
  Audio_PlayStream(chan, AUDID_STAGE1);
}
Or something along those lines :)
@trap0xf | daifukkat.su/blog | scores | FIRE LANCER
<S.Yagawa> I like the challenge of "doing the impossible" with older hardware, and pushing it as far as it can go.
User avatar
n0rtygames
Posts: 1001
Joined: Thu Mar 15, 2012 11:46 pm
Contact:

Re: Sound FX in shmups... how its done???

Post by n0rtygames »

Just because I want to be an annoying geek..

Why don't you extend that further and have an enum for your sound types - then based on the enum you pass in, have your sound playing method automatically allocate the channel and if necessary, play from a random bank of explosions? eh eh?

I suspect if I were working with that I'd get myself confused at some point over what lives in each channel and certainly get annoyed at jumping back and forth to remember them :-)
facebook: Facebook
User avatar
trap15
Posts: 7835
Joined: Mon Aug 31, 2009 4:13 am
Location: 東京都杉並区
Contact:

Re: Sound FX in shmups... how its done???

Post by trap15 »

You don't have to remember any? Audio_Allocate chooses the first free (or used by the same sound effect ID; if you want multiple sfx to be on the same channel, you can use a fake ID instead) channel and uses that, and Audio_AllocateFixed uses a specific channel, but as I said, that should pretty much only be used for music. Those bits were just examples anyways; with the same functions you could do random explosion effects too:

Code: Select all

void SFX_ExplodeRandom(void)
{
  int chan = Audio_Allocate(AUDID_EXPLODE);
  int sfx = random() & 3;
  switch(sfx) {
    case 0: Audio_PlayStream(chan, AUDID_EXPLODE1); break;
    case 1: Audio_PlayStream(chan, AUDID_EXPLODE2); break;
    case 2: Audio_PlayStream(chan, AUDID_EXPLODE3); break;
    case 3: Audio_PlayStream(chan, AUDID_EXPLODE4); break;
  }
}
@trap0xf | daifukkat.su/blog | scores | FIRE LANCER
<S.Yagawa> I like the challenge of "doing the impossible" with older hardware, and pushing it as far as it can go.
User avatar
nasty_wolverine
Posts: 1371
Joined: Sun Oct 09, 2011 11:44 pm

Re: Sound FX in shmups... how its done???

Post by nasty_wolverine »

thanks trap and norty....
I always thought that arcade hardware had very limited sound channels, around 4 or 8, new sounds kicking out old sounds..
what i did was created and enum of channels..

Code: Select all

enum sound_channel
{
	PLAYER	= 0x0000,
	EXPLOSION	= 0x0001,
	ITEM		= 0x0002,
	EFFECT	= 0x0003,
	MENU		= 0x0004,
	SPECIAL1	= 0x0005,
	SPECIAL2	= 0x0006,
	FREE		= 0x0007, //this one just plays the sound in any free channel apart from the above listed
};
and then to play sounds i just use this function

Code: Select all

audio()->playeffect(explosion, loop, vol, EXPLOSION);
not getting any disturbing volume levels, pretty balanced...
Elysian Door - Naraka (my WIP PC STG) in development hell for the moment
relminator
Posts: 55
Joined: Sat Jun 05, 2010 1:48 pm

Re: Sound FX in shmups... how its done???

Post by relminator »

nasty_wolverine wrote:thanks trap and norty....
I always thought that arcade hardware had very limited sound channels, around 4 or 8, new sounds kicking out old sounds..
what i did was created and enum of channels..

Code: Select all

enum sound_channel
{
	PLAYER	= 0x0000,
	EXPLOSION	= 0x0001,
	ITEM		= 0x0002,
	EFFECT	= 0x0003,
	MENU		= 0x0004,
	SPECIAL1	= 0x0005,
	SPECIAL2	= 0x0006,
	FREE		= 0x0007, //this one just plays the sound in any free channel apart from the above listed
};
and then to play sounds i just use this function

Code: Select all

audio()->playeffect(explosion, loop, vol, EXPLOSION);
not getting any disturbing volume levels, pretty balanced...
That's what I do actually. I also use that enum to preallocate how many elements my array needs to store my sound and music.

Then make my sound class as a singleton so that I could call it anywhere.

Note: Code is from a Nintendo DS game.

Code: Select all

/******************************************************************************
*******************************************************************************

	Bubble Fight EX
	relminator
	http://rel.betterwebber.com


	Singleton Sound class


*******************************************************************************
******************************************************************************/

#include <nds.h>
#include <maxmod9.h>
#include <vector>

#include "UTIL.h"

#ifndef SOUND_H
#define SOUND_H


//#define NO_SOUND


enum E_BGM
{
    E_BGM_LEVEL01,
};

enum E_SFX
{
    E_SFX_JUMP,
	E_SFX_BOUNCE,
    E_SFX_HURT
};

class Sound {

	static Sound* ms_instance;

public:
	inline static Sound* Instance();
	inline static void Release();

	inline void Init( mm_addr soundbank );
	inline void SetMode( mm_mode_enum mode );
	inline void SetMasterVolume( mm_word _volume ); 

	inline void LoadBGM( mm_word module_ID );
	inline void LoadSFX( mm_word sample_ID );
	
	inline void UnloadBGM( mm_word module_ID );
	
	inline void PlayBGM( int index, mm_pmode mode );
	inline void PlaySFX( int index );
	
	
	inline void StopBGM();
	
	inline void FadeBGM( s32 &Interp, s32 Speed );
	

private:
	Sound();
	~Sound();
	
	
	std::vector<mm_word> 	BGM_ID;
	std::vector<mm_word>	SFX_ID;
	
	std::vector<mm_sound_effect> SFX;
	
	
	int 			num_bgm;
	int 			num_sfx;
	
	s32 			volume;
	int 			master_volume;		// max 1024
	

};


//--------------------------------------
//	
//--------------------------------------
inline Sound::Sound()
{
	
	num_bgm = 0;
	num_sfx = 0;
	
	volume = 1024 << 12;
	master_volume = 512;
	
}

inline Sound::~Sound()
{
	
	BGM_ID.clear();
	SFX_ID.clear();
	SFX.clear();
	
}

//--------------------------------------
//	
//--------------------------------------
inline Sound* Sound::Instance()
{
	if(ms_instance == 0){
		ms_instance = new Sound();
	}
	return ms_instance;
}

//--------------------------------------
//	
//--------------------------------------
inline void Sound::Release()
{
	if(ms_instance){
		delete ms_instance;
	}
	ms_instance = 0;
}


#ifndef NO_SOUND

//--------------------------------------
//	
//--------------------------------------
inline void Sound::Init( mm_addr soundbank )
{
	mmInitDefaultMem( (mm_addr)soundbank );
}

//--------------------------------------
//	
//--------------------------------------
inline void Sound::SetMode( mm_mode_enum mode )
{
	mmSelectMode( mode );
}

//--------------------------------------
//	
//--------------------------------------
inline void Sound::SetMasterVolume( mm_word _volume )
{
	volume = _volume << 12;
	master_volume = _volume;
	mmSetModuleVolume( _volume );
}

//--------------------------------------
//	
//--------------------------------------
inline void Sound::PlayBGM( int index, mm_pmode mode )
{
	mmStart( BGM_ID[index], mode );
}

//--------------------------------------
//	
//--------------------------------------
inline void Sound::PlaySFX( int index )
{
	mmEffectEx(&SFX[index]);
}

//--------------------------------------
//	
//--------------------------------------
inline void Sound::StopBGM()
{
	mmStop();
}

//--------------------------------------
//	
//--------------------------------------
inline void Sound::FadeBGM( s32 &Interp, s32 Speed )
{
	
	Interp += Speed;
	Interp = UTIL::Clamp(Interp,0,4096);
	
	volume = UTIL::Lerpf32( 0 << 12, master_volume << 12, Interp );
	
	mmSetModuleVolume( volume >> 12 );
	
}


//--------------------------------------
//	
//--------------------------------------
inline void Sound::LoadBGM( mm_word module_ID )
{
	
	mmLoad( module_ID );
	BGM_ID.push_back(module_ID);
	num_bgm++;

}

//--------------------------------------
//	
//--------------------------------------
inline void Sound::LoadSFX( mm_word sample_ID )
{

	mm_sound_effect sfx;
	
	mmLoadEffect( sample_ID );
	
	SFX_ID.push_back(sample_ID);
	
	sfx.id      = sample_ID; 	// sample ID (make sure it is loaded)
	sfx.rate    = 1024;     	// playback rate, 1024 = original sound
	sfx.handle  = 0;           // 0 = allocate new handle
	sfx.volume  = 255;         // volume level
	sfx.panning = 128;     	   // panning at center
	
	SFX.push_back(sfx);
	
	num_sfx++;

}

//--------------------------------------
//	
//--------------------------------------
inline void Sound::UnloadBGM( mm_word module_ID )
{
	mmUnload( module_ID );
	std::vector<mm_word>::iterator iter;
	for( iter = BGM_ID.begin(); iter != BGM_ID.end(); ++iter )
	{
		if( (*iter) == module_ID )
		{
			BGM_ID.erase(iter);
		}
	}
	
}

#else   // NO_SOUND

inline void Sound::Init( mm_addr soundbank )
{
}
inline void Sound::SetMode( mm_mode_enum mode )
{
}
inline void Sound::SetMasterVolume( mm_word _volume )
{
}
inline void Sound::PlayBGM( int index, mm_pmode mode )
{
}
inline void Sound::PlaySFX( int index )
{
}
inline void Sound::StopBGM()
{
}
inline void Sound::FadeBGM( s32 &Interp, s32 Speed )
{
}
inline void Sound::LoadBGM( mm_word module_ID )
{
}
inline void Sound::LoadSFX( mm_word sample_ID )
{
}
inline void Sound::UnloadBGM( mm_word module_ID )
{
}

#endif  // NO_SOUND


#endif // SOUND_H

User avatar
nasty_wolverine
Posts: 1371
Joined: Sun Oct 09, 2011 11:44 pm

Re: Sound FX in shmups... how its done???

Post by nasty_wolverine »

@relminator:
Why is all your code inlined??? you are better of letting your compiler inline and optimize your code, or is the compiler not optimizing...??

anyway, your sound engine structure is very similar to mine, except i just have very few function...
the audio engine just does the below
1) set global music and fx volume
2) play fx and music
3) stop music (I need to add in how to stop the music, like fade out or cold turkey)

I put sound file loading into a seperate resource manager...
Elysian Door - Naraka (my WIP PC STG) in development hell for the moment
relminator
Posts: 55
Joined: Sat Jun 05, 2010 1:48 pm

Re: Sound FX in shmups... how its done???

Post by relminator »

nasty_wolverine wrote:@relminator:
Why is all your code inlined??? you are better of letting your compiler inline and optimize your code, or is the compiler not optimizing...??

anyway, your sound engine structure is very similar to mine, except i just have very few function...
the audio engine just does the below
1) set global music and fx volume
2) play fx and music
3) stop music (I need to add in how to stop the music, like fade out or cold turkey)

I put sound file loading into a seperate resource manager...

Well, it's a code for the Nintendo DS (66 mhz, 4mb for code + data) and the SDK developers use "inline" their declares. And since I have no idea what they change in their version of GCC to work on ARM7/9, I just followed their style. I am well aware of the fact that MSVS and GCC on the PC disregards "inline".

Notice that some of the declares are duplicates and they contain nothing. It allows me to compile with the #NO_SOUND option.

Fading is implemented in that header by simple interpolation.
User avatar
nasty_wolverine
Posts: 1371
Joined: Sun Oct 09, 2011 11:44 pm

Re: Sound FX in shmups... how its done???

Post by nasty_wolverine »

ahh... at work we call it standardizing errors... some guy somewhere screws up and doesnt tell anyone about it...
so when the next guy starts working on it, he sees the first guy has done so he does it too... and now making that error has become a formal process... 8)

SDL has a function which lets you fade out on stop, been lazy not to implement it :D
Been working on how to let go cpu when the workload is less, apart from using win32 functions sdl has the worst resolution timers (10ms resolution where as a frame takes 16.6ms at 60FPS)
As norty said before, building a game is like building a house of cards, takes too much patience or you run out of cards for that grand plan, or the neighbors kid just takes it down with a suplex....

anyway, new vid -> http://youtu.be/wTWEJCIbn04 calling it abstract wars
maybe i ll start a new thread for it as soon as i have more content...
Elysian Door - Naraka (my WIP PC STG) in development hell for the moment
Post Reply