   DirectSound Streaming buffer pause/resume problem
  Hello, i'm making a simple wave player using directsound, everything is working fine except when i try to pause then resume, directsound doesn't resume from exactly the point i paused at, but resumes from some point after that and the thing that gets me crazy is that it's not always like that sometimes it resumes from right where i paused sometimes it resumes a couple 100 milliseconds after and sometimes it resumes a complete 1 second after the point where i paused at.i'm using a streaming buffer (2 seconds long buffer) i tried changing that but the problem is still there also i tried anything from 1 to 20 notifications per second but no luck.as far as i understand when i want to pause (which means that i want to resume from that point) i'ld only call _secondaryBuffer->Stop() then when i want to resume i'ld call _secondaryBuffer->Play(0, 0, DSBPLAY_LOOPING) and that's what i'm doing.my pause/resume functions:void Pause(){_secondaryBuffer->Stop();}void Resume(){_secondaryBuffer->Play(0, 0, DSBPLAY_LOOPING);}i was trying somethings out and actually one thing worked which is:void Resume(){_secondaryBuffer->SetCurrentPosition(0);_secondaryBuffer->Play(0, 0, DSBPLAY_LOOPING);}now while this means that the read pointer should be pointing to the beginning of the buffer it's not because it's always resuming from where i paused.so could some one help with that?i also googled alot couldn't find any similar problem thanx for your time   
  You said that at some point you were using a single update point, a two second buffer, and up to a one second jump in the sound. This leads me to belive that your streamming code if faulty. Are you stoping the streamming of the file when you stop playing the buffer?If you can post the code for both the file streamming and the start/stop of the buffer that would help.Finally, are you using polling or system notifications? I'm guessing the latter.   ;Quote:Are you stoping the streamming of the file when you stop playing the buffer?yes i doQuote:Finally, are you using polling or system notifications? I'm guessing the latter.yes system or event notifications with a different handler thread.Quote:If you can post the code for both the file streamming and the start/stop of the buffer that would help.here:void DirectSoundPlay(){if(_playing && _paused){DirectSoundPause();return;}if(!_playing){_playing = true;_paused = false;StartNotificationHandlingThread();FillBuffer(0, _numBytesPerNotification);_directSoundBuffer-&gt;Play(0, 0, DSBPLAY_LOOPING);}}void DirectSoundPause(){if(_playing && (!_paused)){IgnoreNotifications();_paused = true;_directSoundBuffer-&gt;Stop();return;}if(_playing && _paused){_paused = false;_directSoundBuffer-&gt;Play(0, 0, DSBPLAY_LOOPING);HandleNotifications();return;}}DWORD WINAPI NotificationHandlingThreadProc(LPVOID lpParameter){unsigned int returnValue = 0;unsigned int handleIndex = 0;while(_playing){returnValue = WaitForMultipleObjects(_numNotifications, _eventHandles, FALSE, INFINITE);handleIndex = returnValue - WAIT_OBJECT_0;_lastHandleIndex = handleIndex;if(handleIndex == (_numNotifications - 1)){//if we reached the end stop it!if(_numPassesThroughStopNotificationBeforeStop == 0){_playing = false;_directSoundBuffer-&gt;Stop();MessageBox(0, "ENDED", "ENDED", 0);return 0;}else_numPassesThroughStopNotificationBeforeStop -- ;}else{if(_ignoreNotifications)continue;if(_skipNextNotification){_skipNextNotification = false;continue;}//fill a part of the buffer_index ++ ;if(_index &gt;= (_numNotifications - 1))_index = 0;FillBuffer(_index*_numBytesPerNotification, _numBytesPerNotification);}}MessageBox(0, "EXITING_THREAD", "EXITING_THREAD", 0);return 0;}unsigned int FillBuffer(unsigned int position, unsigned int size){unsigned int returnValue = 0;void* buffer = 0;DWORD lockedSize;if(_directSoundBuffer-&gt;Lock(position, size, &buffer, &lockedSize, 0, 0, 0) != DS_OK)MessageBox(0, "ERROR_LOCKING_BUFFER", "ERROR_LOCKING_BUFFER", 0);returnValue = ReadWave(size, buffer);_directSoundBuffer-&gt;Unlock(buffer, lockedSize, 0, 0);return returnValue;}void SkipNextNotification(){_skipNextNotification = true;}void IgnoreNotifications(){_ignoreNotifications = true;}void HandleNotifications(){_ignoreNotifications = false;}i'ld post more if it'ld help :p[Edited by - r on December 13, 2005 4:31:57 AM];  I didn't completely pick the code apart so I may not have the entire picture here. On the whole, it looks a bit over-engineered to me ;)I really don't know about those calls to functions like 'IgnoreNotifcations()'. you shouldn't be ignoring any notifications. They will only be sent when the soundbuffer reaches certain points you specified. This will let you know it's time to update the next part of the buffer. To stop the notification you need only stop playing the buffer. Effectively calling the IDirectSoundBuffer8::Stop method *IS* pausing the sound in this case.Another thing is that function 'StartNotificationHandlingThread()'. Is there anything that is accidentally being reset in there that should not be? In general, you probably should only create the thread when the stream is created and release it when the stream is released and not when it is played/paused. When I'm using system events I just dedicate a thread full time to soundbuffer notifcations.   ;Quote:you shouldn't be ignoring any notifications. They will only be sent when the soundbuffer reaches certain points you specified.actually that what i did at first, ... same problem.Quote:Another thing is that function 'StartNotificationHandlingThread()'. Is there anything that is accidentally being reset in there that should not be? In general, you probably should only create the thread when the stream is created and release it when the stream is released and not when it is played/paused.well, you didn't have a thorough look at the code, the function StartNotificationHandlingThread() is called only once when the stream is played for the first time, the thread is there and running till we Stop() it. if you have a second look at the function DirectSoundPause(), (which is the function that i use to pause/resume) u'll find that all it does is _directSoundBuffer->Stop()/_directSoundBuffer->Play() even without the use of IgnoreNotifications()/HandleNotifcations() pair the problem is still there.thanx for the replies anyway :)   ;  Have you tried using polling first? Multithreading/events can add headaches to anything, complex or not. Maybe try writing a polling system and then build around that with events and threads.At this point I'm thinking the problem lies somewhere in your buffer filling. Something isn't being taken into account. Like I said, you should not have to ignore notifications (unless they are Window messages). Stopping the buffer should stop the notifications (again, with the exception of Window messages).   ;Quote:Have you tried using polling first? Multithreading/events can add headaches to anything, complex or not. Maybe try writing a polling system and then build around that with events and threads.wont' that be more complex? anyway i'll try a static buffer if it works ok, then you are right something is wrong with the event handling, if not then the problem is somewhere else.Quote:Like I said, you should not have to ignore notifications (unless they are Window messages). Stopping the buffer should stop the notifications (again, with the exception of Window messages).well i tried that too, read my last post.thx for the reply, i checked your site, nice tutorials, but lacking the only thing i hoped to find,... streaming buffers :(   ;  alright i tried using a static buffer it works seamlessly so the problem is with my notification handling/threading.   ;  How many event points do you have? Not including the buffer-stop event. What positionas are they at? And are you taking into account end-of-file correctly?I just relized your code is not in source tags. You'd better put them in. The moderator is really beginning to not like that. Also, it makes it easier to read =)Quote: but lacking the only thing i hoped to find,... streaming buffers That should be up before the weekend. But hopefully you'll have fixed this before then.   ;  i tried 1 to 20 notifications per second (not including the buffer stop notification)positions depends on the number of notifications per second starting from the first byte of the buffer, for example if i have 20 notifications/sec then the first notification position = 0*nAvgBytesPerSec/_numNotificationsPerSec, second position = 1*nAvgBytesPerSec/_numNotificationsPerSec, ...and so on.about the end of file thing, i'm not sure how would that affect this when i'm playing 4 mins wave file and the problem is present at the beginning. but yes i'm taking care of it.how do i put my code in tags i tried "code" between [] didn't work.   