• Advertisement

Archived

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

Playing two sounds at the same time

This topic is 5973 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

Im using DirectX 8.0 and want to be able to play more than one sound at the same time. I''ve run into a problem when trying to do this because when i call a function that plays a sound, and call it again, the first sound stops and the second one takes over. How do I overcome this?

Share this post


Link to post
Share on other sites
Advertisement
What functions are you using. Because DirectSound can play multiple sounds at once (I think, i dont use DirectX8, but iv had previous experience with DX7)

Share this post


Link to post
Share on other sites
i having problem wit running direct sound ( the samples as well,) i able to run it , but it doesn produce any sound
wat wrong wit it

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I tried making a cool sound engine using DirectX, but it took over a year of hard work and it never sounded like I wanted it too. I got quite suicidal after that, never thought I would succeed in making a sound engine nor a game for that matter.

Then in my despair I tried a different approach, just for the heck of it. I tried OpenAL.

WOW!

In just one week I had a working sound engine that really kicked ASS.

After that I never used DirectSound again, although I know OpenAL uses DirectSound under windows, I dont want to combat it again myself.

Read And Learn.

Share this post


Link to post
Share on other sites
Im using DirectMusic from directX 8. Its incredibly simple to do.
Here is the entire source for mu DSound class:
(I suggest copying and pasting it into a text editor)

//-----------------------------------------------------------------------------
// File: DSOUND.cpp
//
// Desc: Plays Sounds
//
// Copyright (c) 2001 Dan
//-----------------------------------------------------------------------------
#define INITGUID


#include
#include "DSOUND.h"


//---------------------------------------------------------------------
// Contstructor / Destructor
//---------------------------------------------------------------------
DSOUND::DSOUND( bool SoundOn )
{
pLoader = NULL;
pPerformance = NULL;
SoundEnabled = SoundOn;
}

DSOUND::~DSOUND()
{
}


//-----------------------------------------------------------------------------
// Name: Initalize()
// Desc: Terminates the DirectSound Components
//-----------------------------------------------------------------------------
bool DSOUND::Initalize()
{
if( SoundEnabled )
{
CoInitialize(NULL);

CoCreateInstance( CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC,
IID_IDirectMusicLoader8, (void**)&pLoader );
Log(" Initalized Loader object\n");

CoCreateInstance( CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC,
IID_IDirectMusicPerformance8, (void**)&pPerformance );

Log(" Initalized Performance object\n");

pPerformance->InitAudio( NULL, NULL, NULL,
DMUS_APATH_SHARED_STEREOPLUSREVERB, 64,
DMUS_AUDIOF_ALL, NULL );
Log(" Initalized audio\n\n");

return true;
}

return false;
}


//-----------------------------------------------------------------------------
// Name: PlayAudioFile()
// Desc: Plays an audio file. If it is not loaded, it loads it. If already
// loaded it is played
// To use format is: PlayAudioFile( L"File.wav" );
//-----------------------------------------------------------------------------
bool DSOUND:layAudioFile( WCHAR *wstrFileName )
{
if( SoundEnabled )
{
DWORD dwFlags;

IDirectMusicSegment8* pSegment = NULL;

if( FAILED( pLoader->LoadObjectFromFile( CLSID_DirectMusicSegment,
IID_IDirectMusicSegment8,
wstrFileName,
(LPVOID*) &pSegment ) ) )
{
Log("ERROR: Could not find an the audio file\n");
return false;
}

// Download the segment''s instruments to the synthesizer
pSegment->Download( pPerformance );

// Play segment on the default audio path
dwFlags |= DMUS_SEGF_SECONDARY;
pPerformance->PlaySegmentEx(pSegment,
NULL, NULL,
dwFlags,
0,
NULL, NULL, NULL );
return true;
}

Log( "Sound System has Been disabled\n" );

return true;
}


//-----------------------------------------------------------------------------
// Name: Terminate()
// Desc: Terminates the DirectSound Components
//-----------------------------------------------------------------------------
bool DSOUND::Terminate()
{
Log( " Terminating DirectSound\n" );

if( SoundEnabled )
{
pPerformance->Stop( NULL, NULL, 0, 0 );
Log( " Stopping Output\n" );

pPerformance->CloseDown();
Log( " Closing Down\n" );

pLoader->Release();
Log( " Releasing Loader\n" );

pPerformance->Release();
Log( " Releasing Performance\n" );

CoUninitialize();
Log( " UnInitalizing\n" );
}

Log(" DirectSound Terminated\n\n");

return true;
}

Now all I need to do is call PlayAudioFile everytime I want to play a sound. It Mixes them together automatically so they all play at once. If you want to use this just remember that the syntax for calling PlayAudioFile is .PlayAudioFile( L"filename.wav" ); Hope this helped.

Share this post


Link to post
Share on other sites
Um, that post looked a little interesting...
1) For some reason the include at the top didnt show up. its dsound.h. in lower case. The class name is the same but in upper case.
2) On PlayAudioFile the P turned into a face. does (: P) do that?
3) There are only 3 Data members to the class in the .h file. They are

IDirectMusicLoader8* pLoader;
IDirectMusicPerformance8* pPerformance;
bool SoundEnabled;

Share this post


Link to post
Share on other sites
This would''ve already been answered in the DirectX forum.
Set the dwFlags parameter of PlaySegmentEx to DMUS_SEGF_SECONDARY.



-Forcas


"Elvis is alive. He is Barney the purple dinosaur. He is the pied piper that leads our children into the wages of sin and eternal damnation."



Share this post


Link to post
Share on other sites
Isn''t there any finished sound engine out there? One where you just can type PlaySound(SoundObject)? I''d like to be able to pan between left and right speaker and also change the volume but those are all the demands I''ve got...

Johan Torp - http://www.destruction.nu

Share this post


Link to post
Share on other sites
quote:
Original post by thorpe
Isn''t there any finished sound engine out there? One where you just can type PlaySound(SoundObject)? I''d like to be able to pan between left and right speaker and also change the volume but those are all the demands I''ve got...

Johan Torp - http://www.destruction.nu


Yup. Try fmod at http://www.fmod.org

Share this post


Link to post
Share on other sites
DuplicateSoundBuffer is the standard way of playing more than one sound simultaneously using DirectSound. Streaming is an alternative, but this is a little more complicated.

Cheers,
John

Share this post


Link to post
Share on other sites
fmod costs $200 for shareware games =(
Isn''t there anyone who has a simple streaming sound engine in their games? Please post it if you do.
If I have to make my own engine and anyone wants it, I can assure you that I will post it.

Johan Torp - http://www.destruction.nu

Share this post


Link to post
Share on other sites
The DirectX 8 samples contain quite a good streaming audio engine. Check out dmutil.cpp in the samples\multimedia\common directory.

This is the engine which is used to provide sounds for all the demos which come with the SDK. It has all the basic features you need in there: Load, Play, Stop, IsPlaying, etc. The code is also contains a lot of comments to help you along. It is definitely a good starting place for anyone who wants to learn DirectAudio.

It is also easy to extend the library to add features such as panning, 3D positioning, Environmental reverb, etc.

Cheers,
John

Share this post


Link to post
Share on other sites

  • Advertisement