playing lotsa sounds at the same time

Started by
3 comments, last by CoolMike 24 years, 2 months ago
It only took me about a half hour to get DirectSound up and running and playing sounds. I can play lots of sounds together at the same time, but not the same sound. For instance, every game loop I want the game to play a gunshot sound. But instead of playing the gunshot sound each loop (starting the sound over each frame) it just plays it and repeats when done, so in actuality about 100 frames go by for each sound. So all it is doing is waiting until the sound is done playing before it starts again. I don''t want this. If I have a machine gun shooting 10 rounds per second, I want the sounds to be played at 10 per second, meaning I must have the sound played while the previous sound is still playing. I know this is possible, but do I need multiple buffers for the same sound or what? Thanks in advance.
Advertisement
Keep on reading the doc''s, it''s all in there. You need another instance of the sound, but you don''t need any more buffers. ie. you load the sound once into the buffer and have multiple pointers to it.
William Reiach - Human Extrodinaire

Marlene and Me


Let''s say I want to play a gun shot sound a bunch of times,
and I don''t wanna wait for the last gun shot sound to finish.
So I use DuplicateSoundBuffer() to create duplicate pointers
to my gun shot sound data. And I play the duplicate sound.

That''s the easy part.

Question is, what do I do with all these pointers after the
sound is played? I know I have to delete/get rid of them, but
how do you do that safely? I obviously have to keep track of
them all, and I probably want to be able to create as many
pointers as needed, and I also have to be able to wait for it
to finish playing completely.

How do I manage and clean this mess up?

Jason
Hello, does anybody use DuplicateSoundBuffer() for
sound repetition?

Jason
I could be wrong, but I think he means that he tries to play the sound over and over again every frame:

frame()
{
// every frame play the sound
play_sound();
}

If you don''t stop the sound first, then nothing will happen and the sound will continue to play. Try:

frame()
{
// stop last frames sound
stop_sound();
// play this frame sound
play_sound();
}

Jim

This topic is closed to new replies.

Advertisement