本文整理汇总了C++中IDirectSoundBuffer::GetCurrentPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirectSoundBuffer::GetCurrentPosition方法的具体用法?C++ IDirectSoundBuffer::GetCurrentPosition怎么用?C++ IDirectSoundBuffer::GetCurrentPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirectSoundBuffer
的用法示例。
在下文中一共展示了IDirectSoundBuffer::GetCurrentPosition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Stream
void DirectSoundStreamer::Stream( void const *pSamples )
{
// Verify buffer availability
DWORD play, write;
if( FAILED( m_pDirectSoundBuffer->GetCurrentPosition( &play, &write ) ) )
return;
if( write < play )
write += DWORD( m_physical );
std::size_t begin( m_begin );
if( begin < play )
begin += m_physical;
if( begin < write )
begin = std::size_t( write );
std::size_t end( begin + m_stream );
if( play + m_virtual < end )
return;
begin %= m_physical;
// Copy samples to buffer
void *ps[ 2 ];
DWORD sizes[ 2 ];
HRESULT hResult( m_pDirectSoundBuffer->Lock( DWORD( begin ), DWORD( m_stream ), &ps[ 0 ], &sizes[ 0 ], &ps[ 1 ], &sizes[ 1 ], 0 ) );
if( FAILED( hResult ) )
{
if( hResult != DSERR_BUFFERLOST )
return;
m_pDirectSoundBuffer->Restore();
if( FAILED( m_pDirectSoundBuffer->Lock( DWORD( begin ), DWORD( m_stream ), &ps[ 0 ], &sizes[ 0 ], &ps[ 1 ], &sizes[ 1 ], 0 ) ) )
return;
}
using std::memcpy;
memcpy( ps[ 0 ], pSamples, std::size_t( sizes[ 0 ] ) );
if( ps[ 1 ] )
memcpy( ps[ 1 ], static_cast< char const * >( pSamples ) + sizes[ 0 ], std::size_t( sizes[ 1 ] ) );
m_pDirectSoundBuffer->Unlock( ps[ 0 ], sizes[ 0 ], ps[ 1 ], sizes[ 1 ] );
// Select next buffer
m_begin = end % m_physical;
}