Multiple Sounds with DMUS_SEGF_SECONDARY

Started by
4 comments, last by Brendan Bond 20 years, 2 months ago
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]
Brendan Bond
Advertisement
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
Brendan Bond
I don''t know much about this really, but I remember reading somewhere that you need a primary buffer and then secondary buffers.
And the rockets' red glare, the bombs bursting in air,gave proof through the fight that our flag was still there.Oh say, does that star-spangled banner yet waveover the land of the free and the home of the brave?
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.
Brendan Bond
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.
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);}
Brendan Bond

This topic is closed to new replies.

Advertisement