Archived

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

Brendan Bond

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);

	_dmLoaderPtr->SetSearchDirectory(GUID_DirectMusicAllTypes, searchPath, 0);

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

	_dmLoaderPtr->LoadObjectFromFile(CLSID_DirectMusicSegment, IID_IDirectMusicSegment8, wideFileName, 
									 (void**)&_dmSgmntsPtr[sndID]);

	_dmSgmntsPtr[sndID]->Download(_dmPerformancePtr);
}

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 this post


Link to post
Share on other sites
PlayGGY    122
I don''t know much about this really, but I remember reading somewhere that you need a primary buffer and then secondary buffers.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
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.

Share this post


Link to post
Share on other sites
Brendan Bond    145
Ok, here''s the initialization code:


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);
}

Share this post


Link to post
Share on other sites