*
* *
*
scene.org
Log in:
login for 1 year
No account? register here

Scene.org is hosted and supported by:
Scene.org is sponsored by:
* forum - #coders

*
Topic:  Question regarding buffers in realtime synth
* Posted by wb Monday 22 August 2005 - 17:03 
I'm playing around with some realtime sound generation using mmsystem, and have come across a problem. I can't find a good way to swap and play my buffers (using doubble buffering). As a result, lots of nasty clicking sounds are generated once a buffer is finished playing.
I made it work properly by playing a buffer once WM_WOM_DONE was called (generated by mmsystem when a buffer is finished playing), but I want to avoid using callbacks if possible.

Anyway, at the moment, I'm using waveOutGetPosition to get the sample position, and if the sample position indicates that a buffer is done playing, it starts playback of the second buffer. The code goes like this:

 
get newSamplePosition from waveOutGetPosition
if newPosition - oldPosition > bufferLength or if newPosition = 0 then
begin
if buffer1 is active then
begin
playBuffer1
fillBuffer2
set activeBuffer to buffer2
end else
begin
playBuffer2
fillBuffer1
set activeBuffer to buffer1
end
oldPosition = newPosition
end


I'm sure there's a better (and working;) way of doing this, so if anyone has any tips, I would greatly appriciate it..

* Posted by skrebbel Tuesday 23 August 2005 - 10:23 
I don't mean to sound like a dick (cause I don't actually know an answer), but did you look into DirectSound? It does exactly what you seem to want to do, and not really much more than that, and was made to avoid problems like this.

* Posted by wb Tuesday 23 August 2005 - 16:01 
Thanks for the reply. :)

I have looked into it, but I thought I'd just use mmsystem since it seemed to offer the features I'm looking for, and because my knowledge of DirectX is extremely limited. I'll probably try out DirectSound now though, since I can't get started on the synth itself until my little problem is solved.

* Posted by kusma Thursday 25 August 2005 - 19:12 
http://www.demoscene.no/kusma/sound.cpp

here you go, this is my sound-streamer. it works well for my use.

* Posted by wb Thursday 25 August 2005 - 22:57 
Thanks a lot! :D Now I can finally start working on the synth itself.

*