DirectSound 声音输出的延时问题?
大家好!
我最近用DirectSound8 编写了一段代码,想知道在调用IDirectSoundBuffer8::Play后多少ms能听到要放的声音?这个延迟时间怎么能得到?(最好能精确到1ms).
请知道的达人帮帮忙,有相关资料也行!!若能一起探讨更好!!
本人Q|Q号274631279 在线(隐身)
谢谢!!
附代码:
HRESULT hr;
VOID* pDSLockedBuffer = NULL;
DWORD dwDSLockedBufferSize = 0;
DWORD dwWavDataRead = 0;
m_dwDSBufferSize = 40*2*2;//缓冲区
//创建第二缓冲区
BufferDesc.dwBufferBytes = m_dwDSBufferSize;
if(FAILED(hr = m_pDirectSound->CreateSoundBuffer(&BufferDesc, &m_pDSBuffer, 0)))
{
return FALSE;
}
if(FAILED(hr = m_pDirectSound->SetCooperativeLevel(hwnd,DSSCL_NORMAL)))
{
return FALSE;
}
//向缓冲区写数据
m_dwDSBufferSize = 40*2*2;
if(FAILED(hr = m_pDSBuffer->Lock(0, m_dwDSBufferSize, &pDSLockedBuffer,&dwDSLockedBufferSize,NULL,NULL,DSBLOCK_FROMWRITECURSOR )))
{
return FALSE;
}
BYTE * m_pbData= (BYTE*)new BYTE[40*2*2];
short * pShort =(short*)m_pbData;
for (int i=0;i<40*2;i++) {
pShort[i]=32767;
}
delete []m_pbData;
memcpy(pDSLockedBuffer,m_pbData, mode.Wide * 40*2*2);
if(FAILED(hr = m_pDSBuffer->Unlock(pDSLockedBuffer,
dwDSLockedBufferSize,NULL,NULL)))
{
return FALSE;
}
m_pDSBuffer->SetVolum(DSBVOLUME_MAX);
m_pDSBuffer->Play(0, 0,m_bool)
------解决方案--------------------------------------------------------
buffersize/(samplerate*bitpersample*channel) = s (秒)
------解决方案--------------------------------------------------------
顶