#### Archived

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

# Multiple Sounds with DMUS_SEGF_SECONDARY

## Recommended Posts

Brendan Bond    145
I'm having a problem with IDirectMusicSegment8; what I have is a sound wrapper class that loads a sound into an array of IDirectMusicSegment8*'s. After you load the sound, the class plays the sound with the PlaySegmentEx function. The weird thing about this is that even though I use the flag DMUS_SEGF_SECONDARY when I play any segment, I still can't play multiple files at once. Here's the code:
void Sound::Load(char* fileName, int sndID){
WCHAR searchPath[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, ".\\sounds", -1, searchPath, MAX_PATH);
WCHAR wideFileName[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, fileName, -1, wideFileName, MAX_PATH);

CoCreateInstance(CLSID_DirectMusicSegment, 0, CLSCTX_INPROC, IID_IDirectMusicSegment8,
(void**)&_dmSgmntsPtr[sndID]);

(void**)&_dmSgmntsPtr[sndID]);

}

void Sound::Play(int sndID){
_dmPerformancePtr->PlaySegmentEx(_dmSgmntsPtr[sndID], 0, 0, DMUS_SEGF_SECONDARY, 0, 0, 0, 0);
}

After that, in main, I load the file and then play it in the game's loop. [edited by - Brendan Bond on January 24, 2004 2:44:09 PM]

##### Share on other sites
Brendan Bond    145
Oh, yeah, and for a while it was able to play two sounds at once, but only if you played the second sound halfway through the first.

-Brendan Bond

PlayGGY    122

##### Share on other sites
Brendan Bond    145
Well, I read (I believe on these forums) that DMUS_SEGF_SECONDARY was usable, and that you didn''t need a primary sound; you could simply specify them all as secondary.

##### Share on other sites
Guest Anonymous Poster
I can''t imagine why the two sounds would only play if the second sound if played halfway through the first, but maybe posting your initialization code could help someone answer your question.

void Sound::Create(){	CoInitialize(0);		CoCreateInstance(CLSID_DirectMusicPerformance, 0, CLSCTX_INPROC, IID_IDirectMusicPerformance8, 					 (void**)&_dmPerformancePtr);	_dmPerformancePtr->InitAudio(0, 0, 0, DMUS_APATH_DYNAMIC_STEREO, 64, DMUS_AUDIOF_ALL, 0);		CoCreateInstance(CLSID_DirectMusicLoader, 0, CLSCTX_INPROC, IID_IDirectMusicLoader8, 					 (void**)&_dmLoaderPtr);}