Archived

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

Eibwen

Direct Sound + .WAV

Recommended Posts

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
CoInitialize(NULL);
// 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,
DMUS_APATH_SHARED_STEREOPLUSREVERB, 64,
DMUS_AUDIOF_ALL, 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,
IID_IDirectMusicSegment8,
wstrFileName,
(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,
0, NULL, NULL, NULL );
return true;
}

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

CSimpleSound::~CSimpleSound()
{
// Stop the music, and close down
m_pPerformance->Stop( NULL, NULL, 0, 0 );
m_pPerformance->CloseDown();

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

Share this post


Link to post
Share on other sites