I've been playing around a bit with your code and it seems to work reasonably well like this:
Part of the stuttering problem appears to be that the buffersize is incorrect. I discovered this with my sound generation code above, in that the produced sample played for about half the calculated buffer duration.
Also added channel switching, the numbers need tweaking, but it's going somewhere...
SuperStrict Const freq:Int=11025 Const updatespeed:Int=10 Const buffersize:Int=(freq/updatespeed) * 32 Print "Buffer Size: "+buffersize Const numBuffers:Int = 2 Const numChannels:Int = 40 Const numSounds:Int = numChannels'20 Global my:Int ' mouse y position Local iterator:Int Local currentbuffer:Int Local currentChannel:Int Local t:Int Graphics 640 , 480 Global buffer:TAudioSample[numBuffers] For iterator = 0 Until numBuffers buffer[iterator]=CreateAudioSample(buffersize,freq,SF_STEREO16BE) Next Global channel:TChannel[numChannels] For iterator = 0 Until numChannels channel[iterator]=AllocChannel() Next Global sound:TSound[numSounds] For iterator = 0 Until numSounds sound[iterator] = LoadSound(buffer[0]) Next Local timer:TTimer=CreateTimer(updatespeed) calcnew buffer,currentbuffer Repeat WaitEvent() If EventID() = EVENT_TIMERTICK currentChannel = getAvailableChannel() PlaySound sound[currentbuffer],channel[currentChannel] currentbuffer = currentbuffer Mod numBuffers Cls calcnew buffer,currentbuffer sound[currentChannel]=LoadSound(buffer[currentbuffer]) SetColor 255,255,255 For t=0 Until Min(buffersize,640) Plot t,240+buffer[currentbuffer].samples[t] 'DrawLine t-1, 240+buffer[currentBuffer].samples[t-1], t,240+buffer[currentbuffer].samples[t] Next DrawText my,0,0 Flip EndIf my=MouseY() If KeyDown(KEY_ESCAPE) End Forever Function calcnew(buffer:TAudioSample[] Var,index:Int) Local ratio:Int=8'Rnd(15)+1 Cls Local a:Int For Local t:Int=0 Until buffersize a=Sin((t*ratio))*my buffer[index].samples[t]=a SetColor 255,128,64 Plot t,240+a Next End Function Function getAvailableChannel:Int() For Local i:Int = 0 Until numChannels If Not ChannelPlaying(channel[i]) Then Return i Next Print "no channel available" Return 0 End Function
Part of the stuttering problem appears to be that the buffersize is incorrect. I discovered this with my sound generation code above, in that the produced sample played for about half the calculated buffer duration.
Also added channel switching, the numbers need tweaking, but it's going somewhere...