{"id":682,"date":"2008-11-11T09:49:30","date_gmt":"2008-11-11T07:49:30","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=682"},"modified":"2008-11-11T09:49:30","modified_gmt":"2008-11-11T07:49:30","slug":"directsound-play-buffer-notification-idirectsoundnotify8","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/682","title":{"rendered":"DirectSound play buffer notification (IDirectSoundNotify8)"},"content":{"rendered":"<p><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb174483(VS.85).aspx\">IDirectSoundNotify8<\/a> 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).<\/p>\n<p>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&#8217;s <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/h4616bh2.aspx\">CWindowImpl<\/a> (CMessageOnlyWindowImpl).<\/p>\n<pre>...\r\nATLENSURE_SUCCEEDED(DirectSoundCreate8(NULL, &amp;pDirectSound8, NULL));\r\n...\r\nATLENSURE_SUCCEEDED(pDirectSound8-&gt;SetCooperativeLevel(Window, DSSCL_PRIORITY));\r\n...\r\nATLENSURE_SUCCEEDED(pDirectSound8-&gt;CreateSoundBuffer(&amp;BufferDescriptor, &amp;pDirectSoundBuffer, NULL));\r\n...\r\nCComQIPtr&lt;IDirectSoundNotify8, &amp;IID_IDirectSoundNotify8&gt; pDirectSoundNotify8 = pDirectSoundBuffer;\r\n...\r\nATLENSURE_SUCCEEDED(pDirectSoundNotify8-&gt;SetNotificationPositions(g_nPositionCount, pPositionNotify));\r\nATLENSURE_SUCCEEDED(pDirectSoundBuffer-&gt;Play(0, 0, DSBPLAY_LOOPING));<\/pre>\n<p><!--more--><\/p>\n<p>Application output:<\/p>\n<pre>BufferDescriptor.dwBufferBytes 128000\r\ng_nPositionCount 8\r\npPositionNotify[0].dwOffset 15999\r\npPositionNotify[1].dwOffset 31999\r\npPositionNotify[2].dwOffset 47999\r\npPositionNotify[3].dwOffset 63999\r\npPositionNotify[4].dwOffset 79999\r\npPositionNotify[5].dwOffset 95999\r\npPositionNotify[6].dwOffset 111999\r\npPositionNotify[7].dwOffset 127999\r\nnWaitResult 0\r\nnWaitResult 1\r\nnWaitResult 2\r\nnWaitResult 3\r\nnWaitResult 4\r\nnWaitResult 5\r\nnWaitResult 6\r\nnWaitResult 7\r\nnWaitResult 0\r\nnWaitResult 1\r\nnWaitResult 2\r\nnWaitResult 3\r\nnWaitResult 4\r\nnWaitResult 5\r\nnWaitResult 6\r\nnWaitResult 7<\/pre>\n<p>A Visual C++ .NET 2008 source code <a href=\"http:\/\/trac2.assembla.com\/roatl-utilities\/browser\/trunk\/DirectSoundNotifySample01\">is available from SVN<\/a>.<\/p>\n<p>See Also:<\/p>\n<ul>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb219693(VS.85).aspx\">DirectSoundCreate8<\/a><\/li>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb174483(VS.85).aspx\">IDirectSoundNotify8<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>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&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/682\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,6,13],"tags":[487,485,139,140,488],"class_list":["post-682","post","type-post","status-publish","format-standard","hentry","category-atl","category-audio","category-source","tag-atl","tag-audio","tag-directsound","tag-directx","tag-source"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=682"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/682\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}