本文整理汇总了C++中IDirectSoundBuffer::SetCurrentPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirectSoundBuffer::SetCurrentPosition方法的具体用法?C++ IDirectSoundBuffer::SetCurrentPosition怎么用?C++ IDirectSoundBuffer::SetCurrentPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirectSoundBuffer
的用法示例。
在下文中一共展示了IDirectSoundBuffer::SetCurrentPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateBuffer
bool DSoundAudioBackend::CreateBuffer() {
PCMWAVEFORMAT pcmwf;
DSBUFFERDESC dsbdesc;
memset(&pcmwf, 0, sizeof(PCMWAVEFORMAT));
memset(&dsbdesc, 0, sizeof(DSBUFFERDESC));
bufferSize_ = BUFSIZE;
pcmwf.wf.wFormatTag = WAVE_FORMAT_PCM;
pcmwf.wf.nChannels = 2;
pcmwf.wf.nSamplesPerSec = sampleRate_;
pcmwf.wf.nBlockAlign = 4;
pcmwf.wf.nAvgBytesPerSec = pcmwf.wf.nSamplesPerSec * pcmwf.wf.nBlockAlign;
pcmwf.wBitsPerSample = 16;
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; // //DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
dsbdesc.dwBufferBytes = bufferSize_; //FIX32(pcmwf.wf.nAvgBytesPerSec); //change to set buffer size
dsbdesc.lpwfxFormat = (WAVEFORMATEX *)&pcmwf;
if (SUCCEEDED(ds_->CreateSoundBuffer(&dsbdesc, &dsBuffer_, NULL))) {
dsBuffer_->SetCurrentPosition(0);
return true;
} else {
dsBuffer_ = NULL;
return false;
}
}
示例2: 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;
}