I'm trying to play gapless loop using mp3 file. I've read some tutorials and learned there is something like encoder / decored delay and it is possible to fill that gap with proper music data using some tools. It even worked fine, but when I'm trying to play that music in flash (haxe nme actually, but I don't think it makes any difference), I discovered there is another delay, which is, I guess, made by flash.media.Sound (well, found some comments like this in the code in the internet actually).
Sooo, because I sometimes need to play sounds faster or slower, this is how my player works:
- extraced bytes are stored in bytes var
- speed is a float var, default = 1
- there is position var indicating actual position in bytes (bytes are shared by many sound objects so I can't easily use bytes.position)
- when I'm playing the sound, in the SampleDataEvent handler, I set bytes.position = position * 8, then read and play two floats and updating position += speed
If I'm doing something wrong already - please, point it out.
To get rid of that delay, I tried to:
- add DELAY var
- hardcode the length of sound read from audacity (it looks like flash.media.Sound object.length is not accurate, I'm not sure but I guess because of mp3 decoder/encoder delays)
- make an assumption each sound is 128kbps, 44.1kHz
- set DELAY so flash.media.Sound object bytesTotal - DELAY = hardcoded length * 128kbps
It playes, but:
- mp3 from audacity still has annoying gap.
- mp3 from the tool filling mp3 gap (from here http://www.compuphase.com/mp3/mp3loops.htm) is playing better, but sound at the beginning is not clear.
- I can hear annoying "click" noise after stopping sound.
Can you help me understanding why (1) happens and how to solve all 3 problems?