Jump to content
  • Advertisement
Sign in to follow this  

direct sound newbie--question about segments

This topic is 5145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ?

//in GameInit()
CoCreateInstance(CLSID_DirectMusicLoader, NULL, 
                 CLSCTX_INPROC, IID_IDirectMusicLoader8,

CoCreateInstance(CLSID_DirectMusicPerformance, NULL,
                 CLSCTX_INPROC, IID_IDirectMusicPerformance8,
                 (void**)&g_pPerformance );
// end of COM and DMusic setup
// init audio
   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.
    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";
		(LPVOID*) &g_pSegment2);

g_pSegment->Download( g_pPerformance );

//In HandleInput




    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_pSegment2, NULL, NULL, 

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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!