DirectMusic - can't get sound to loop?

Grand Nagus

Newcomer
Joined
Jan 7, 2004
Messages
10
Hey guys. Coding for Direct3D is fun, but how much fun is a game without sound? :)

Anyways, I've created a simple DirectMusic performance object...
Code:
	if (FAILED(MyGame->g_pPerformance->InitAudio( 
		NULL,				// IDirectMusic interface not needed.
		NULL,				// IDirectSound interface not needed.
		NULL,				// Window handle.
		DMUS_APATH_SHARED_STEREOPLUSREVERB,	// Default audiopath type.
		64,					// Number of performance channels.
		DMUS_AUDIOF_ALL,	// Features on synthesizer.
		NULL				// Audio parameters; use defaults.
	)))

loaded it up with data...
Code:
			if (FAILED(MyGame->g_pLoader->LoadObjectFromFile(
				CLSID_DirectMusicSegment,					// Class identifier.
				IID_IDirectMusicSegment8,					// ID of desired interface.
				MyGame->MusicFiles[i].SoundName,			// wstrFileName,	// Filename.
				(LPVOID*) &MyGame->MusicFiles[i].g_pSegment	// Pointer that receives interface.
				)))

and loaded the music segments into my performance object...
Code:
			if ( FAILED(MyGame->MusicFiles[i].g_pSegment->Download(MyGame->g_pPerformance)) )

and can play sound effects using this...
Code:
MyGame->g_pPerformance->PlaySegment(MyGame->MusicFiles[SoundFX].g_pSegment, (DMUS_SEGF_NOINVALIDATE), NULL, NULL);

...and it all works pretty well. I can get sound effects to play whenever I want, and they don't interrupt each other when the playing sound effects get numerous.

But what I'm having a problem with is 'looping' a sound; more specifically, a music track. Here's what I'm doing to try to loop the song stored in array 6:
Code:
	MyGame->MusicFiles[6].g_pSegment->SetRepeats(DMUS_SEG_REPEAT_INFINITE);
	MyGame->g_pPerformance->PlaySegmentEx(MyGame->MusicFiles[6].g_pSegment, NULL, NULL, 0, 0, NULL, NULL, NULL);
When the song plays, it plays once and stops. I thought that the flag 'DMUS_SEG_REPEAT_INFINITE' was to make it repeat over and over, but it only plays once. How do I get it to play indefinitely? :confused:

Thanks in advance for the help!
 
I need to post more often! It seems that whenever I post, I figure out my problem almost right after I post. Heh!

Anyways, it had to do with setting up my sound effects segment with the 'DMUS_SEGF_SECONDARY' flag. After I did that, Voila! It worked!

OK, for those of you who want to do what I'm doing:

Play primary (music) sound:
Code:
g_pPerformance->PlaySegmentEx(g_pSegment, NULL, NULL, 0, 0, NULL, NULL, NULL);

Play secondary (sound effects) sound:
Code:
g_pPerformance->PlaySegmentEx(g_pSegment, NULL, NULL, DMUS_SEGF_SECONDARY, 0, NULL, NULL, NULL);

Purdy neat! Now my game has music AND sound effects! Plus, I don't have to get my program to jump through flaming hoops to keep sounds from getting interrupted when a new one is played. Yippee! Granted, what I'm doing is prolly pretty 'old hat' compared to what most of you are doing, but I've only been coding with DirectX for only a few months. It's still new to me, so I still get pretty excited to see a game slowly flesh out of pages of DirectX and C++ code!

Well, back to work. Have a good weekend! :)
 
Back
Top