本文整理汇总了C++中DirectSoundCreate8函数的典型用法代码示例。如果您正苦于以下问题:C++ DirectSoundCreate8函数的具体用法?C++ DirectSoundCreate8怎么用?C++ DirectSoundCreate8使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DirectSoundCreate8函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DirectSoundCreate8
bool FVoiceCaptureDeviceWindows::Init()
{
HRESULT hr = DirectSoundCreate8(NULL, &DirectSound, NULL);
if (FAILED(hr))
{
UE_LOG(LogVoiceCapture, Warning, TEXT("Failed to init DirectSound %d"), hr);
return false;
}
bool bHmdAvailable = IModularFeatures::Get().IsModularFeatureAvailable(IHeadMountedDisplayModule::GetModularFeatureName());
HmdVoiceCaptureDeviceIndex = bHmdAvailable ? CVarHmdDirectSoundVoiceCaptureDeviceIndex.GetValueOnGameThread() : -1;
VoiceCaptureDeviceCount = 0;
VoiceCaptureDeviceGuid = DSDEVID_DefaultVoiceCapture;
hr = DirectSoundCaptureEnumerate((LPDSENUMCALLBACK)CaptureDeviceCallback, this);
if (FAILED(hr))
{
UE_LOG(LogVoiceCapture, Warning, TEXT("Failed to enumerate capture devices %d"), hr);
return false;
}
bool bDuckingOptOut = false;
if (GConfig)
{
if (!GConfig->GetBool(TEXT("Voice"), TEXT("bDuckingOptOut"), bDuckingOptOut, GEngineIni))
{
bDuckingOptOut = false;
}
}
FAudioDuckingWindows::UpdateAudioDucking(bDuckingOptOut);
bInitialized = true;
return true;
}
示例2: FONLINE_LOG
int SoundManager::Init()
{
if(active==true) return 1;
FONLINE_LOG("SoundManager Init\n");
if (!fm.Init(opt_masterpath.c_str(), opt_critterpath.c_str(), opt_fopath.c_str())) return 0;;
if(DirectSoundCreate8(0,&lpDS,0)!=DS_OK)
{
FONLINE_LOG("Неудалось создать устройство!\n");
return 0;
}
if(lpDS->SetCooperativeLevel(GetForegroundWindow(),DSSCL_NORMAL)!=DS_OK)
{
FONLINE_LOG("Неудалось установить уровень кооперации!\n");
return 0;
}
cur_snd=1;
active=true;
FONLINE_LOG("SoundManager Init OK\n");
return 1;
}
示例3: InitDirectSound
///////////////////////////////////////////////////////////////////////////////
// Function : "InitDirectSound"
//
// Last Modified : 4/05/2004
//
// Input : hWnd - Main Window Handle.
// nPrimaryBufferFormat - PB_LOQUAL for Normal, 11khz (default)
// PB_MEDQUAL for 22khz
// PB_HIQUAL for 44khz
//
// Return : true, if successful.
//
// Purpose : Initialize DirectSound and create a Primar Buffer, if needed.
///////////////////////////////////////////////////////////////////////////////
bool CSGD_DirectSound::InitDirectSound(HWND hWnd, int nPrimaryBufferFormat)
{
// Make sure hWnd is valid.
if (!hWnd) return false;
// Store the Main Window Handle.
m_hWnd = hWnd;
// Create the main DirectSound Object.
if (FAILED(DirectSoundCreate8(NULL, &m_dsObject, NULL)))
DSERRBOX("Failed to Create DirectSound Object");
// Set the Cooperative Level for DirectSound.
if (nPrimaryBufferFormat != PB_MEDQUAL && nPrimaryBufferFormat != PB_HIQUAL)
{
// The Default cooperative level.
if (FAILED(m_dsObject->SetCooperativeLevel(m_hWnd, DSSCL_NORMAL)))
DSERRBOX("Failed to SetCooperativeLevel - NORMAL");
}
else
{
// Attempt to set the primary buffer format
// we're doing this because DirectSound likes to convert our samples to its
// default low qual format, causing lots of white noise on our samples
if (FAILED(m_dsObject->SetCooperativeLevel(m_hWnd, DSSCL_PRIORITY)))
DSERRBOX("Failed to SetCooperativeLevel - PRIORITY");
// Make a wave format structure for our primary sound buffer.
static WAVEFORMATEX waveFormatEx;
memset(&waveFormatEx, 0, sizeof(waveFormatEx));
waveFormatEx.wFormatTag = WAVE_FORMAT_PCM;
waveFormatEx.nChannels = 2;
// Give us 22050 or 44100
(nPrimaryBufferFormat == PB_MEDQUAL) ? waveFormatEx.nSamplesPerSec = 22050 : waveFormatEx.nSamplesPerSec = 44100;
waveFormatEx.nBlockAlign = 4;
waveFormatEx.nAvgBytesPerSec = waveFormatEx.nSamplesPerSec * waveFormatEx.nBlockAlign;
waveFormatEx.wBitsPerSample = 16;
// Setup the DSBUFFERDESC struct.
DSBUFFERDESC dsbd;
memset(&dsbd, 0, sizeof(dsbd));
dsbd.dwSize = sizeof(dsbd);
// Will be making a Primary Buffer.
dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;
dsbd.dwBufferBytes = 0;
dsbd.lpwfxFormat = NULL; // Must be NULL for primary buffers.
// Make the primary sound buffer
if (FAILED(m_dsObject->CreateSoundBuffer(&dsbd, &m_dsPrimaryBuffer, NULL)))
DSERRBOX("Couldn't Create the Primary Sound Buffer");
// Set the desired format for the buffer.
if (FAILED(m_dsPrimaryBuffer->SetFormat(&waveFormatEx)))
DSERRBOX("Couldn't Set the Primary Sound Buffer Format");
}
// Return success.
return true;
}
示例4: getCurrentChannelConfig
BOOL getCurrentChannelConfig()
{
IDirectSound8* ds;
DWORD speakerConfig;
LPGUID guid = NULL;
DirectSoundEnumerate((LPDSENUMCALLBACK)DSEnumProc, (VOID*)&guid);
if (DirectSoundCreate8(guid, &ds, NULL) != S_OK) {
return FALSE;
}
ds->Initialize(NULL);
if (ds->GetSpeakerConfig(&speakerConfig) != S_OK) {
PrintLastError("GetSpeakerConfig()");
return FALSE;
}
if (ds) {
ds->Release();
}
if (guid) {
LocalFree(guid);
}
switch (DSSPEAKER_CONFIG(speakerConfig)) {
case DSSPEAKER_STEREO: currentChannelCount = 2; return TRUE;
case DSSPEAKER_QUAD: currentChannelCount = 4; return TRUE;
case DSSPEAKER_5POINT1: currentChannelCount = 6; return TRUE;
case DSSPEAKER_7POINT1: currentChannelCount = 8; return TRUE;
}
return FALSE;
}
示例5: iniDirectSound
bool cSound::iniDirectSound(HWND hWnd)
{
for (int i = 0; i < 500; i++)
stopped[i] = false;
HRESULT result;
DSBUFFERDESC bufferDesc;
WAVEFORMATEX wavFormat;
result=DirectSoundCreate8(NULL, &intSound, NULL);
if (FAILED(result))return false;
result=intSound->SetCooperativeLevel(hWnd, DSSCL_PRIORITY);
if (FAILED(result))return false;
bufferDesc.dwSize = sizeof(DSBUFFERDESC);
bufferDesc.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRLVOLUME; //For primary
bufferDesc.dwBufferBytes = 0; //For primary 0
bufferDesc.dwReserved = 0;//For primary 0
bufferDesc.lpwfxFormat = NULL;//For Primary NULL
bufferDesc.guid3DAlgorithm = GUID_NULL;//For Primary without 3d functions
result=intSound->CreateSoundBuffer(&bufferDesc, &primaryBuffer, NULL);
if (FAILED(result))return false;
wavFormat.wFormatTag = WAVE_FORMAT_PCM;
wavFormat.nSamplesPerSec = 44100;
wavFormat.wBitsPerSample = 16;
wavFormat.nChannels = 2;
wavFormat.nBlockAlign = (wavFormat.wBitsPerSample/8)*wavFormat.nChannels;
wavFormat.nAvgBytesPerSec = wavFormat.nSamplesPerSec*wavFormat.nBlockAlign;
wavFormat.cbSize = 0;
result=primaryBuffer->SetFormat(&wavFormat);
if (FAILED(result))return false;
return true;
}
示例6: ZeroMemory
ClSoundDS::ClSoundDS(HWND hWnd,ClReadFile *readFile,BOOL b3DSound)
{
HRESULT hr;
DSBUFFERDESC dsbdDesc;
WAVEFORMATEX wfx;
ZeroMemory(this,sizeof(ClSoundDS));
lpReadFile = readFile;
hr = DirectSoundCreate8(NULL,&lpDSound,NULL);
if(hr!=DS_OK)return;
hr = lpDSound->SetCooperativeLevel(hWnd, DSSCL_EXCLUSIVE);
if(hr!=DS_OK)return;
ZeroMemory(&dsbdDesc,sizeof(DSBUFFERDESC));
dsbdDesc.dwSize = sizeof(DSBUFFERDESC);
dsbdDesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
dsbdDesc.dwFlags |= DSBCAPS_LOCSOFTWARE;
if(b3DSound) dsbdDesc.dwFlags |= DSBCAPS_CTRL3D;
dsbdDesc.lpwfxFormat = NULL;
hr = lpDSound->CreateSoundBuffer(&dsbdDesc, &lpPrimaryBuffer, NULL);
if(DS_OK!=hr) return;
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = 2;
wfx.nSamplesPerSec = 44100;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = wfx.nChannels * (wfx.wBitsPerSample/8);
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
wfx.cbSize = 0;
lpPrimaryBuffer->SetFormat(&wfx);
lpDSound->SetCooperativeLevel(hWnd,DSSCL_NORMAL);
CreateDummyBuffer();
Enable = TRUE;
} // ClSoundDS::ClSoundDS
示例7: SAFE_RELEASE
//-----------------------------------------------------------------------------
// Name: CSoundManager::Initialize()
// Desc: Initializes the IDirectSound object and also sets the primary buffer
// format. This function must be called before any others.
//-----------------------------------------------------------------------------
HRESULT CSoundManager::Initialize( HWND hWnd,
DWORD dwCoopLevel,
DWORD dwPrimaryChannels,
DWORD dwPrimaryFreq,
DWORD dwPrimaryBitRate )
{
HRESULT hr;
SAFE_RELEASE( m_pDS );
// Create IDirectSound using the primary sound device
if( FAILED( hr = DirectSoundCreate8( NULL, &m_pDS, NULL ) ) )
return DXTRACE_ERR( TEXT("DirectSoundCreate8"), hr );
// Set DirectSound coop level
if( FAILED( hr = m_pDS->SetCooperativeLevel( hWnd, dwCoopLevel ) ) )
return DXTRACE_ERR( TEXT("SetCooperativeLevel"), hr );
// Set primary buffer format
if( FAILED( hr = SetPrimaryBufferFormat( dwPrimaryChannels, dwPrimaryFreq, dwPrimaryBitRate ) ) )
return DXTRACE_ERR( TEXT("SetPrimaryBufferFormat"), hr );
m_dwPrimaryChannels = dwPrimaryChannels;
m_dwPrimaryFreq = dwPrimaryFreq;
m_dwPrimaryBitRate = dwPrimaryBitRate;
return S_OK;
}
示例8: Init
sBool Init(sInt rate, sInt channels)
{
#ifndef KSDATAFORMAT_SUBTYPE_PCM
const static GUID KSDATAFORMAT_SUBTYPE_PCM = {0x00000001,0x0000,0x0010,{0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71}};
#endif
if FAILED(DirectSoundCreate8(0,&DS,0))
return sFALSE;
if FAILED(DS->SetCooperativeLevel(sHWND,DSSCL_PRIORITY))
return sFALSE;
// this is our output format.
WAVEFORMATPCMEX wf;
wf.Format.cbSize=22;
wf.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
wf.Format.nChannels=channels;
wf.Format.wBitsPerSample=16;
wf.Format.nSamplesPerSec=rate;
wf.Format.nBlockAlign=channels*((wf.Format.wBitsPerSample+7)/8);
wf.Format.nAvgBytesPerSec=wf.Format.nBlockAlign*rate;
wf.dwChannelMask=(1<<channels)-1; // very space opera
wf.Samples.wValidBitsPerSample=16;
wf.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
// set up some stuff while we're at it
BufferSize = sAlign(rate*LATENCY_MS/1000,16);
BytesPerSample= wf.Format.nBlockAlign;
RenderBuffer = new sF32[channels*BufferSize];
LastPlayPos=0;
Channels=channels;
Rate=rate;
// create primary buffer...
DSBUFFERDESC dsbd;
sSetMem(&dsbd,0,sizeof(dsbd));
dsbd.dwSize = sizeof(dsbd);
dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;
dsbd.dwBufferBytes = 0;
dsbd.lpwfxFormat = 0;
if FAILED(DS->CreateSoundBuffer(&dsbd,&PrimBuffer,0))
return sFALSE;
// set primary buffer format to prepare DirectSound for what's coming (may fail)
PrimBuffer->SetFormat((WAVEFORMATEX*)&wf);
// create secondary buffer
sSetMem(&dsbd,0,sizeof(dsbd));
dsbd.dwSize = sizeof(dsbd);
dsbd.dwFlags = DSBCAPS_GLOBALFOCUS|DSBCAPS_STICKYFOCUS|DSBCAPS_GETCURRENTPOSITION2;
dsbd.dwBufferBytes = BufferSize*BytesPerSample;
dsbd.lpwfxFormat = (WAVEFORMATEX*)&wf;
if FAILED(DS->CreateSoundBuffer(&dsbd,&Buffer,0))
return sFALSE;
// now that everything seemed to work, let's switch over to the rendering thread
Renderers.HintSize(8);
Thread = new sThread(ThreadProxy,1,0,this);
return sTRUE;
}
示例9: create
bool GlobalSoundManager::create(HWND hMainWindow) {
if (APP_ERROR(FAILED(DirectSoundCreate8(NULL, &direct_sound_, NULL)) ||
FAILED(direct_sound_->SetCooperativeLevel(hMainWindow, DSSCL_NORMAL)))
("Couldn't initialize DirectSound"))
return false;
return true;
}
示例10: return
// ////////////////////////////////////////////////////////////////////
//
// ////////////////////////////////////////////////////////////////////
bool DirectSound8Audio::VInitialize()
{
if(Audio::IsInitialized()) {
return (true);
}
Audio::SetInitialized(false);
Release(m_pDS);
HRESULT hr;
// Create IDirectSound using the primary sound device
if(FAILED(hr = DirectSoundCreate8(NULL, &m_pDS, NULL))) {
GF_LOG_TRACE_ERR("DirectSound8Audio::VInitialize()", "Failed to initialized the DirectSound interface");
return (false);
}
if(FAILED(hr = m_pDS->SetCooperativeLevel(m_hWnd, DSSCL_PRIORITY))) {
GF_LOG_TRACE_ERR("DirectSound8Audio::VInitialize()", "Failed to set the coop level of the DirectSound interface");
return (false);
}
if(FAILED(hr = SetPrimaryBufferFormat(8, 44100, 16))) {
GF_LOG_TRACE_ERR("DirectSound8Audio::VInitialize()", "Failed to set the primary buffer format of the DirectSound interface");
return (false);
}
Audio::SetInitialized(true);
m_AllSamples.clear();
return (true);
}
示例11: CBaseRenderer
CMpcAudioRenderer::CMpcAudioRenderer(LPUNKNOWN punk, HRESULT *phr)
: CBaseRenderer(__uuidof(this), NAME("MPC - Audio Renderer"), punk, phr)
, m_pDSBuffer (NULL )
, m_pSoundTouch (NULL )
, m_pDS (NULL )
, m_dwDSWriteOff (0 )
, m_nDSBufSize (0 )
, m_dRate (1.0 )
, m_pReferenceClock (NULL )
, m_pWaveFileFormat (NULL )
, pAudioClient (NULL )
, pRenderClient (NULL )
, useWASAPI (true )
, bufferFrameCount (0 )
, hnsRequestedDuration (0 )
, hTask (NULL )
{
if (useWASAPI)
*phr = GetDefaultAudioDevice(&pAudioClient);
else
{
m_pSoundTouch = new soundtouch::SoundTouch();
*phr = DirectSoundCreate8 (NULL, &m_pDS, NULL);
}
}
示例12: DirectSoundCreate8
HRESULT FrkSound::InitializeSoundClass(HWND windowsHandler)
{
m_hWindowsHandler = windowsHandler;
HRESULT result;
// Thu tao thiet bi DS
result = DirectSoundCreate8(0, &m_hAudioHandler, 0);
result = result | m_hAudioHandler->SetCooperativeLevel(m_hWindowsHandler, DSSCL_PRIORITY);
ZeroMemory(&m_hBufferFormat, sizeof(WAVEFORMATEX));
ZeroMemory(&m_hBufferDescription, sizeof(DSBUFFERDESC));
m_hBufferFormat.wFormatTag = AUDIO_FORMAT_TAG;
m_hBufferFormat.nChannels = AUDIO_NUM_OF_CHANNEL;
m_hBufferFormat.nSamplesPerSec = AUDIO_SAMPLE_SPEED;
m_hBufferFormat.wBitsPerSample = AUDIO_BITS_PER_SAMPLE;
m_hBufferFormat.nBlockAlign = AUDIO_BLOCK_ALIGN(m_hBufferFormat.wBitsPerSample,
m_hBufferFormat.nChannels);
m_hBufferFormat.nAvgBytesPerSec = AUDIO_AVERAGE_BPS(m_hBufferFormat.nSamplesPerSec,
m_hBufferFormat.nBlockAlign);
m_hBufferDescription.dwFlags = AUDIO_FLAGS;
m_hBufferDescription.guid3DAlgorithm = AUDIO_GUID;
m_hBufferDescription.dwSize = sizeof(DSBUFFERDESC);
return result;
}
示例13: DirectSoundCreate8
bool WindowsSound::Init()
{
HRESULT hr;
//create the sound device
hr = DirectSoundCreate8(NULL, &(this->directSoundDevice), NULL);
if(FAILED(hr))
return false;
//set cooperative level to PRIORITY (=high)
HWND hwndC = GetConsoleWindow() ;
hr = this->directSoundDevice->SetCooperativeLevel(hwndC, DSSCL_PRIORITY);
if(FAILED(hr))
return false;
//create an output wave format
WAVEFORMATEX waveFormat;
memset(&waveFormat, 0, sizeof(WAVEFORMATEX));
waveFormat.wFormatTag = WAVE_FORMAT_PCM;
waveFormat.nChannels = CHANNELS_NUMBER;
waveFormat.nSamplesPerSec = SAMPLE_RATE;
waveFormat.wBitsPerSample = BITS_PER_SAMPLE;
waveFormat.nBlockAlign = BLOCK_ALIGN;
waveFormat.nAvgBytesPerSec = AVERAGE_BYTES_PER_SECOND; //msdn recommendation for PCM format
//Primary sound buffer
DSBUFFERDESC bufferDesc;
memset(&bufferDesc, 0, sizeof(DSBUFFERDESC));
bufferDesc.dwSize = sizeof(DSBUFFERDESC);
bufferDesc.dwFlags = DSBCAPS_PRIMARYBUFFER|DSBCAPS_STICKYFOCUS;
bufferDesc.dwBufferBytes = 0;
bufferDesc.lpwfxFormat = NULL;
LPDIRECTSOUNDBUFFER primaryDirectSoundBuffer;
hr = this->directSoundDevice->CreateSoundBuffer(&bufferDesc, &primaryDirectSoundBuffer, NULL);
if(FAILED(hr))
return false;
hr = primaryDirectSoundBuffer->SetFormat(&waveFormat);
if(FAILED(hr))
return false;
//set up a buffer description
DSBUFFERDESC soundBufferDescription;
memset(&soundBufferDescription, 0, sizeof(DSBUFFERDESC));
soundBufferDescription.dwSize = sizeof(DSBUFFERDESC);
//DSBCAPS_STICKYFOCUS: allows to play sound even if we don't have have focus.
//DSBCAPS_GETCURRENTPOSITION2: tells DirectSound we'll use the GetPosition method later on that sound buffer.
soundBufferDescription.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_STICKYFOCUS;
soundBufferDescription.dwBufferBytes = BUFFER_LENGTH_IN_BYTES;
soundBufferDescription.lpwfxFormat = &waveFormat;
//create the sound buffer
hr = this->directSoundDevice->CreateSoundBuffer(&soundBufferDescription, &(this->directSoundBuffer), NULL);
if(FAILED(hr))
return false;
return true;
}
示例14: Dsoundinit
bool Dsoundinit( HWND hwnd )
{
// SBArrの初期化
initSBArr();
// DirectSound8 の作成
if (FAILED(DirectSoundCreate8(NULL,&lpDS,NULL)))
{
MessageBox(NULL,"DirectSound オブジェクトの作成に失敗しました。","DirectSoundエラー",MB_OK | MB_ICONSTOP);
return false;
}
// DirectSound の協調レベルを設定
if (FAILED(lpDS->SetCooperativeLevel(hwnd,DSSCL_PRIORITY)))
{
MessageBox(NULL,"DirectSound の協調レベルの設定に失敗しました。","DirectSoundエラー",MB_OK | MB_ICONSTOP);
// 閉じる
SendMessage(hwnd,WM_CLOSE,0,0);
return false;
}
// プライマリ サウンドバッファ作成
DSBUFFERDESC desc;
ZeroMemory(&desc,sizeof(DSBUFFERDESC));
desc.dwSize = sizeof(DSBUFFERDESC);
desc.dwFlags = DSBCAPS_PRIMARYBUFFER;
if (FAILED(lpDS->CreateSoundBuffer(&desc,&lpDSP,NULL)))
{
MessageBox(NULL,"プライマリサウンドバッファの作成に失敗しました。","DirectSoundエラー",MB_OK | MB_ICONSTOP);
// 閉じる
SendMessage(hwnd,WM_CLOSE,0,0);
return false;
}
//ここまでは一回行えばOKの処理
//SEの数だけセカンダリバッファにデータ読み込み
//読み込みファイル名をリストから読み込む
initSBFileList();
int nCount;
for(nCount = 0;nCount <= SE_MAX - 1;nCount++){
// WAVE ファイルの読み込み
// MessageBox(NULL,SBArr[nCount].cSeFileName,"",MB_OK);
SBArr[nCount].SB_lpDSB = LoadWave(SBArr[nCount].cSeFileName); //効果音
if (SBArr[nCount].SB_lpDSB == NULL)
{
MessageBox(NULL,"ファイルの読み込みに失敗しました。","DirectSoundエラー",MB_OK | MB_ICONSTOP);
// 閉じる
SendMessage(hwnd,WM_CLOSE,0,0);
return false;
}
}
return true;
}
示例15: WriteTrace
bool DirectSoundDriver::Initialize()
{
WriteTrace(TraceAudioDriver, TraceDebug, "Start");
if (!SoundDriverBase::Initialize())
{
WriteTrace(TraceAudioDriver, TraceDebug, "Done (res: false)");
return false;
}
CGuard guard(m_CS);
LPDIRECTSOUND8 & lpds = (LPDIRECTSOUND8 &)m_lpds;
HRESULT hr = DirectSoundCreate8(NULL, &lpds, NULL);
if (FAILED(hr))
{
WriteTrace(TraceAudioDriver, TraceWarning, "Unable to DirectSoundCreate (hr: 0x%08X)", hr);
WriteTrace(TraceAudioDriver, TraceDebug, "Done (res: false)");
return false;
}
hr = lpds->SetCooperativeLevel((HWND)g_AudioInfo.hwnd, DSSCL_PRIORITY);
if (FAILED(hr))
{
WriteTrace(TraceAudioDriver, TraceWarning, "Failed to SetCooperativeLevel (hr: 0x%08X)", hr);
WriteTrace(TraceAudioDriver, TraceDebug, "Done (res: false)");
return false;
}
LPDIRECTSOUNDBUFFER & lpdsbuf = (LPDIRECTSOUNDBUFFER &)m_lpdsbuf;
if (lpdsbuf)
{
IDirectSoundBuffer_Release(lpdsbuf);
lpdsbuf = NULL;
}
DSBUFFERDESC dsPrimaryBuff = { 0 };
dsPrimaryBuff.dwSize = sizeof(DSBUFFERDESC);
dsPrimaryBuff.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRLVOLUME;
dsPrimaryBuff.dwBufferBytes = 0;
dsPrimaryBuff.lpwfxFormat = NULL;
WAVEFORMATEX wfm = { 0 };
wfm.wFormatTag = WAVE_FORMAT_PCM;
wfm.nChannels = 2;
wfm.nSamplesPerSec = 48000;
wfm.wBitsPerSample = 16;
wfm.nBlockAlign = wfm.wBitsPerSample / 8 * wfm.nChannels;
wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign;
LPDIRECTSOUNDBUFFER & lpdsb = (LPDIRECTSOUNDBUFFER &)m_lpdsb;
hr = lpds->CreateSoundBuffer(&dsPrimaryBuff, &lpdsb, NULL);
if (SUCCEEDED(hr))
{
lpdsb->SetFormat(&wfm);
lpdsb->Play(0, 0, DSBPLAY_LOOPING);
}
WriteTrace(TraceAudioDriver, TraceDebug, "Done (res: true)");
return true;
}