Codejie's C++ Space

Using C++

DSound的更新,以支持SetCurrentPosition功能

    查看了DirectSound的MSDN文档,才发现DirectSoundBuffer的Primary Buffer和Second Buffer还是有很大区别的,就像SetCurrentPosition函数不支持Primary Buffer。
    这里是MSDN上的说明:
IDirectSoundBuffer8::SetCurrentPosition

IDirectSoundBuffer8::SetCurrentPosition

The SetCurrentPosition method sets the position of the play cursor, which is the point at which the next byte of data is read from the buffer.

HRESULT SetCurrentPosition(
DWORD dwNewPosition
);

Parameters

dwNewPosition
Offset of the play cursor, in bytes, from the beginning of the buffer.

Return Values

If the method succeeds, the return value is DS_OK. If the method fails, the return value may be one of the following error values:

Return code
DSERR_INVALIDCALL
DSERR_INVALIDPARAM
DSERR_PRIOLEVELNEEDED

Remarks

This method cannot be called on the primary buffer.

If the buffer is playing, the cursor immediately moves to the new position and play continues from that point. If it is not playing, playback will begin from the new position the next time the Play method is called.



    相应代码修改如下,用于建立新的DirectSoundBuffer8对象。
 1 int CDSoundObject::CreateDSoundBuffer()
 2 {
 3     IDirectSoundBuffer* psbuffer = NULL;
 4 
 5     DSBUFFERDESC desc;
 6     memset(&desc, 0sizeof(DSBUFFERDESC));
 7     desc.dwSize = sizeof(DSBUFFERDESC);
 8     desc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_LOCSOFTWARE;
 9     desc.dwBufferBytes = CDSoundObject::SIZE_DS_BUFFER;//header.data_size;
10     desc.lpwfxFormat = &_fmtWave;
11 
12     if(_pDSBuffer != NULL)
13         _pDSBuffer->Release();
14 
15     HRESULT hr = _pDS->CreateSoundBuffer(&desc, &psbuffer, NULL);
16     if(hr != DS_OK)
17         return -1;
18     hr = psbuffer->QueryInterface(IID_IDirectSoundBuffer8, (void**)&_pDSBuffer);
19     psbuffer->Release();
20     if(hr != DS_OK)
21         return -1;
22 
23     return 0;
24 }


posted on 2009-03-27 10:10 codejie 阅读(893) 评论(0)  编辑 收藏 引用 所属分类: C++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


公告

Using C++

导航

统计

留言簿(73)

随笔分类(513)

积分与排名

最新评论

阅读排行榜

评论排行榜