Looping sound

Share your ZGE-development tips and techniques here!

Moderator: Moderators

Post Reply
User avatar
Rado1
Posts: 770
Joined: Wed May 05, 2010 12:16 pm

Looping sound

Post by Rado1 » Sun Aug 31, 2014 4:45 pm

If wanted to achieve seamless looping of a relatively short sampled sound (e.g. ticking of watches), the first thing coming to mind is usage of looping Timer of which Interval is set to the length of the Sound. Unfortunately, this does not work properly as demonstrated in the attached example sound_test1.zgeproj. (For illustration I used a generated sound, not a sample.)

I came up with a trick: setting the Sound.Length to a very high number causes seamless looping of the sample when used in PlaySound. The problem is stopping of such a sound... but if you set the Sound.Length to 0 and play the sound again, it is stopped. Of course, both sound playings must have the PlaySound.ByReference set to 1 (true). This is illustrated in example sound_test2.zgeproj, which stops the looping sound, of length 1 second, after 5 seconds.

I'm not telling this is the ideal solution, but it works. BTW has anyone a better trick for seamless looping of short samples?
Attachments
sound_test2.zgeproj
correct sound looping
(1008 Bytes) Downloaded 156 times
sound_test1.zgeproj
incorrect sound looping with Timer
(608 Bytes) Downloaded 158 times

Post Reply