Published by alax on 11 Nov 2008 at 09:49 am
DirectSound play buffer notification (IDirectSoundNotify8)
IDirectSoundNotify8 is an interface to get notified on playback on capture audio buffer reaching certain position in the buffer. It is a must thing when implementing ring buffers with new data continuously added to the buffer for seamless playback (continuously copied from in case of capture).
This project is a minimalistic C++ sample code to illustrate the API. To initialize the DirectSound subsystem it is required to provide a window handle, which is created using ATL’s CWindowImpl (CMessageOnlyWindowImpl).
... ATLENSURE_SUCCEEDED(DirectSoundCreate8(NULL, &pDirectSound8, NULL)); ... ATLENSURE_SUCCEEDED(pDirectSound8->SetCooperativeLevel(Window, DSSCL_PRIORITY)); ... ATLENSURE_SUCCEEDED(pDirectSound8->CreateSoundBuffer(&BufferDescriptor, &pDirectSoundBuffer, NULL)); ... CComQIPtr<IDirectSoundNotify8, &IID_IDirectSoundNotify8> pDirectSoundNotify8 = pDirectSoundBuffer; ... ATLENSURE_SUCCEEDED(pDirectSoundNotify8->SetNotificationPositions(g_nPositionCount, pPositionNotify)); ATLENSURE_SUCCEEDED(pDirectSoundBuffer->Play(0, 0, DSBPLAY_LOOPING));
Application output:
BufferDescriptor.dwBufferBytes 128000 g_nPositionCount 8 pPositionNotify[0].dwOffset 15999 pPositionNotify[1].dwOffset 31999 pPositionNotify[2].dwOffset 47999 pPositionNotify[3].dwOffset 63999 pPositionNotify[4].dwOffset 79999 pPositionNotify[5].dwOffset 95999 pPositionNotify[6].dwOffset 111999 pPositionNotify[7].dwOffset 127999 nWaitResult 0 nWaitResult 1 nWaitResult 2 nWaitResult 3 nWaitResult 4 nWaitResult 5 nWaitResult 6 nWaitResult 7 nWaitResult 0 nWaitResult 1 nWaitResult 2 nWaitResult 3 nWaitResult 4 nWaitResult 5 nWaitResult 6 nWaitResult 7
A Visual C++ .NET 2008 source code is available from SVN.
See Also:
Tags: ATL, Audio, directsound, directx, Source
Leave a Reply
You must be logged in to post a comment.
