0
votes

I wanted to make live drums play with keyboard shortcuts. The problem was that MP3 is not good enough in this case (encoders adds random silence at beginning of the sound) and also flash itself makes delay (I tried use already buffered file with play(specified_start_point_in_miliseconds)). So my solution is OGG (this format is gapless). I use compiled swc file from Adobe Alchemy library and simple frontend for it. Everything works fine, OGG file is playing, but its still much delay - no matter if its lodeaded external or as embedded, and if its first or n time. I need a solution, how to make sound play fast equally to key press. Here is my very simple example code:

import flash.display.Sprite;
import flash.events.*;
import flash.utils.ByteArray;
import flash.events.SampleDataEvent;
import com.mauft.OggLibrary.OggStream;
import com.mauft.OggLibrary.OggEmbed;

public class ogg extends Sprite
{

    [Embed(source="/drumssnare2.ogg",mimeType="application/octet-stream")] private var OGG_FILE:Class   //Embed Ogg file as binary stream

    public function ogg()
    {
    var gameinfo:Sprite=new Sprite();
    gameinfo.graphics.beginFill(0x000000,1);
    gameinfo.graphics.drawRect(0,0,240,16);
    gameinfo.graphics.endFill();
    gameinfo.addEventListener(MouseEvent.CLICK, playOGG);
    addChild(gameinfo);
    //var streamTest:OggStream=new OggStream("http://127.0.0.1/~7z/drumssnare2.ogg");

        var embedTest:OggEmbed=new OggEmbed((new OGG_FILE) as ByteArray)    //Create new instance of OggEmbed

        function playOGG():void
        {
        //var streamTest:OggStream=new OggStream("http://www.vorbis.com/music/Hydrate-Kenny_Beltrey.ogg")

        //streamTest.play(0);
        embedTest.play(0);

        }
    }
}
1

1 Answers

1
votes

I was having the same problem with audio files in my Flash CS5.5 project with loops. Me and my audio director spent too much time to find a fast and "gapless" solution for loops in as3. He made a .aif file without any gap and I imported it in my library, calling from my Main class. Then, we changed the sound properties and seems like this:

http://s7.postimage.org/6me47lfzv/Screen_shot_2012_02_06_at_4_35_15_PM.png

in actionscript I call the .aif file like this:

var aifSound:AifSound = new AifSound(); 
//AifSound is the name of the file in the ActionScript tab

//creates a new Sound Channel
var scAif:SoundChannel = new SoundChannel();
scAif = aifSound.play(0,999, 1);

ok, it gives me a loop without a gap, delay or perfomance complications. Try it and post a feedback!

ps.: sorry about my bad english

Thank you stackoverflow!!