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...
Multiple streams/sounds with Audiere
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]
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]
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,..
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,..
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
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();
}
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.
Have you looked at the audiere.h file?
Audiere has a sound effect module for just what you are looking to do./**
* 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).
*/
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
Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram