Original Post
Hey, I am using directx 8.0 direct sound. I have never programmed sound before and have been browsing some of the articles on this website. I have managed to load to sound files, which I can play simultaneously using the DMUS_SEGF_SECONDARY flag when I call PlaySegmentEx. My question is do I need to load a different segment for every single direct x sound file that I want to be able to play? What is a good way to store/organize in memory all these sound files. I'll put some sample code in here of the application I have at the moment. My thinking for the game is I need a background music that can just play straight through the level and loop, plus sound effects for many actions. Anyway, here is the relevent code that I have for this part. Also when I turn that flag on for the background music, the song goes REALLY slowly. Does this mean that the file is just too big to be a secondary sound file ? Note that everything works as it is supposed to, just I want to make sure before I actually throw this code into my game that I use the best method or organizing many sounds. Thanks!! Daniel
//in GameInit()
CoInitialize(NULL);
CoCreateInstance(CLSID_DirectMusicLoader, NULL,
CLSCTX_INPROC, IID_IDirectMusicLoader8,
(void**)&g_pLoader);
CoCreateInstance(CLSID_DirectMusicPerformance, NULL,
CLSCTX_INPROC, IID_IDirectMusicPerformance8,
(void**)&g_pPerformance );
// end of COM and DMusic setup
// init audio
g_pPerformance->InitAudio(
NULL, // IDirectMusic interface not needed.
NULL, // IDirectSound interface not needed.
g_hWndMain, // 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.
);
// end init audio
CoCreateInstance(CLSID_DirectMusicSegment, NULL, CLSCTX_INPROC,
IID_IDirectMusicSegment8, (void**) &g_pSegment);
CoCreateInstance(CLSID_DirectMusicSegment, NULL, CLSCTX_INPROC,
IID_IDirectMusicSegment8, (void**) &g_pSegment2);
// Set the search directory.
g_pLoader->SetSearchDirectory(
GUID_DirectMusicAllTypes, // Types of files sought.
/*L"C:\\Program Files\\KaZaA\\My Shared Folder"*/ NULL, // Where to look. Null for default
FALSE // Don't clear object data.
); // This function has a lot of stuff I did to it, explained below
WCHAR wstrFileName[MAX_PATH] = L"backinussr.mid";
//The above line's filename should be changed to whatever you wish to load
//It can either be mid or wav files. Maybe others, look it up.
if (FAILED(g_pLoader->LoadObjectFromFile(
CLSID_DirectMusicSegment, // Class identifier.
IID_IDirectMusicSegment8, // ID of desired interface.
wstrFileName, // Filename.
(LPVOID*) &g_pSegment))) // Pointer that receives interface.
{
MessageBox( NULL, "Media not found, sample will now quit.",
"DMusic Tutorial", MB_OK );
return 0;
}
WCHAR wstrFileName2[MAX_PATH] = L"start.wav";
g_pLoader->LoadObjectFromFile(
CLSID_DirectMusicSegment,
IID_IDirectMusicSegment8,
wstrFileName2,
(LPVOID*) &g_pSegment2);
g_pSegment->Download( g_pPerformance );
g_pSegment2->Download(g_pPerformance);
//In HandleInput
if (KEYDOWN(VK_LEFT)) {
g_pPerformance->StopEx(g_pSegment,0,0);
}
if (KEYDOWN(VK_RIGHT)) {
g_pPerformance->PlaySegmentEx(
g_pSegment, // Segment to play.
NULL, // Used for songs; not implemented.
NULL, // For transitions.
NULL, // DMUS_SEGF_SECONDARY, // Flags.
0, // Start time; 0 is immediate.
NULL, // Pointer that receives segment state.
NULL, // Object to stop.
NULL // Audiopath, if not default.
);
}
if (KEYDOWN(VK_UP)) {
g_pPerformance->PlaySegmentEx(
g_pSegment2, NULL, NULL,
DMUS_SEGF_SECONDARY,
0, NULL,NULL,NULL);
}