Jump to content
  • Advertisement


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


Direct Sound + .WAV

This topic is 6056 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

is there an easier way to load .wav files in a Soundbuffer as in the microsoft "Play Sound" example?

Share this post

Link to post
Share on other sites
Uh, not sure what you''re asking, but i use:
In fact i''m pretty sure that''s not what you''re asking for, but it works fine for me (sorry about the formatting.)

#include "CSimpleSound.h"

CSimpleSound::CSimpleSound(char *strPath)
// Initialize COM
// Create loader object
CoCreateInstance( CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC,
IID_IDirectMusicLoader8, (void**)&m_pLoader );

// Create performance object
CoCreateInstance( CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC,
IID_IDirectMusicPerformance8, (void**)&m_pPerformance );

// Initialize the performance with the standard audio path.
// This initializes both DirectMusic and DirectSound and
// sets up the synthesizer.
m_pPerformance->InitAudio( NULL, NULL, NULL,
//CHAR strPath[MAX_PATH];
//GetWindowsDirectory( strPath, MAX_PATH );
//strcat( strPath, "\\media" );

// Tell DirectMusic where the default search path is
WCHAR wstrSearchPath[MAX_PATH];
MultiByteToWideChar( CP_ACP, 0, strPath, -1,
wstrSearchPath, MAX_PATH );

m_pLoader->SetSearchDirectory( GUID_DirectMusicAllTypes,
wstrSearchPath, FALSE );
m_pSegment = NULL;

bool CSimpleSound:laySound (char *pFileName)
// Load the segment from the file
WCHAR wstrFileName[MAX_PATH];
MultiByteToWideChar( CP_ACP, 0, pFileName, -1,
wstrFileName, MAX_PATH );
if( FAILED( m_pLoader->LoadObjectFromFile( CLSID_DirectMusicSegment,
(LPVOID*) &m_pSegment ) ) )
MessageBox( NULL, "Media not found, sample will now quit",
"DirectMusic Tutorial", MB_OK );
return false;

// Download the segment''s instruments to the synthesizer
m_pSegment->Download( m_pPerformance );

// Play segment on the default audio path
m_pPerformance->PlaySegmentEx( m_pSegment, NULL, NULL, 0,
return true;

CSimpleSound::Stop ()
m_pPerformance->Stop( NULL, NULL, 0, 0 );

// Stop the music, and close down
m_pPerformance->Stop( NULL, NULL, 0, 0 );

// Cleanup all interfaces
SAFE_RELEASE (m_pLoader);
SAFE_RELEASE (m_pPerformance);
SAFE_RELEASE (m_pSegment);
// Close down COM

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!