本文整理汇总了C++中LPDIRECTSOUNDBUFFER类的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTSOUNDBUFFER类的具体用法?C++ LPDIRECTSOUNDBUFFER怎么用?C++ LPDIRECTSOUNDBUFFER使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LPDIRECTSOUNDBUFFER类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateDSBuffer
HRESULT CMpcAudioRenderer::CreateDSBuffer()
{
if (! m_pWaveFileFormat) {
return E_POINTER;
}
HRESULT hr = S_OK;
LPDIRECTSOUNDBUFFER pDSBPrimary = NULL;
DSBUFFERDESC dsbd;
DSBUFFERDESC cDSBufferDesc;
DSBCAPS bufferCaps;
DWORD dwDSBufSize = m_pWaveFileFormat->nAvgBytesPerSec * 4;
ZeroMemory(&bufferCaps, sizeof(bufferCaps));
ZeroMemory(&dsbd, sizeof(DSBUFFERDESC));
dsbd.dwSize = sizeof(DSBUFFERDESC);
dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;
dsbd.dwBufferBytes = 0;
dsbd.lpwfxFormat = NULL;
if (SUCCEEDED(hr = m_pDS->CreateSoundBuffer(&dsbd, &pDSBPrimary, NULL))) {
hr = pDSBPrimary->SetFormat(m_pWaveFileFormat);
_ASSERTE(SUCCEEDED(hr));
SAFE_RELEASE(pDSBPrimary);
}
SAFE_RELEASE(m_pDSBuffer);
cDSBufferDesc.dwSize = sizeof(DSBUFFERDESC);
cDSBufferDesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2 |
DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN | DSBCAPS_CTRLFREQUENCY;
cDSBufferDesc.dwBufferBytes = dwDSBufSize;
cDSBufferDesc.dwReserved = 0;
cDSBufferDesc.lpwfxFormat = m_pWaveFileFormat;
cDSBufferDesc.guid3DAlgorithm = GUID_NULL;
hr = m_pDS->CreateSoundBuffer(&cDSBufferDesc, &m_pDSBuffer, NULL);
m_nDSBufSize = 0;
if (SUCCEEDED(hr)) {
bufferCaps.dwSize = sizeof(bufferCaps);
hr = m_pDSBuffer->GetCaps(&bufferCaps);
}
if (SUCCEEDED(hr)) {
m_nDSBufSize = bufferCaps.dwBufferBytes;
hr = ClearBuffer();
m_pDSBuffer->SetFrequency((long)(m_pWaveFileFormat->nSamplesPerSec * m_dRate));
}
return hr;
}
示例2: StreamPoll
/*------------------------------------------------------------------------
*
* PROTOTYPE : int StreamPoll(void)
*
* DESCRIPTION : Poller to the stream. If return -1, StreamLoad must be called.
*
*/
int StreamPoll(V3XA_STREAM handle)
{
DS_stream *pHandle = g_pDSStreams + handle;
DWORD lPlay=0;
DWORD lWrite=0;
int ret=-1;
LPDIRECTSOUNDBUFFER pDS = g_pDSHandles[pHandle->channel].pbuffer;
if (!pDS)
return ret;
if ((pHandle->nState&1)==0)
return -1;
if (pHandle->m_nStreamState)
{
ret = 1;
}
else
{
// Polled streaming
int32_t elapsed;
ULONG lpStatus;
if (pDS->GetStatus(&lpStatus)==DS_OK)
{
if ((lpStatus & DSBSTATUS_PLAYING)==0)
{
SYS_DXTRACE(pDS->Play(0, 0, DSBPLAY_LOOPING));
}
}
SYS_DXTRACE(pDS->GetCurrentPosition(&lWrite, &lPlay));
elapsed = (pHandle->m_nPreviousPosition<=(int32_t)lPlay)
? lPlay - pHandle->m_nPreviousPosition
: (lPlay + (int32_t)pHandle->sample.length) - pHandle->m_nPreviousPosition;
pHandle->m_nWriteBytes+=elapsed;
pHandle->m_nTotalBytes+=elapsed;
pHandle->m_nPreviousPosition = lPlay;
if ((pHandle->m_nWriteBytes+elapsed>=pHandle->m_nUploadedBytes)
&&(pHandle->m_nUploadedBytes))
{
pHandle->m_nWriteBytes-=pHandle->m_nUploadedBytes;
pHandle->m_nUploadedBytes = 0;
ret = 1;
}
}
return ret;
}
示例3: pcmdestroy
static void pcmdestroy(void) {
UINT i;
LPDIRECTSOUNDBUFFER dsbuf;
for (i=0; i<SOUND_MAXPCM; i++) {
dsbuf = pDSwave3[i];
pDSwave3[i] = NULL;
if (dsbuf) {
dsbuf->Stop();
dsbuf->Release();
}
}
}
示例4: get3DListener
//获得3D收听对象
HRESULT get3DListener(LPDIRECTSOUND8 lpds, LPDIRECTSOUND3DBUFFER8* ppListener){
DSBUFFERDESC dsbd;
LPDIRECTSOUNDBUFFER lpdsbPrimary;
LPDIRECTSOUND3DLISTENER lp3DListener = NULL;
HRESULT hr;
ZeroMemory(&dsbd, sizeof(DSBUFFERDESC));
dsbd.dwSize = sizeof(DSBUFFERDESC);
dsbd.dwFlags = DSBCAPS_CTRL3D | DSBCAPS_PRIMARYBUFFER;
if (SUCCEEDED(hr = lpds->CreateSoundBuffer(&dsbd, &lpdsbPrimary, NULL))){
hr = lpdsbPrimary->QueryInterface(IID_IDirectSound3DListener8, (LPVOID*)ppListener);
lpdsbPrimary->Release();
}
return hr;
}
示例5: soundmng_pcmplay
BRESULT soundmng_pcmplay(UINT num, BOOL loop) {
LPDIRECTSOUNDBUFFER dsbuf;
if ((!mute) && (num < SOUND_MAXPCM)) {
dsbuf = pDSwave3[num];
if (dsbuf) {
// dsbuf->SetCurrentPosition(0);
dsbuf->Play(0, 0, (loop)?DSBPLAY_LOOPING:0);
return(SUCCESS);
}
}
return(FAILURE);
}
示例6: return
// ////////////////////////////////////////////////////////////////////
//
// ////////////////////////////////////////////////////////////////////
F32 DirectSound8AudioBuffer::VGetProgress()
{
LPDIRECTSOUNDBUFFER pDSB = static_cast<LPDIRECTSOUNDBUFFER>(VGet());
if(!pDSB) {
GF_LOG_TRACE_ERR("DirectSound8AudioBuffer::VGetProgress()", "Failed to cast the buffer to a DirectSound buffer");
return (false);
}
DWORD progress = 0;
pDSB->GetCurrentPosition(&progress, NULL);
F32 length = static_cast<F32>(m_Resource->GetPCMBufferSize());
return (static_cast<F32>(progress) / length);
}
示例7: DXTRACE_ERR
/*
===============
idAudioBufferWIN32::RestoreBuffer
Desc: Restores the lost buffer. *pbWasRestored returns true if the buffer was
restored. It can also NULL if the information is not needed.
===============
*/
int idAudioBufferWIN32::RestoreBuffer( LPDIRECTSOUNDBUFFER pDSB, bool* pbWasRestored )
{
int hr;
if( pDSB == NULL )
{
return -1;
}
if( pbWasRestored )
{
*pbWasRestored = false;
}
ulong dwStatus;
if( FAILED( hr = pDSB->GetStatus( &dwStatus ) ) )
{
return DXTRACE_ERR( TEXT("GetStatus"), hr );
}
if( dwStatus & DSBSTATUS_BUFFERLOST )
{
// Since the app could have just been activated, then
// DirectSound may not be giving us control yet, so
// the restoring the buffer may fail.
// If it does, sleep until DirectSound gives us control.
do
{
hr = pDSB->Restore();
if( hr == DSERR_BUFFERLOST )
{
Sleep( 10 );
}
hr = pDSB->Restore();
}
while( hr );
if( pbWasRestored != NULL )
{
*pbWasRestored = true;
}
return S_OK;
}
else
{
return S_FALSE;
}
}
示例8: Initialize
//--------------------------------------------------------------------
//Function: Initialize
//Parameters: lpDSB - DirectSoundBuffer
// bLoadDefaultParamValues - Load default parameters or not
//Description: Associates a DirectSoundBuffer with the manager
// Any effects enabled in the old DirectSoundBuffer will
// Be disabled and the effect objects released
//--------------------------------------------------------------------
HRESULT CSoundFXManager::Initialize(LPDIRECTSOUNDBUFFER lpDSB, BOOL bLoadDefaultParamValues)
{
HRESULT hr;
if(m_lpDSB8)
{
// Release the effect for the previously associated sound buffers
DisableAllFX();
SAFE_RELEASE(m_lpDSB8);
}
if(NULL == lpDSB)
{
return S_OK;
}
// Get the interface
if(FAILED(hr = lpDSB->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*) &m_lpDSB8)))
{
return hr;
}
if(bLoadDefaultParamValues)
{
LoadDefaultParamValues();
}
return S_OK;
}
示例9: VStop
// *******************************************************************************************************************
bool cDirectSoundAudioBuffer::VPlay()
{
VStop();
LPDIRECTSOUNDBUFFER pDSBuffer = GetSoundBuffer();
if (pDSBuffer == NULL)
{
return false;
}
if (S_OK == pDSBuffer->Play(0, 0, 0))
{
m_Paused = false;
}
return m_Paused;
}
示例10: get_buffer_caps
/**
* @brief Helper routine, gets the device capabilities.
* @param[in] lpdsb pointer to the direct sound buffer, either primary or secondary.
* @return returns 1 if succeeded, any other value indicates an error.
* @sa http://bit.ly/zP10oa
*/
int get_buffer_caps(const char * prefix, LPDIRECTSOUNDBUFFER lpdsb)
{
DSBCAPS caps;
HRESULT hr;
ZeroMemory(&caps, sizeof(DSBCAPS));
caps.dwSize = sizeof(DSBCAPS);
hr = lpdsb->GetCaps(&caps);
if (SUCCEEDED(hr))
{
size_t index;
debug_outputln("%4.4u %20s : 0x%8.8x %8u %8u %8u"
,__LINE__
,prefix
,caps.dwFlags
,caps.dwBufferBytes
,caps.dwUnlockTransferRate
,caps.dwPlayCpuOverhead
);
for (index = 0; index <sizeof(flags_to_descs)/sizeof(flags_to_descs[0]); ++index)
{
if (caps.dwFlags & flags_to_descs[index].flag_)
debug_outputln("%s %4.4u : %s"
,__FILE__, __LINE__
,flags_to_descs[index].desc_);
}
}
else
{
debug_outputln("%s %4.4u : %8.8x", __FILE__, __LINE__, hr);
}
return SUCCEEDED(hr);
}
示例11: LoopBlank
static int LoopBlank(void)
{
void *mema=NULL,*memb=NULL;
DWORD sizea=0,sizeb=0;
LoopBuffer->Lock(0, LoopLen, &mema,&sizea, &memb,&sizeb, 0);
if (mema) memset(mema,0,sizea);
LoopBuffer->Unlock(mema,sizea, memb,sizeb);
return 0;
}
示例12: soundmng_destroy
void soundmng_destroy(void) {
if (pDSData3) {
#if defined(VERMOUTH_LIB)
midimod_destroy(vermouth_module);
vermouth_module = NULL;
#endif
#if defined(MT32SOUND_DLL)
mt32sound_setrate(0);
#endif
pDSData3->Stop();
pDSData3->Release();
pDSData3 = NULL;
}
}
示例13: SNDDXClearAudioBuffer
void SNDDXClearAudioBuffer()
{
// we shouldn't need to provide 2 buffers since it's 1 contiguous range
// but maybe newer directsound implementations have issues
LPVOID buffer1;
LPVOID buffer2;
DWORD buffer1_size, buffer2_size;
HRESULT hr = lpDSB2->Lock(0, 0, &buffer1, &buffer1_size, &buffer2, &buffer2_size, DSBLOCK_ENTIREBUFFER);
if(FAILED(hr))
return;
memset(buffer1, 0, buffer1_size);
if(buffer2)
memset(buffer2, 0, buffer2_size);
lpDSB2->Unlock(buffer1, buffer1_size, buffer2, buffer2_size);
}
示例14:
/*-----------------------------------------------------------------------------
[Play]
-----------------------------------------------------------------------------*/
void
AOUT_Play(
BOOL bPlay)
{
if (!_bAudioInit)
return;
_bPlay = bPlay;
if (_bPlay)
{
_pDSB1->Play(0, 0, DSBPLAY_LOOPING);
_pDSB2->Play(0, 0, DSBPLAY_LOOPING);
_pDSB3->Play(0, 0, DSBPLAY_LOOPING);
}
}
示例15: SNDDMA_GetDMAPos
/*
==============
SNDDMA_GetDMAPos
return the current sample position (in mono samples read)
inside the recirculating dma buffer, so the mixing code will know
how many sample are required to fill it up.
===============
*/
int SNDDMA_GetDMAPos(void)
{
MMTIME mmtime;
int s = 0;
DWORD dwWrite;
if (dsound_init)
{
mmtime.wType = TIME_SAMPLES;
//if (!s_primary->value)
#ifdef QDSNDCOMPILERHACK
pDSBuf->lpVtbl->GetCurrentPosition(pDSBuf, &mmtime.u.sample, &dwWrite);
#else
pDSBuf->GetCurrentPosition(&mmtime.u.sample, &dwWrite);
#endif
//else
// pDSPBuf->lpVtbl->GetCurrentPosition(pDSPBuf, &mmtime.u.sample, &dwWrite);
s = mmtime.u.sample - mmstarttime.u.sample;
}
else if (wav_init)
{
s = snd_sent * WAV_BUFFER_SIZE;
}
s >>= sample16;
s &= (dma.samples-1);
return s;
}