Sign in to follow this  
cyric74

Simple & Fast Multiple Sounds?

Recommended Posts

cyric74    100
What is the most simple and quickest way to implement multiple sounds at once? I'm currently using DirectSound, but it's crashing whenever I try to loop more than one sound at a time. For my 4E4 entry, so nothing complicated.. Just need it working.

Share this post


Link to post
Share on other sites
remigius    1172
If you are using C#/Managed DX, you can use multiple instances of Audio objects found in the AudioVideoPlayback namespace. I don't know if there's something similar in normal DX, but maybe it's your lucky day :)

Share this post


Link to post
Share on other sites
cyric74    100
The problem with AudioVideoPlayback, at least from what I can tell (and I am using MDX with C#), is that it only allows for the sound data to be loaded from a file, and not a stream (as my sounds come from internal resource streams).

If I'm wrong about this, someone please correct me and make my day =D

What is my next best option? I see a lot of tutorials talking about using multiple secondary buffers, but my code dies the moment I try to instantiate another SecondaryBuffer object using the same sound device.

I spent most of the night reading tutorials, and they all were great for trying to do 3D sound, or getting sounds from streams, but none of them actually explained the methods behind looping multiple sounds at once.

Share this post


Link to post
Share on other sites
Darkneon    166
[Edit] Never mind, I've read your second post too fast :| . I still leave the message for others to see.

Like remigius side,

Here's a sample:

using Microsoft.DirectX.AudioVideoPlayback;

...

Audio audio1 = new Audio("song1.mp3", false);
Audio audio2 = new Audio("song2.mp3", false);

...

audio1.Play();
audio2.Play();

...

audio1.Stop();
audio2.Stop();

...

/* Clear Ressources */
audio1.Close();
audio1.Dispose();

audio2.Close();
audio2.Dispose();


Seriously, it doesn't get easier than that :)

You can also control the volume with Volume property. Note that setting it to 0 is saying 100% volume while setting it to -10000 is like 0% volume.

Darkneon

Share this post


Link to post
Share on other sites
cyric74    100
I've decided to go with AVplayback because it is very simple and works well with multiple tracks at once--to play from resources, I'm just going to write to a temp file, play it, then delete when done.

I have a quick question about AVPlayack, however: I've noticed that I can instantiate a non-permanent Audio object, in a class constructor for example, and it will continue to play the sound even after the life of that object *should* be over.

Does this create any memory leak problems? Can I just 'create-it-and-forget-it', or do I need to set up an object refrence where I can Stop and Dispose once finished? I guess my best example of this is a one-shot thunder sound for my ambient rain which is randomly played--will all those Audio objects remain in memory, or clean themselves up?

Share this post


Link to post
Share on other sites
cyric74    100
To answer my own question: Yes, AudioVideoPlayback creates a memory leak in a hurry. Must always explicit close and dispose the object.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this