扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:李强 来源:天极开发 2007年10月16日
关键字:
LPDIRECTSOUND8 g_pDS = NULL; LPDIRECTSOUNDBUFFER g_pDsbuffer[3] = NULL; CWaveFile* g_pWaveFile;// WAVEFORMATEX g_wfxInput; //输入的音频格式 |
BOOL InitDirectSound() { if ( FAILED( hr = DirectSoundCreate(NULL, & g_pDS, NULL ) ) ) return FALSE; // Set cooperative level. if ( FAILED( hr = g_pDS ->SetCooperativeLevel( hwnd, DSSCL_PRIORITY ) ) ) return FALSE; return TRUE; } |
LPDIRECTSOUNDBUFFER LoadWaveFile(LPSTR lpzFileName) { DSBUFFERDESC dsbdesc; HRESULT hr; BYTE *pBuffer; DWORD dwSizeRead; LPDIRECTSOUNDBUFFER lpdsbStatic=NULL; if( FAILED( hr = g_pWaveFile->Open( lpzFileName, &g_wfxInput, WAVEFILE_WRITE ) ) ) { return NULL; } DWORD dwSize = g_pWaveFile->GetSize(); pBuffer = new BYTE[dwSize]; g_pWaveFile->Read(pBuffer,dwSize,&dwSizeRead); if(dwSizeRead > 0) { memset(dsbdesc,0,sizeof(DSBUFFERDESC)); dsbdesc.dwSize = sizeof(DSBUFFERDESC); dsbdesc.dwFlags =DSBCAPS_STATIC; dsbdesc.dwBufferBytes =dwSizeRead; dsbdesc.lpwfxFormat = g_wfxInput; if ( FAILED( g_pDS->CreateSoundBuffer(&dsbdesc, & lpdsbStatic, NULL ) ) ) { g_pWaveFile->Close(); delete pBuffer; return NULL } LPVOID lpvWrite; DWORD dwLength; if (DS_OK == lpdsbStatic ->Lock( 0, // Offset at which to start lock. 0, // Size of lock; ignored because of flag. &lpvWrite, // Gets address of first part of lock. &dwLength, // Gets size of first part of lock. NULL, // Address of wraparound not needed. NULL, // Size of wraparound not needed. DSBLOCK_ENTIREBUFFER)) // Flag. { memcpy(lpvWrite, pBuffer, dwLength); lpdsbStatic ->Unlock( lpvWrite, // Address of lock start. dwLength, // Size of lock. NULL, // No wraparound portion. 0); // No wraparound size. } } delete pBuffer; return lpdsbStatic; } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者