delta timing used for sequencer
Monkey Forums/Monkey Programming/delta timing used for sequencer
| ||
Hi team, I wanted to create simple timer engine based on delta timer sample and other sources on the web to play simple sound files periodicly like in sequencer. I found even using delta timing example in monkey examples sound is never played at constant intervals. When same timer is used to move item or draw bitmap its working just fine. I tested it on flash and android targets. I was wondering if this is my setup fault or its rather a general problem with monkey playing sounds. Or how create simple effect to play sound click every 150 ms exacly. Human ear will detect changes above 5 ms. |
| ||
Have you tried using MilliSecs()? Or the Diddy framework, which has a RealMillisecs() function. I guess that a sound takes a short while to buffer and play, which complicates things. |
| ||
i am using DeltaTimer from Diddy framework the worst thing is that delay after playing sound seems to be random |
| ||
Yeah, I'm not sure monkeys sound system is written with this in mind, Have you considered playing then immediately pausing a sound? Is playback instant from unpausing the sound? |
| ||
@Bladmum, maybe use dt.frametime instead of dt.delta? @Matt - I wouldnt really use RealMillisecs() for anything but a random seed, due to the limitations of it (some targets it will only update every second and in others like Java it is a float and really needed to be a double, which Monkey doesnt support). |
| ||
Good to know |
| ||
I use dt.delta instead of 1 to increment loop counter refresh rate = 60Hz rounds per minute = 240 rounds per seconds = 4 cycle period = 15 ticks ive check it on another mobile device with android with same result as other targets = sound delay looks a bit random now i will try this play and pause stuff |
| ||
i did not mentioned this is sequencer so i need to play different sounds not just one. so play and pause is not applicable hereImport mojo Function Main:Int() New MyApp Return 0 End Function Class MyApp Extends App Field sss:Sound = null Field aaa:Float = 0 Field nnn = 0 Field dt:DeltaTimer Method OnCreate:Int() sss = LoadSound("click.mp3") SetUpdateRate 60 dt = New DeltaTimer(60) Return 0 End Method OnUpdate:Int() dt.UpdateDelta() aaa = aaa + dt.delta if(aaa >= 10.0) aaa = aaa - 10.0 nnn = nnn + 1 StopChannel(nnn Mod 30) PlaySound(sss, nnn Mod 30) End Return 0 End Method OnRender:Int() Return 0 End End Class DeltaTimer Field targetfps:Float = 60 Field currentticks:Float Field lastticks:Float Field frametime:Float Field delta:Float Method New (fps:Float) targetfps = fps lastticks = Millisecs() End Method UpdateDelta:Void () currentticks = Millisecs frametime = currentticks - lastticks delta = frametime / (1000.0 / targetfps) lastticks = currentticks End End |
| ||
Do you need more than the 32 channels Monkey provides? If not, can you play each sound on it's own channel? |
| ||
i am doing this exactly as You mentioned, for the test i just change channel every time in a loop same effect on all targets including two android phones |
| ||
can somebody test my sample code ? i still cannot make it working on my terminal without random delay (or just my sense of hear is so good...) thanks |
| ||
can you post your sound file? thanks |
| ||
this is not related to sound file, please use sample sounds from windows. As I mentioned it is working same on flash / GLWF or android target that is suprising me the most. |
| ||
What if the sound file has a bunch of silence at the beginning? What if it's encoded in a way that causes monkey to do something strange in a way that my sound file might not exhibit. Also, I'm not running Windows. So please post an example sound file so we can all work from the same files. |
| ||
here it is a source sound https://sites.google.com/site/cosalaeu2/Home/militaria-i-wojsko/click.wav and output sounds recorded from phone (android): https://sites.google.com/site/cosalaeu2/Home/militaria-i-wojsko/out.wav of course mp3 and ogg version are the same |
| ||
For me, running HTML5 in Safari the sounds are exactly spaced, well as far as my ears go (I can hear the problems in your Android recording), but now and again one beat is missed entirely. There is also a period of time when the page loads where timing is very wrong, but it settles down to a steady beat quite quickly. As a test, if I reduce the update rate to 2 (to beats per second) then Safari is rock steady and doesn't miss any beats. If I put it at 4, it is rock steady but misses some beats. Chrome and Firefox are noticeably less accurate on my setup. Perhaps the PlaySound code is tripping over itself if sounds are played more often than every 0.25 seconds? or perhaps the time resolution is not accurate enough. I would file this as a bug with Mark so at least he looks at it more closely. Maybe he can shed some light? Here is the code I am running: Also, just so you're aware, when I convert (no editing of the sound in any way) click.wav to click.mp3 I get the following periods of silence introduced at the beginning of the sound: iTunes 10.4, 0.024 seconds http://cl.ly/440B2X413A0k0k1L2B2I SoundBooth CS4, 0.0275 seconds http://cl.ly/310x3t320o0k200k2h2w So I'd be interested in how you convert your mp3s to remove this phenomenon. I also saw the same thing with m4a files, but ogg had no such silence introduced in my experience. |
| ||
hmmmm i didn't notice this silence part at the beginning but its true. I am using audacity with standard lame codec. Anyway i have same issue on ogg file on android when this mp3 bug does not exist. Can we please move this issue into bug subforum ? something is wrong with playsound. Thanks ! |