flixel icon indicating copy to clipboard operation
flixel copied to clipboard

FlxSound looping on native has audible glitch between loops

Open JoeCreates opened this issue 10 years ago • 5 comments

I have sounds which I have made to loop seamlessly. On flash they loop fine, but on native there is an audible but very brief pause between loops. It is slightly noticeable on windows, but extra noticeable on mobile.

JoeCreates avatar Nov 26 '14 14:11 JoeCreates

I've also struggled with seamless loops recently, and I don't think it's truly fixable, just like the sound lag on Android issue. There are some things you can try, like:

  • Using .wav/.ogg/.m4a files in hope for a better result,
  • OpenFL: Using sound and not music (streaming makes it worse as I understand it),
  • (Especially for Android) Making the sounds mono channel with 44100 Hz sampling rate seems to have some kind of benefit,
  • Keeping the sound channel open by keep playing a mute sound may help (in theory it takes less time to trigger the sounds after):
silence = Assets.getSound("sounds/silence.wav");
silence.play(0,99999);
  • Using tricks to make the user less aware to the bug (longer music for example).

On HaxeFlixel's end I had an idea of using the time property (over FlxSound) to compensate for lag (make loop + necessary delay implementation) but decided to just ignore the problem like I always do :)

sruloart avatar Nov 26 '14 15:11 sruloart

There's a similar problem regarding playing music on Android but it seems to be OpenFL specific and it's been reported on Github some time ago. It can by mitigated by using .WAV file (at the expense of file size) until it's solved.

goshki avatar Nov 27 '14 11:11 goshki

I'm inclined to believe that this is an OpenFL, not a Flixel issue (since SoundChannel#play() is the one doing the actual looping).

Gama11 avatar Feb 07 '16 20:02 Gama11

@Gama11 Can we reopen this please? There remains to be an issue in flixel even on flash, although on flash you require like a pure wave to really hear it. SoundChannel#play() is not the thing doing the looping. Flixel implements its own by restarting a sound once it has finished.

The old flash way of creating a seamless loop was just setting the loops number to really high iirc.

// No glitch
var sound:FlxSound = FlxG.sound.load("assets/sounds/beeploop.mp3", 1, true);
var s:Sound = sound._sound;
s.play(0, 10000);

// Glitch
var sound:FlxSound = FlxG.sound.play("assets/sounds/beeploop.mp3", 1, true);

JoeCreates avatar Nov 15 '18 09:11 JoeCreates

I'm requested that lime issue be reopened also.

I have been able to eliminate the delay on both flash and native.

On flash it required only that I get the flash Sound and set the number of loops instead of using flixel's looping, which introduces a slightly delay.

On native, I had to do this AND bypass lime's built in looping to use openAL directly, setting AL_LOOPING to 1 on the source.

So basically, both flixel and lime are responsible here. Both implement their own looping and each implementation adds (a frame of?) delay between loops.

JoeCreates avatar Nov 16 '18 09:11 JoeCreates