Discuss Scratch

karinleek
Scratcher
4 posts

Delayed sound (play drum)

My browser / operating system: Windows NT 10.0, Chrome 70.0.3538.67, Flash 31.0 (release 0)

Hi, I am not sure if this is a bug or if it is expected behavior. But I'll ask anyway. My sincere apologies if this is in the wrong topic.

I made a rhythm recognition game in which the user has to guess if the pattern played is made up out of quarter notes and/or eighth notes . Now the rhythm is sometimes delayed. Especially above 75 bpm the delay becomes really noticable and pattern recognition is harder. Is a delay expected when using play drum? Or is it my code.

The pattern is randomly generated and stored in a 4-item list that contains 1's (quarter) and 2's(eighth).

When the “play rhythm” button is clicked, the rhythm will be played.

the beat(duration) is “60/bpm”
if the first list item is a quarter note, it is played for “beat” seconds
If it is an eighth note it is played twice for “beat/2” seconds

The same logic applies to list item 2, 3, and 4. Especially the eighth notes can be delayed. But they are not always delayed.

Is this behavior expected? And if so, why? Is it the code? Is it my compuer? Can it be the internet connection speed? Is there a workaround that you know of?

Thanks in advance.



TheLogFather
Scratcher
1000+ posts

Delayed sound (play drum)

You can't really rely on blocks getting run with such a precise timing, for various reasons.

Scratch tells Flash to use a frame-rate of 30 per-second, which also means that's the typical rate that loops run at – and Scratch tells Flash to allow a screen refresh at the end of each pass through all loops. That means it can be nearly 1/30th second before it starts the next pass through a loop, hence causing a potential delay of nearly 1/30th sec before it starts the next sound/note/drum block in your repeat loops.

Even if above were not the case, your computer has to share time between lots of different apps, so it's always possible that it'll happen to end up spending a bit of time on another app at the point between two blocks – causing a slight delay.


If you want to ensure that a sound/note/drum starts at the correct time then you should use the timer (or “days since 2000”, multiplying by 86400 to give seconds, since there's a bug in the current v461 version of the Scratch player that means the timer isn't always reliable under certain situations), and play it when it reaches the required time.

Hope that helps!

Last edited by TheLogFather (Nov. 1, 2018 16:03:44)


Siggy the Kumquat slayer:
Main account: DadOfMrLog –– Frameworks for basic pen-rendered 3D in scratch (see studio). Examples:

- - - - 3D Text - - - - - - Simple shapes - - - Controllable structures - - - On the ground - - - - - - In space - - - -

karinleek
Scratcher
4 posts

Delayed sound (play drum)

You have certainly helped. The timer works sooooo much better! Thanks a lot!

Powered by DjangoBB