Multiple streams/sounds with Audiere

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
$w!tCh
Posts: 10
Joined: Mon Dec 19, 2005 7:35 am
Location: India

Multiple streams/sounds with Audiere

Post by $w!tCh »

hi all,
i am using the shooting code from the tech demo...and the function is called by a mouse click...i am using thecod for playing the gun shot sound from the tech demo... the problem is if i am shootin continuosly i hear the gun shot only for the first click and the next sound comes only after the first one hs finished playing... i want the sounds to be heard simultaneously when the shootin is continuos...not posting the code cuz its directly from the tech demo...

can i use audeire for multiple gun shots at a time...
thanks in advance...
Guest

Post by Guest »

one way of doing it is to set up a small array (enough to cover the longest length your sample could play for).

if the sound lasts 2 seconds and you can fire every 0.5 seconds you will need 4 instances of audiereobjects.

psuedo code:

audiereob[4] = "gunshot.wav"

if shoot

if audiereob[0]->isPlaying()
audiereob[1]->play
else
audiereob[0]->play

if audiereob[1]->isPlaying()
audiereob[2]->play
else
audiereob[1]->play

if audiereob[2]->isPlaying()
audiereob[3]->play
else
audiereob[2]->play

if audiereob[3]->isPlaying()
audiereob[0]->play
else
audiereob[3]->play


obviously that is not real code but you get the idea - it can be tweaked or optimised.
[/code]
$w!tCh
Posts: 10
Joined: Mon Dec 19, 2005 7:35 am
Location: India

Post by $w!tCh »

is that how everyone is handling the multiple sounds????

Guest:
wont this creat a problem when i have more number of players... lets imagine there are ten players and the bullets are shot one after the other.. then following ur way wont it cause too many array just for sound...

isn't there a better way to handle this??? something that is built in with Audier....
thanks anyways,..
MiNalien
Posts: 9
Joined: Mon Feb 06, 2006 6:05 pm

Post by MiNalien »

I'm not sure if this will work or not, but you could define a number of audiere objects (a decent number would be somewhere less than 100) as an array, then have it do a for loop to find the highest one not playing

ie: for Guest's code

Code: Select all

audiereob[100] = "gunshot.wav"

if shoot

for(int i = 0; i < 100; i++)
{
if(!audiereob[i]->isPlaying())
audiereob[i]->play();
}
Guest

Post by Guest »

well i didnt realise it was for multiplayer but yeah like MiNalien posted (which is basically the same but in a different way) - there should be a maximum you would ever use if you know the total max players, the length of sound and firing rate. failing that just use a vector (dynamic array) and enlarge it on the fly to suit, if you could feasibly have 100 players or just 1 player.
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Post by MikeR »

Have you looked at the audiere.h file?
/**
* SoundEffect is a convenience class which provides a simple
* mechanism for basic sound playback. There are two types of sound
* effects: SINGLE and MULTIPLE. SINGLE sound effects only allow
* the sound to be played once at a time. MULTIPLE sound effects
* always open a new stream to the audio device for each time it is
* played (cleaning up or reusing old streams if possible).
*/
Audiere has a sound effect module for just what you are looking to do.
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
$w!tCh
Posts: 10
Joined: Mon Dec 19, 2005 7:35 am
Location: India

Post by $w!tCh »

that sounds promising.... thanks mikeR.... cant wait to try it out... thanks a lot guys...

programming rocks... create wonders with snippets... best luck..thanks again... :D
Post Reply