本文整理汇总了C++中LPDIRECTSOUND8::DuplicateSoundBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTSOUND8::DuplicateSoundBuffer方法的具体用法?C++ LPDIRECTSOUND8::DuplicateSoundBuffer怎么用?C++ LPDIRECTSOUND8::DuplicateSoundBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTSOUND8
的用法示例。
在下文中一共展示了LPDIRECTSOUND8::DuplicateSoundBuffer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Create
// Create
// create 'empty' sound buffer into the memory
HRESULT CSoundWave::Create( CSoundEngine& soundEngine,
DWORD dwFrequency,
DWORD dwBitsPerSample,
DWORD dwChannels,
DWORD dwBytes,
DWORD dwDuplicates,
DWORD dwFlags)
{
// set original freq
m_OriginalFrequency = dwFrequency;
HRESULT hres;
WAVEFORMATEX wfx;
DSBUFFERDESC desc;
// init the wave format
::memset(&wfx, 0, sizeof(WAVEFORMATEX));
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = (WORD)dwChannels;
wfx.nSamplesPerSec = dwFrequency;
wfx.wBitsPerSample = (WORD)dwBitsPerSample;
wfx.nBlockAlign = wfx.wBitsPerSample / 8 * wfx.nChannels;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
// init the buffer desc
::memset(&desc, 0, sizeof(DSBUFFERDESC));
desc.dwSize = sizeof(DSBUFFERDESC);
desc.dwFlags = dwFlags;
desc.dwBufferBytes = dwBytes;
desc.lpwfxFormat = &wfx;
// create sound buffer(s)...
LPDIRECTSOUND8 pDS = soundEngine.GetDirectSound();
m_ppDSB = new LPDIRECTSOUNDBUFFER8[dwDuplicates + 1];
if (!m_ppDSB)
{
return E_OUTOFMEMORY;
}
// set pointers in array to NULL
::memset(m_ppDSB, 0, sizeof(LPDIRECTSOUNDBUFFER8) * (dwDuplicates + 1));
m_dwBufferCount = dwDuplicates + 1;
// create the first sound buffer
// first sound buffer is special one,
// it is the only one that actually contains
// any sound data. The duplicate buffers have only
// separate play positions, pointing into the data
// in first buffer
LPDIRECTSOUNDBUFFER pDSB = NULL;
hres = pDS->CreateSoundBuffer(&desc, &pDSB, NULL);
if (FAILED(hres))
{
Release();
return hres;
}
// query the latest sound buffer interface
hres = pDSB->QueryInterface( IID_IDirectSoundBuffer8,
(void**)&m_ppDSB[0]);
pDSB->Release();
if (FAILED(hres))
{
Release();
return hres;
}
// create the duplicates
DWORD i;
for (i=0; i<dwDuplicates; i++)
{
if ((dwFlags & DSBCAPS_CTRLFX))
{
// real time effects required, all duplicate buffers
// must have their own wave data
hres = pDS->CreateSoundBuffer(&desc, &pDSB, NULL);
}
else
{
// no real time effect required, use duplicate buffers
// to save memory
hres = pDS->DuplicateSoundBuffer(m_ppDSB[0], &pDSB);
}
if (SUCCEEDED(hres))
{
hres = pDSB->QueryInterface( IID_IDirectSoundBuffer8,
(void**)&m_ppDSB[i + 1]);
pDSB->Release();
if (FAILED(hres))
{
Release();
return hres;
}
}
else
//.........这里部分代码省略.........