本文整理汇总了C++中IDirectSoundBuffer::Play方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirectSoundBuffer::Play方法的具体用法?C++ IDirectSoundBuffer::Play怎么用?C++ IDirectSoundBuffer::Play使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirectSoundBuffer
的用法示例。
在下文中一共展示了IDirectSoundBuffer::Play方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RunThread
// TODO: Move the init into the thread, like WASAPI?
int DSoundAudioBackend::RunThread() {
setCurrentThreadName("DSound");
currentPos_ = 0;
lastPos_ = 0;
dsBuffer_->Play(0,0,DSBPLAY_LOOPING);
while (!threadData_) {
EnterCriticalSection(&soundCriticalSection);
dsBuffer_->GetCurrentPosition((DWORD *)¤tPos_, 0);
int numBytesToRender = RoundDown128(ModBufferSize(currentPos_ - lastPos_));
if (numBytesToRender >= 256) {
int numBytesRendered = 4 * (*callback_)(realtimeBuffer_, numBytesToRender >> 2, 16, 44100, 2);
//We need to copy the full buffer, regardless of what the mixer claims to have filled
//If we don't do this then the sound will loop if the sound stops and the mixer writes only zeroes
numBytesRendered = numBytesToRender;
WriteDataToBuffer(lastPos_, (char *) realtimeBuffer_, numBytesRendered);
currentPos_ = ModBufferSize(lastPos_ + numBytesRendered);
totalRenderedBytes_ += numBytesRendered;
lastPos_ = currentPos_;
}
LeaveCriticalSection(&soundCriticalSection);
WaitForSingleObject(soundSyncEvent_, MAXWAIT);
}
示例2: RunThread
int DSoundAudioBackend::RunThread() {
if (FAILED(DirectSoundCreate8(0, &ds_, 0))) {
ds_ = NULL;
threadData_ = 2;
return 1;
}
ds_->SetCooperativeLevel(window_, DSSCL_PRIORITY);
if (!CreateBuffer()) {
ds_->Release();
ds_ = NULL;
threadData_ = 2;
return 1;
}
soundSyncEvent_ = CreateEvent(0, false, false, 0);
InitializeCriticalSection(&soundCriticalSection);
DWORD num1;
short *p1;
dsBuffer_->Lock(0, bufferSize_, (void **)&p1, &num1, 0, 0, 0);
memset(p1, 0, num1);
dsBuffer_->Unlock(p1, num1, 0, 0);
totalRenderedBytes_ = -bufferSize_;
setCurrentThreadName("DSound");
currentPos_ = 0;
lastPos_ = 0;
dsBuffer_->Play(0,0,DSBPLAY_LOOPING);
while (!threadData_) {
EnterCriticalSection(&soundCriticalSection);
dsBuffer_->GetCurrentPosition((DWORD *)¤tPos_, 0);
int numBytesToRender = RoundDown128(ModBufferSize(currentPos_ - lastPos_));
if (numBytesToRender >= 256) {
int numBytesRendered = 4 * (*callback_)(realtimeBuffer_, numBytesToRender >> 2, 16, 44100, 2);
//We need to copy the full buffer, regardless of what the mixer claims to have filled
//If we don't do this then the sound will loop if the sound stops and the mixer writes only zeroes
numBytesRendered = numBytesToRender;
WriteDataToBuffer(lastPos_, (char *) realtimeBuffer_, numBytesRendered);
currentPos_ = ModBufferSize(lastPos_ + numBytesRendered);
totalRenderedBytes_ += numBytesRendered;
lastPos_ = currentPos_;
}
LeaveCriticalSection(&soundCriticalSection);
WaitForSingleObject(soundSyncEvent_, MAXWAIT);
}
示例3: DXTRACE_ERR
//-----------------------------------------------------------------------------
// Name: CSound::Play3D()
// Desc: Plays the sound using voice management flags. Pass in DSBPLAY_LOOPING
// in the dwFlags to loop the sound
//-----------------------------------------------------------------------------
HRESULT CSound::Play3D( LPDS3DBUFFER p3DBuffer, DWORD dwPriority, DWORD dwFlags, LONG lFrequency )
{
HRESULT hr;
BOOL bRestored;
DWORD dwBaseFrequency;
if( m_apDSBuffer == NULL )
return CO_E_NOTINITIALIZED;
IDirectSoundBuffer* pDSB = GetFreeBuffer();
if( pDSB == NULL )
return DXTRACE_ERR( TEXT("GetFreeBuffer"), E_FAIL );
// Restore the buffer if it was lost
if( FAILED( hr = RestoreBuffer( pDSB, &bRestored ) ) )
return DXTRACE_ERR( TEXT("RestoreBuffer"), hr );
if( bRestored )
{
// The buffer was restored, so we need to fill it with new data
if( FAILED( hr = FillBufferWithSound( pDSB, FALSE ) ) )
return DXTRACE_ERR( TEXT("FillBufferWithSound"), hr );
}
if( m_dwCreationFlags & DSBCAPS_CTRLFREQUENCY )
{
pDSB->GetFrequency( &dwBaseFrequency );
pDSB->SetFrequency( dwBaseFrequency + lFrequency );
}
// QI for the 3D buffer
IDirectSound3DBuffer* pDS3DBuffer;
hr = pDSB->QueryInterface( IID_IDirectSound3DBuffer, (VOID**) &pDS3DBuffer );
if( SUCCEEDED( hr ) )
{
hr = pDS3DBuffer->SetAllParameters( p3DBuffer, DS3D_IMMEDIATE );
if( SUCCEEDED( hr ) )
{
hr = pDSB->Play( 0, dwPriority, dwFlags );
}
pDS3DBuffer->Release();
}
return hr;
}
示例4: Play
int CSound::Play(DWORD position_ms, bool isLoop)
{
if(!m_pSecondaryBuffer) return CS_E_NULL_SECONDARY;
m_isLoop = isLoop;
if(m_isStreamFile){
//OpenStreamThread();
//if(IsPlaying()){
//PostThreadMessage(m_dwThreadId, CSL_MSG_SEEK_AND_PLAY, (DWORD)(position_ms * ((double)m_wfx.nAvgBytesPerSec/1000.0)), 0);
PostThreadMessage(m_dwThreadId, CSL_MSG_SEEK_AND_PLAY, position_ms, 0);
WaitForSingleObject(m_hThreadMessageDispatchEvent, INFINITE);
//this->SetStreamCurosr((DWORD)(position_ms * ((double)m_wfx.nAvgBytesPerSec/1000.0)));
//}
//m_pSecondaryBuffer->Play(0, 0, DSBPLAY_LOOPING);
}else{
IDirectSoundBuffer* pBuffer = NULL;
if(m_nDuplicateLimit > 0){ //セカンダリバッファのコピーを使う
int id = GetInactiveBufferNo();//使用中でないバッファのインデックスを取得
if(id == -1) return CS_E_NOCANDO;
pBuffer = m_ppDuplicatedBuffer[id];
}else{
if( !m_isAllowRapidAccess ){
DWORD dwStatus;
m_pSecondaryBuffer->GetStatus( &dwStatus );
bool isSecondaryPlaying = (dwStatus & DSBSTATUS_PLAYING);
if( isSecondaryPlaying ){
/* nop */
}else{
pBuffer = m_pSecondaryBuffer;
}
}else{
pBuffer = m_pSecondaryBuffer;
}
}
if( !pBuffer ){
/* nop */
}else{
pBuffer->SetCurrentPosition( (DWORD)((double)position_ms * (double)(m_wfx.nAvgBytesPerSec/1000.0)) );
pBuffer->Play(0, 0, isLoop ? DSBPLAY_LOOPING : 0);
//m_pSecondaryBuffer->Play(0, 0, m_isStreamFile ? DSBPLAY_LOOPING : isLoop ? DSBPLAY_LOOPING : 0);
}
}
return CS_E_OK;
}
示例5: Play
//-----------------------------------------------------------------------------
// Name: CSound::Play()
// Desc: Plays the sound using voice management flags. Pass in DSBPLAY_LOOPING
// in the dwFlags to loop the sound
//-----------------------------------------------------------------------------
HRESULT CSound::Play( DWORD dwPriority, DWORD dwFlags, LONG lVolume, LONG lFrequency, LONG lPan )
{
HRESULT hr;
BOOL bRestored;
if( m_apDSBuffer == NULL )
return CO_E_NOTINITIALIZED;
IDirectSoundBuffer* pDSB = GetFreeBuffer();
if( pDSB == NULL )
return DXTRACE_ERR( TEXT("GetFreeBuffer"), E_FAIL );
// Restore the buffer if it was lost
if( FAILED( hr = RestoreBuffer( pDSB, &bRestored ) ) )
return DXTRACE_ERR( TEXT("RestoreBuffer"), hr );
if( bRestored )
{
// The buffer was restored, so we need to fill it with new data
if( FAILED( hr = FillBufferWithSound( pDSB, FALSE ) ) )
return DXTRACE_ERR( TEXT("FillBufferWithSound"), hr );
}
if( m_dwCreationFlags & DSBCAPS_CTRLVOLUME )
{
pDSB->SetVolume( lVolume );
}
if( lFrequency != -1 &&
(m_dwCreationFlags & DSBCAPS_CTRLFREQUENCY) )
{
pDSB->SetFrequency( lFrequency );
}
if( m_dwCreationFlags & DSBCAPS_CTRLPAN )
{
pDSB->SetPan( lPan );
}
return pDSB->Play( 0, dwPriority, dwFlags );
}
示例6: play
int CSoundResource::play( int sndID, DWORD priority, DWORD flags, LONG volume, LONG freq, LONG pan )
{
assert( mDSBuffers );
int bufferIdx = getFreeBufferIndex();
IDirectSoundBuffer* buffer = mDSBuffers[bufferIdx];
if( !restoreBufferAndFill( buffer, false ) )
return -1;
if( mCreationFlags & DSBCAPS_CTRLVOLUME )
buffer->SetVolume( volume );
if( freq != -1 && (mCreationFlags & DSBCAPS_CTRLFREQUENCY) )
buffer->SetFrequency( freq );
if( mCreationFlags & DSBCAPS_CTRLPAN )
buffer->SetPan( pan );
mPlayingIDs[bufferIdx] = sndID;
buffer->Play( 0, priority, flags );
return bufferIdx;
}
示例7: toear
int CSoundResource::play3D( int sndID, const DS3DBUFFER& props3D, DWORD priority, DWORD flags, LONG volume, LONG freq )
{
HRESULT hr;
DWORD baseFreq;
assert( mDSBuffers );
// cull the sound if too far
const SVector3& earPos = G_AUDIOCTX->getListener().transform.getOrigin();
SVector3 toear( earPos.x - props3D.vPosition.x, earPos.y - props3D.vPosition.y, earPos.z - props3D.vPosition.z );
if( toear.lengthSq() >= props3D.flMaxDistance * props3D.flMaxDistance )
return 0;
int bufferIdx = getFreeBufferIndex();
IDirectSoundBuffer* buffer = mDSBuffers[bufferIdx];
if( !restoreBufferAndFill( buffer, false ) )
return -1;
if( mCreationFlags & DSBCAPS_CTRLVOLUME )
buffer->SetVolume( volume );
if( mCreationFlags & DSBCAPS_CTRLFREQUENCY ) {
buffer->GetFrequency( &baseFreq );
buffer->SetFrequency( baseFreq + freq );
}
IDirectSound3DBuffer* buf3D;
hr = buffer->QueryInterface( IID_IDirectSound3DBuffer, (void**)&buf3D );
if( SUCCEEDED( hr ) ) {
hr = buf3D->SetAllParameters( &props3D, DS3D_IMMEDIATE );
if( SUCCEEDED( hr ) ) {
mPlayingIDs[bufferIdx] = sndID;
hr = buffer->Play( 0, priority, flags );
}
buf3D->Release();
}
return bufferIdx;
}
示例8: sizeof
IDirectSoundBuffer *SoundLibrary3dDirectSound::CreateSecondaryBuffer(int _numSamples)
{
int errCode;
IDirectSoundBuffer *buffer = NULL;
WAVEFORMATEX wfx;
ZeroMemory( &wfx, sizeof(WAVEFORMATEX) );
wfx.wFormatTag = (WORD) WAVE_FORMAT_PCM;
wfx.nChannels = 1;
wfx.nSamplesPerSec = m_sampleRate; // was _mixFreq;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = (WORD) (wfx.wBitsPerSample / 8 * wfx.nChannels);
wfx.nAvgBytesPerSec = (DWORD) (wfx.nSamplesPerSec * wfx.nBlockAlign);
int flags = DSBCAPS_CTRL3D |
DSBCAPS_CTRLFX |
DSBCAPS_CTRLFREQUENCY |
DSBCAPS_CTRLVOLUME |
DSBCAPS_GETCURRENTPOSITION2;
if( Hardware3DSupport() && m_hw3dDesired ) flags |= DSBCAPS_LOCHARDWARE;
else flags |= DSBCAPS_LOCSOFTWARE;
DSBUFFERDESC dsbd;
ZeroMemory( &dsbd, sizeof(DSBUFFERDESC) );
dsbd.dwSize = sizeof(DSBUFFERDESC);
dsbd.dwFlags = flags;
dsbd.dwBufferBytes = _numSamples * 2;
dsbd.lpwfxFormat = &wfx;
dsbd.guid3DAlgorithm = DS3DALG_DEFAULT;
errCode = m_directSound->m_device->CreateSoundBuffer(&dsbd, &buffer, NULL);
//
// Used to be SOUNDASSERT, early return if fails
SOUNDDEBUG( errCode, "Direct sound couldn't create a secondary buffer, numSamples(%d)", _numSamples );
if( errCode != DS_OK )
{
return NULL;
}
// Fill the buffer with zeros to start with
void *buf1;
unsigned long buf1Size;
errCode = buffer->Lock(0, // Offset
0, // Size (ignored because using DSBLOCK_ENTIREBUFFER)
&buf1,
&buf1Size,
NULL,
NULL,
DSBLOCK_ENTIREBUFFER);
SOUNDASSERT( errCode, "Direct Sound couldn't lock buffer" );
memset( buf1, 0, buf1Size );
buffer->Unlock(buf1, buf1Size, NULL, 0);
// Start the stream playing
errCode = buffer->Play( 0, 0, DSBPLAY_LOOPING );
SOUNDASSERT(errCode, "Direct sound couldn't start playing a stream" );
return buffer;
}