Is it possible?
I have some mp3 tracks that combine and loop but the gap is destroying is.... any help?
Is it possible?
I have some mp3 tracks that combine and loop but the gap is destroying is.... any help?
you might want to try using the sound object to play the sound so you can define how many times it would loop and I think the native looping system is much much more seamless than the way the SoundManager currently does it
sorry for what you have to go through :
import citrus.citrus_internal; var realSoundObject:Sound = _ce.sound.getSound("loop").citrus_internal::sound; realSoundObject.play(0,999);
yeah I'm using the sound manager... but not sure if I want to replicate all CE functionality and improve it.... maybe that bit should be improved...
Maybe we can have the option that if you choose to repeat 999 times, then it uses a different mechanism on the soundmanager. For 999 times in a game is almost infinite. Who is going to want to repeat a sound 999 times and not really forever?
EDIT: Fixed text.
This was created to track down how many loops we already played so that when you paused at 12,2 and you needed to do 15, then you would start back at 12,2 .
But I guess when we need infinite loops, we can use the other way, you're right.
(I'm currently working on the SoundManager in fact.)
Yeah that way should be gapless or near it. In theory looping with event is also gapless, the silent part in between the end and start of sound is the latency, really just the latency (if you have never witnessed the high latency of the AS3 Sound API is here you have it).
ASWC, would the perfect solution be extracting the sound (either in full or progressively) to write the sound to the buffer (or event.data) to loop back when needed ? if so I wouldn't put that in as a default looping system - I'm afraid of the performances involved
gsynuh, it would be perfect yes except at the start where the latency would show (SmapleDataevent generates a higher latency).
Jaime, unfortunately flash latency is random so on each loop you'll never know how much gap you'll have to fill.
EDIT: I checked the article you posted, it's AS2 code. Prior to FP9 there was no latency problems with sounds in the AS2 Sound API. Starting with FP9 we got stuck with latency using the Flash Sound API.
Also don't forget that mp3s have often silent added at beginning and end (this comes with the format). Make sure you edit your mp3s correctly to remove as much as possible of those silent parts.
If you are talking about mp3 files that are loaded dynamically then the glitch loop you hear is an artefact of the mp3 encoding algorithm and nothing to do with flash looping mechanism. There is a workaround if you use Lame encoder, you need to use a 'magic number' offset, as Lame always produces the same amount of silence at the start.
If you are actually talking about library assets that are in uncompressed format (ie flash does the compressing to mp3 itself when you publish your swf) then flash works around the looping glitch issue by keeping track of how much silence is added automatically, in which case it really could be some other issue so ignore me.
library assets that are in uncompressed format (ie flash does the compressing to mp3 itself when you publish your swf) then flash works around the looping glitch issue by keeping track of how much silence is added automatically
This is the best way I found to use looping music in the Flash runtimes. Import an uncompressed WAV into the Flash Pro library and give it a class name. If you're using another IDE, you can export it as a SWC. Flash Pro has some non-standard magic that omits the silence when the audio is converted to MP3.
Yeah, but Im using normal assets, Im using flash but is nothing like flash... Stage3d: no timelines, no vectors, no SWCs, just JSONs, PNG atlases, JPG,PNG,mp3 XML, and common things like that ... I dont want to need flash to create SWC files.
That seems like kind of a strange response to me. I don't use Flash Pro for many of those features either, but it's a tool in my toolbox, and I found that it worked well as an easy hack for creating loopable MP3s without silence. It's not like I'm advocating that you switch over to Flash Pro for everything. SWCs aren't meant for just Flash Pro. Most libraries are distributed as SWCs that can be used in any environment, including Flash Builder, IntelliJ IDEA, and others. It's definitely "normal".
Well, I'm loading everything on the fly in Flash and AIR. and I will do it in more systems, maybe iOS will revert their silly policy and deny again the SWC to be loaded. so I got fed up with it and use everything as standardized as possible. If there is no other option I will have to do it that way, but I just hope I can get a solution using non flash tools. The least dependant I am from Flash Pro the better.
I use SWC which is alright for code , but I definitely don't want to embed 16 tracks of music to the SWF.
You can embed a few sounds but the more you have sounds and the bigger they are, the less embedding sounds like a good solution.
Anyway, in my experience, all those little tricks bring very little improvements. I tested them all and I found it difficult to see any difference in latency response. You have, embedding mp3 as Josh said, you also have playing a silent sound at all time, you also have embedding as .wav instead of mp3. You probably can find articles about those technics online and their latency improvement claims but like I said in my tests I never really saw any kind of latency improvement.
Gap-less looping with mp3s has nothing at all to do with latency.
If you load the mp3 into any decent audio editor you can clearly see that a few milliseconds of silence get added at the start of the audio data as part of the encoding process. ie, there is no silence in your .wav file, but when you compress it to .mp3 it now mysteriously has 50 ms of silence at the start. This is what causes an audible glitch when it is played on loop (in any audio player software, not just in flash). I think I heard somewhere once that the silence is actually caused by data that is supposed to be part of the file header being interpreted as part of the audio content or something stupid like that.
Latency is a completely different matter altogether.
Maybe we went a bit off subject but the question was about looping with the citrus sound manager so I'm still on that target and the difference between using repetition number when playing a sound vs event.complete and playing again. In that case the silence added at beginning and end of mp3 is part of the problem but is not the only problem.
Actually, I don't recommend embedding MP3. My recommendation was putting a WAV file into the library of Flash Pro and exporting it as SWC (or you could export a SWF too, which could possibly be loaded at runtime). Flash Pro converts the WAV to MP3, but somehow, it can play back without the silence that other MP3 encoders like Lame add. In my experience, music will loop seamlessly this way.
I usually use Sound's play() with a loop count set to int.MAX_VALUE, if I want it to repeat indefinitely. I've never tried manually playing again on Event.COMPLETE, but I definitely wouldn't be surprised if that added a gap.
I'm working on a new sound manager to introduce the following features : being able to play one sound more than once at a time - this didn't exist anymore after I came in and played with the sound manager's code - sorry about this.
I'm still controlling loops using the COMPLETE event in my current version,
But reading you I thought I could do the following :
- if loops = 0 , then play once.
- if loops = 24, play 24 times (excluding the first play) , looping with the COMPLETE event to count what the current loop is (necessary for pause/resume to work correctly right?)
- if loops < 0, then play indefinitely using sound.play(0,int.MAX,...)
is that alright when it comes to what we can do on our side?
I'm sure you could find a way to count the current loop without having to use the complete event to control the looping. 2 ideas you could investigate:
1) I haven't checked this myself, but does the complete event fire when it gets to the end if even if the sound is set to loop? (Maybe not, but worth double checking)
2) you could poll the current playback time every second or so, and if at any point it is less than it was on the last check this means the sound has just looped so increment your current loop counter.
gsynuh, I think that would work just fine. Alternatively you could offer a Boolean variable to switch between the two ways.
Josh, Event.COMPLETE does not add a gap, the Flash Sound API high latency does and that's the core of the problem.
Due to the "elastic racetrack" nature of Flash/AIR runtime execution, getting millisecond accuracy to loop is next to impossible. Say you know your loop is exactly 1000ms long, and on the complete event you restart it. Your event will never arrive exactly at 1000ms, it will arrive some time after, making it impossible to fire another sound instance at exactly the right time.
My solution was to add a half second of silence to the beginning of my loop (in the file itself) and set up a recurring timer that fired a bit before the actual loop point, that would poll how "off" the runtime execution was from the expected timestamp, and then play it at a certain position into the silence so that the actual sound would start playing just as the other loop was finishing up. Haven't done this in the mobile space yet but it got pretty good results on the web.
I didn't say Event.COMPLETE is the exact cause of the loop. If I had intended to go into more detail, I would have mentioned the elastic racetrack nature of the Flash runtimes, like Jonathan Hart did, and that many events are queued up for a new frame rather than dispatched immediately. If the audio length doesn't match up well with the frame duration, or a frame runs long, I'd expect it to cause gaps.
If you have more information about the Flash runtime internals, perhaps specific to sound APIs, that shows this explanation is wrong too, I'm happy to be corrected, of course.
Those are valid points but at the end we are limited to what a human ear can catch. It is said that non trained human ears can catch a 40/50ms gap while extremely trained ears can catch as low as 15/20ms gaps. While as I said your points are valid I really doubt that a human ear can catch the time it takes for the Event.COMPLETE to be dispatched, caught, and a new sound to be played (assuming no latency). I'm only assuming that operation would take less than 15ms as I have never tried to measure it. If it doesn't that would be a shame for Flash.
Anyway it is all theoretical but for me using Event.COMPLETE in theory should work fine. It's just that an accumulation of time waste makes it inaccurate. A few Flash runtime ms loss, adding a few mp3 ms at end of sounds, adding a few ms latency loss, at the end that makes a lot of lost ms.
Just use the SampleDataEvent and call it a day.
The right way to do this in Flash (which kinda sucks) is:
1) Combine all the tracks in one mp3
2) do the following
var mp3:Sound = // obtain sound object
That way you won't be experiencing gaps
That's not possible, can you imagine loading 16 tracks of music ahead?
whether you are running low on resources or not. For instance we're making a game that has tightly filled all available resources we may utilize. But if you have a lot of memory available, you can do that.
No, I make smartphone games.
So, whats happening after all. Is the soundmanager beeing improved?
Should i get it from GIT now?
You must log in to post.