Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

colinisinhere

sound?

This topic is 5384 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For my game i am currently using the function PlaySound(); to play my sound, but i noticed with that function it can only play one sound at a time... how can i make it play about 20 sounds at a time?

Share this post


Link to post
Share on other sites
Advertisement
Playing more than one sound at a time involves mixing buffers. Each sound has it''s own individual buffer of sound data, while the sound system itself plays sound from a buffer. By mixing different sample buffers into the stream, you can combine sound from different sources (sound effects, looping music track, etc) into a single stream for output to the sound device.

Without knowing what API you are using (PlaySound() isn''t really descriptive) it is impossible to be more specific than that.

APIs such as OpenAL make creation, manipulation and mixing of sound samples fairly easy. OpenAL also makes it easy to implement 3D sound as well, by using Listeners.


Josh
vertexnormal AT linuxmail DOT org


Check out Golem at:
My cheapass website

Share this post


Link to post
Share on other sites
You could use DirectSound or DirectMusic.

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

Share this post


Link to post
Share on other sites
<< For my game i am currently using the function PlaySound() >>

I had the same problem, so I learned DirectSound. Wrote a short demo with straight C interface. You have to load each sound in buffers beforehand. Simplest DirectSound here

DirectSoundDemo.cpp EXE

This uses dsutil.cpp and dsutil.h

The new problem you'll have is being able to play the same WAV simultaneously. For example, an explosion sound that plays for 3 seconds, but 1 second in you need to play the same WAV again. You'll only hear the first one until it finishes.

I'm guessing you can load a couple of the same WAV in different buffers, and use an array to check if one is playing, then play the next one in array that is not playing, etc. That way you can mix even the same sound simultaneously. With Win PlaySound you're stuck since there is no mixing.

Phil P

[edited by - PhilVaz on September 23, 2003 12:25:17 AM]

Share this post


Link to post
Share on other sites
That only happens in DirectSound if you play it in a primary buffer. To play multiple instances of a single sound, play it in a secondary buffer.

Share this post


Link to post
Share on other sites
<< To play multiple instances of a single sound, play it in a secondary buffer. >>

Are you sure? If I understand how DirectSound works from the documentation, I thought all sounds play (i.e. get mixed) in the primary buffer. The secondary is only for storage of the sound (in my case WAV files). They don't play (i.e. get mixed) in the secondary buffer, only the primary (on the sound card).

I am playing my WAVs from secondary buffers, but if the same sound is played you only hear the first one. For example, my asteroids clone uses DirectSound, if two large rocks (or two medium, or two small) are hit in quick succession, you only hear the first sound, even though I'm playing 2 sounds.

I would like to solve it, I still think I have to store multiple copies of the same sound in separate buffers in order to hear 2 or more instances of the same sound.

Vazteroids.cpp EXE

Phil P

[edited by - PhilVaz on September 23, 2003 12:42:04 AM]

Share this post


Link to post
Share on other sites
I have a plug and play DirectSound 8 class posted at the DevZone that''s main intent is to play Ogg files though you can use it for anything. Ogg + DSound == 100% free for any purpose.

I dropped it down to DirectSound 7 (a few simple changes to variable and function names) for compatibility but that version hasn''t been posted. If you plan on your project being compatible with older hardware you''ll want to use DX7.

Ben


[ IcarusIndie.com | recycledrussianbrides.com | Got Linux? ]


Will Post For Food

Share this post


Link to post
Share on other sites
If you wanna make it even easier, use DirectMusic (rather than DirectSound directly). Then just create a loader and a performance, load the wave to a segment, download it to the performance, and play it however many times you want. If in the future you want to work with 3D sound, you can just play each instance through a separate audiopath and get a direct sound 3D buffer interface from the audiopath and manipulate its 3D parameters (location, velocity, cone, orientation, and effects after query''ing for an IDirectSoundBuffer8), and manipulate the listener via a listener interface pulled from the primary buffer through the audiopath. This way, you can load wav files (as well as any form of ACM compressed wav via segments, hence using directmusic) and play them many times overlapping each with separate changeable settings. You can get the directx sdk and directmusic producer for creating segments at http://msdn.microsoft.com/directx The documentation is pretty well done considering you have a basic understanding of COM.

Share this post


Link to post
Share on other sites
quote:
Original post by PhilVaz
<< To play multiple instances of a single sound, play it in a secondary buffer. >>

Are you sure? If I understand how DirectSound works from the documentation, I thought all sounds play (i.e. get mixed) in the primary buffer. The secondary is only for storage of the sound (in my case WAV files). They don''t play (i.e. get mixed) in the secondary buffer, only the primary (on the sound card).



PhilVaz is right. You can only play multiple sounds on top of each other using DirectSound if you duplcate the secondary buffer.

The best solution is the one recommended in the DX9 docs, and by Polymorphic OOP. Use direct music to and a performance object. Not only can you load any wav file easily without parsing it yourself, but you can play multiple sounds on top of each other. The code is very short and simple too, smaller than the buffer system.

Mark
Cornutopia Games
http://www.cornutopia.net
Sound Effects For Game Developers
http://www.indiesfx.co.uk

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!