Jump to content
  • Advertisement

Archived

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

DanTheRocker

Playing two sounds at the same time

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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!