我现在是通过网络接收到音频数据,请问如何用DirectSound来播放,哪位大哥有这方面的例子,请发一份给我,谢谢
DirectSound中有一个例子StreamData,但是是播放Wave文件的,我是将Socket收到的音频数据用DirectSound来播放,不知如何改.
[email protected]
DirectSound中有一个例子StreamData,但是是播放Wave文件的,我是将Socket收到的音频数据用DirectSound来播放,不知如何改.
[email protected]
解决方案 »
- 如何向OCX控件传递参数?
- 请教我在创建一个SOCKET连接的时候,可以指定本机的发起连接的端口吗?而不是由系统自动分配,请高手指点
- 送分题 怎么在VIEW里输出aaa回车bbb回车ccc
- CRichEditView保存问题!
- 请教几个问题,一个十分
- 一个小的Dll程序....老报错哇,求高人指点....
- 请问如何在一个基于对话框的程序中注册一个系统热键并使用?
- 求助!关于AfxGetMainWnd()的问题!
- 在VC中如何隐藏CONSOLE程序运行时的DOS窗口.
- 关于屏保保护口令验证对话框的编程问题。
- 求教如何实现对话框生成时自动最小化到托盘且在任务栏没有图标(注意是自动)?
- 变态的问题!!!
//
// Function to cleanup allocated objects
//
//--------------------------------------------------------------------------------------
void vCleanup( void )
{
if( g_pSound ) {
if( g_pPerformance )
g_pSound->Unload( g_pPerformance );
}
SAFE_RELEASE( g_pSound ); SAFE_RELEASE( g_pLoader );
SAFE_RELEASE( g_pPerformance );
}//--------------------------------------------------------------------------------------
//
// Function to initialize the sound system and load the various
// sounds needed for the game.
//
//--------------------------------------------------------------------------------------
bool bInitializeSoundSystem( HWND hWnd )
{
HRESULT hResult;
IDirectMusicAudioPath8 *dmAudioPath; // Initialize COM
CoInitialize( NULL );
// Create the loader
if( FAILED( hResult = CoCreateInstance( CLSID_DirectMusicLoader, NULL,
CLSCTX_INPROC, IID_IDirectMusicLoader8,
(void**) &g_pLoader ) ) ) {
return( 0 );
}
// Create the performance
if( FAILED( hResult = CoCreateInstance( CLSID_DirectMusicPerformance, NULL,
CLSCTX_INPROC, IID_IDirectMusicPerformance8,
(void**) &g_pPerformance ) ) ) {
return( 0 );
}
// Initialize the audio
if( FAILED( hResult = g_pPerformance->InitAudio(
NULL,
NULL,
hWnd,
DMUS_APATH_DYNAMIC_STEREO,
4,
DMUS_AUDIOF_ALL,
NULL
))) {
return( 0 );
}
// Get the default path
if( FAILED( g_pPerformance->GetDefaultAudioPath( &dmAudioPath ) ) )
return( 0 );
// Set the default volume
if( FAILED( dmAudioPath->SetVolume(0,0) ) )
return( 0 ); // Load the sound from a file
if ( FAILED(g_pLoader->LoadObjectFromFile (
CLSID_DirectMusicSegment,
IID_IDirectMusicSegment8,
L"testsound.wav",
( LPVOID* ) &g_pSound
) ) )
{
return( 0 );
}
// Download the data
if ( FAILED ( g_pSound->Download( g_pPerformance ) ) ) {
return( 0 );
} // Return success
return( 1 );
}//--------------------------------------------------------------------------------------
//
// Function to play the global sound file
//
//--------------------------------------------------------------------------------------
void vPlaySound( void )
{
// Play the sound segment
g_pPerformance->PlaySegmentEx(
g_pSound,
NULL,
NULL,
DMUS_SEGF_DEFAULT | DMUS_SEGF_SECONDARY,
0,
NULL,
NULL,
NULL
);
}
// Name: SoundSystem::hrInitSoundSystem()
// Desc: Initializes Direct Audio
//-----------------------------------------------------------------------------
HRESULT SoundSystem::hrInitSoundSystem(void)
{
HRESULT hResult;
IDirectMusicAudioPath8 *path; // Initialize COM
CoInitialize(NULL);
// Create the loader
if( FAILED( hResult = CoCreateInstance(CLSID_DirectMusicLoader, NULL,
CLSCTX_INPROC, IID_IDirectMusicLoader8,
(void**)&pLoader) )) {
return(SOUNDERROR_MUSICLOADER);
}
// Create the performance
if( FAILED( hResult = CoCreateInstance(CLSID_DirectMusicPerformance, NULL,
CLSCTX_INPROC, IID_IDirectMusicPerformance8,
(void**)&pPerformance ))) {
return(SOUNDERROR_MUSICPERFORMANCE);
}
// Initialize the audio
if( FAILED( hResult = pPerformance->InitAudio(
NULL,
NULL,
hWnd,
DMUS_APATH_DYNAMIC_STEREO,
4,
DMUS_AUDIOF_ALL,
NULL
))) {
return(SOUNDERROR_INITAUDIO);
}
// Get the default path
if( FAILED( pPerformance->GetDefaultAudioPath( &path ) ) )
return(SOUNDERROR_PATH);
// Set the default volume
if( FAILED( path->SetVolume(0,0) ) )
return(SOUNDERROR_VOLUME); return(S_OK);
}//-----------------------------------------------------------------------------
// Name: SoundSystem::hrLoadSound()
// Desc: Loads a sound and stores it in the GameSound passed
//-----------------------------------------------------------------------------
HRESULT SoundSystem::hrLoadSound(char *szname,GameSound *gs)
{
WCHAR szWideFileName[ 512 ]; // Make sure audio is initialized
if( !pLoader )
return(SOUNDERROR_MUSICLOADER); if( !pPerformance )
return(SOUNDERROR_MUSICPERFORMANCE); // Clean up sound if it already exists
if( gs->pSound ) {
gs->pSound->Unload( pPerformance );
gs->pSound->Release();
gs->pSound = NULL;
}
// Copy in the filename
DXUtil_ConvertGenericStringToWideCch( szWideFileName, szname, 512 ); // Load the sound from a file
if ( FAILED(pLoader->LoadObjectFromFile (
CLSID_DirectMusicSegment,
IID_IDirectMusicSegment8,
szWideFileName,
( LPVOID* ) &gs->pSound
) ) )
{
return( SOUNDERROR_LOAD );
}
gs->pPerformance = pPerformance; // Download the data
if ( FAILED ( gs->pSound->Download( pPerformance ) ) ) {
return(SOUNDERROR_DOWNLOAD);
}
return(S_OK);
}//-----------------------------------------------------------------------------
// Name: SoundSystem::hrPlaySound()
// Desc: Plays a GameSound segment object
//-----------------------------------------------------------------------------
HRESULT SoundSystem::hrPlaySound(GameSound *gs)
{
// Make sure there is a performance object present
if( !pPerformance )
return( SOUNDERROR_MUSICPERFORMANCE );
if( !gs->pSound )
return( SOUNDERROR_NOSEGMENT );
// Play the sound segment
if( FAILED ( pPerformance->PlaySegmentEx(
gs->pSound,
NULL,
NULL,
DMUS_SEGF_DEFAULT | DMUS_SEGF_SECONDARY,
0,
NULL,
NULL,
NULL
)))
return( SOUNDERROR_PLAYFAIL );
return(S_OK);
}