SoundChannel.position inaccuracies within SampleDataEvent.SAMPLE_DATA

The application generates sound dynamically by handling SampleDataEvent. It needs to determine exactly what part of the sound was actually playing when a click was made.
Unfortunately, the latency calculation is slightly off because SoundChannel.position seems to be returning values that are +- 20 milliseconds off. The attached class demonstrates the issue by using a timer to occasionally check the position against the current time, displaying the difference between the two, along with the range of differences over time. The timer fires as often as it can so different ranges can be seen by using different movie frame rates.
I'm not sure why this is, but I'm guessing it's something to do with the fact that the sound buffering is happening in a separate thread. Perhaps this thread only periodically updates the main thread about its position?
Is there any more accurate way to calculate latency? Or maybe some way to know just how much the position value with be off at any given time?

The application generates sound dynamically by handling SampleDataEvent. It needs to determine exactly what part of the sound was actually playing when a click was made.
Unfortunately, the latency calculation is slightly off because SoundChannel.position seems to be returning values that are +- 20 milliseconds off. The attached class demonstrates the issue by using a timer to occasionally check the position against the current time, displaying the difference between the two, along with the range of differences over time. The timer fires as often as it can so different ranges can be seen by using different movie frame rates.
I'm not sure why this is, but I'm guessing it's something to do with the fact that the sound buffering is happening in a separate thread. Perhaps this thread only periodically updates the main thread about its position?
Is there any more accurate way to calculate latency? Or maybe some way to know just how much the position value with be off at any given time?

Similar Messages

  • SoundChannel.position won't reset

    I'm trying to play an audio that goes along with the text on the screen.  As the audio plays, a timer event handler checks the SoundChannel.position to see determine what text should be highlighted. In my application I have a few audios that play in succession.  When one ends, the SoudComplete event is fired and I start playing the next audio.  I create a new sound object and reset the timer, but for some reason, the SoundChannel.Postion is off.  Here is my code:
    private function soundComplete(evt:Event):void
    //unHighlightSegment(this.curSegment_int);
    //timer.removeEventListener(TimerEvent.TIMER, highlightNext);
    //timer.stop();
    oSoundChannel.removeEventListener(Event.SOUND_COMPLETE, soundComplete);
    /*oSoundChannel = null;
    oSound = null;*/
    //timer.reset();
    if(this.toggleFull_bl && (curSegment_int+1 < this.dialogueText_ary.length))
    if(this.normal)
    playAllNormal(curSegment_int+1);
    else
    playAllSlow(curSegment_int+1);
    return;
    dialoguePlaying = false;
    firstPlay = true;
    isPaused = false;
    stopPlaying();
    playDialogue_btn.gotoAndStop("playUp");
    //plays the entire audio
    private function playAllNormal(seg:uint):void
    //trace(audiosToPlay_ary[curDialogue_uint] + "_nml.mp3");
    //soundEnd = true;
    timer.stop();
    timer.reset();
    timer.removeEventListener(TimerEvent.TIMER, stopVocalPlayback);
    timer.removeEventListener(TimerEvent.TIMER, highlightNext);
    trace("playAllNormal", seg);
    try
    trace("stop audio");
    oSoundChannel.stop();
    catch(e:Error)
    trace("Sound Channel object not yet created");
    var temp:int = dialogInfo.Segment[seg].Dialog;
    trace(String("CurrentDialog"), temp);
    oSound = new Sound(new URLRequest(audiosToPlay_ary[temp] + "_nml.mp3"));  //Create a new sound
    oSoundChannel = oSound.play(uint(audioTimes[temp].Time[dialogInfo.Segment[seg].Seg]));  //Play the sound and assign this to oSoundChannel
    trace(audiosToPlay_ary[temp] + "_nml.mp3", audioTimes[temp].Time[dialogInfo.Segment[seg].Seg]);
    oSoundChannel.addEventListener(Event.SOUND_COMPLETE, soundComplete);
    oSoundTransform.volume = volumeLevel;
    oSoundChannel.soundTransform = oSoundTransform;
    trace("Sound position just after play", oSoundChannel.position);  //oSoundChannel.position should be close to zero here.
    timer.addEventListener(TimerEvent.TIMER, highlightNext);      //add the timer event to check the soundchannel position
    timer.start();
    private function highlightNext(evt:TimerEvent):void
    var len:uint;
    len = this.dialogueText_ary.length;
    if(normal)
    if(curSegment_int+1 < len)
    if(oSoundChannel.position >= uint(audioTimes[dialogInfo.Segment[curSegment_int].Dialog].Time[dialogInfo.Segment[curSeg ment_int].Seg]) && oSoundChannel.position < uint(audioTimes[dialogInfo.Segment[curSegment_int].Dialog].Time[dialogInfo.Segment[curSeg ment_int].Seg+1]))
    highlightSegment(curSegment_int);
    var a:int = 1;
    else  //if the position is not within range, highlight the next segment and increment the curSement counter
    unHighlightSegment(curSegment_int);
    curSegment_int++;
    trace("highlightNext", curSegment_int, oSoundChannel.position);
    else if(curSegment_int+1 == len)
    highlightSegment(curSegment_int);
    else
    if(curSegment_int+1 < len)
    if(oSoundChannel.position >= uint(audioTimes[dialogInfo.Segment[curSegment_int].Dialog].TimeSlw[dialogInfo.Segment[cur Segment_int].Seg]) && oSoundChannel.position < uint(audioTimes[dialogInfo.Segment[curSegment_int].Dialog].TimeSlw[dialogInfo.Segment[cur Segment_int].Seg+1]))
    highlightSegment(curSegment_int);
    else
    unHighlightSegment(curSegment_int);
    curSegment_int++;
    else if(curSegment_int+1 == len)
    highlightSegment(curSegment_int);
    here's the output I get:
    JAN_2000_Claudia1_TYE_Cesar_1.1_nml.mp3 42440
    Sound position just after play 42440
    highlightNext 16 45458.59410430839
    highlightNext 17 47687.70975056689
    highlightNext 18 47780.589569161
    highlightNext 19 47873.4693877551
    highlightNext 20 47919.90929705215
    highlightNext 21 48059.229024943306
    highlightNext 22 48152.10884353741
    highlightNext 23 48244.988662131516
    highlightNext 24 48337.86848072562
    highlightNext 25 48430.748299319726
    highlightNext 26 48523.62811791383
    highlightNext 27 48570.06802721088
    highlightNext 28 48662.947845804985
    highlightNext 29 48802.26757369615
    highlightNext 30 48895.14739229025
    highlightNext 31 48941.5873015873
    playAllNormal 32
    stop audio
    CurrentDialog 1
    JAN_2000_Claudia1_TYE_Cesar_1.2_nml.mp3 35015      -- This is where things go wrong
    Sound position just after play 35014.988662131516          --sound position should be zero here.  Because it's not zero, the position is out of range 
    highlightNext 32 35061.42857142857                               --and the curSegment counter is incremented and the highlighted segment skips ahead too
    highlightNext 33 36315.30612244898                               --far
    highlightNext 34 38962.380952380954
    highlightNext 35 39055.26077097505
    highlightNext 36 39101.70068027211
    highlightNext 37 39194.58049886621
    highlightNext 38 39241.02040816326
    highlightNext 39 39380.34013605442
    highlightNext 40 39426.78004535147
    highlightNext 41 39519.65986394558
    highlightNext 42 39566.099773242626
    highlightNext 43 39705.41950113379
    highlightNext 44 39798.29931972789
    highlightNext 45 39844.73922902494
    playAllNormal 46
    stop audio
    CurrentDialog 2
    JAN_2000_Claudia1_TYE_Cesar_1.3_nml.mp3 28812
    Sound position just after play 28811.995464852607          --again here the position should be 0
    highlightNext 46 28858.43537414966
    Any ideas on why the position is not close to zero just after I begin playing?

    Somewhere between the sound ending and the firing of the soundComplete event, the timer still keeps counting and firing the timer event.  Any suggestions on how to stop the timer?  I already call Timer.stop() and Timer.RemoveEventListener when the sound complete fires, but the timer still has time to fire several times before I can stop it in the SoundComplete event handler.

  • [AS3.0]SoundChannel.position≠Sound.length

    別の掲示板の引用で恐縮ですが、まさにこの問題に直面しています。
    http://www.flash-jp.com/modules/newbb/viewtopic.php?topic_id=7819&forum=8&post_id=38874#f orumpost38874
    上記サイトで書かれていますが、
    「 Firefox 2.0.0.14 & Internet Explorer 7.0/Windows Vistaで確認したところ、SoundChannel.positionプロパティの値がSound.lengthの値に達しないという問題が生じました。」
    の問題に対する、解決策、回避策などはございませんでしょうか。
    AS3.0+Vistaの環境では、mp3の再生に合わせてバーを伸縮させるスライダーようなものは作れない、なんてことはないと思うのですが・・・
    再生終了時のpositionの値がlengthの値と同じにならなくても、その終了した時の値が、再生前に分かれば問題ないのだと思うのですが、そのようなことは無理でしょうか。
    その他、何か情報がありましたら、ぜひよろしくお願いいたします。

    Thanks Andrei.
    But I really dont understand. You see, I am not too good (actually pretty bad) with Ationscript 3.
    Att.,
    Edwin
    I managed to get it to move each second though with this:
    var myTimer:Timer = new Timer(1000);
    myTimer.addEventListener(TimerEvent.TIMER, runTimer);
    myTimer.start();
    function runTimer(event:TimerEvent):void {
    trace("Hello");
    progreso.value = progreso.value+1;

  • Microphone.addEventListener(SampleDataEvent.SAMPLE_DATA) Causes output volume to decrease

    I would like to record sound from the microphone in AIR.
    This is working, except that while recording, AIR reduces the volume of all playing sounds.
    This volume reduction is triggered by
    microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, myFunction);
    It should be noted that myFunction() can be completely empty. The output volume is still reduced.
    How to reproduce:
    // Start playing a sound
    var url:String = "100Hz_44100Hz_16bit_30sec.mp3";
    var urlRequest:URLRequest = new URLRequest(url);
    var isound:Sound = new Sound();
    isound.load(urlRequest);
    isound.play();
    // Set up the microphone
    var microphone = Microphone.getMicrophone();
    microphone.setUseEchoSuppression(false); // I have tried both ways.
    microphone.setLoopBack(false); // I have tried both ways.
    microphone.rate = 44;
    // Start recording
    microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
    // The volume of 'isound' will now be reduced until the microphone listener is removed.
    // Once the listener is removed, the volume of 'isound' returns to normal.
    I do NOT want the volume of other playing sounds to be reduced while recording. How might I do this?
    Note: I am using Windows 7.

    I believe reducing volume on mic record is a Windows 7 feature and nothing to do with Air.
    To disable this, take the following steps:
    Click Windows button
    Choose Control Panel
    Choose "Hardware and Sound"
    Choose "Manage audio devices" under the "Sound" heading
    Goto the "Communications" tab
    Set "When windows detects communications activity" to "Do Nothing"
    Even though that setting says it's supposed to adjust volume when placing telephone calls using you computer, I have had it reduce volume in some programs when i activate the microphone.
    Let me know if that works for you.
    Edit:  Heh, was reading some other recent forum posts to see if there was anything else I could help with.  The thread "2 flash instances & Windows 7" currently a few below this one on the front page mentions this Windows 7 Feature, although it's causing a different issue for him.

  • SoundChannel position

    Why isn't the end position of a sound channel the same as the length of a sound?
            public function play():void
                soundChannel = sound.play();
                soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
            private function onSoundComplete(e:Event):void
                var endPosition:Number = soundChannel.position;
                var length:Number = sound.length;
    If you test the previous code you will see that the position of the soundChannel when SOUND_COMPLETE is dispatched is different then the length of the sound.
    Why isn't the soundChannel play all the sound? Why does it stops earlier? and how can I find the end position of the soundChannel without playing and listening to the SOUND_COMPLETE event?

    imnikey,
    I see no one has answered your question.  I don't have an answer either, but I'm experiencing similar problems with the SoundChannel position. The problem with tracking the sound object's position through its sound channel gets worse when there is more than one Flash movieclip open in a different browser window.  Opening a Flash audio player seems to work fine if it is the only Flash movieclip open on my desktop.  After I open another Flash object in a separate window, the audio player fails to properly track the SoundChannel position, and fails to correctly fire the SoundComplete event.
    Anyone else experiencing these problems?  Has anyone been able to find a reliable method for tracking the sound channel position with more than one Flash movieclip open on the desktop?  Is this a known issue or bug with the Sound API for Flash Player 10?  We could really use some answers.
    jazzsurfer

  • Assigning position hierarchy within Org Model

    Hi,
    have maintained the org model with sales org and position in crm 5.0. This position is President sales and would like to maintain General Manager under this position as a subordinate. While doing so, I get the following message:
    <b>Before you select a function, select suitable entries in the structure.
        Message no. 5W707
    Diagnosis
        You have chosen a function for which a selection of  suitable entries in the structure is a prerequisite.
    Procedure
        Select one or more suitable functions in the structure and choose the function again. You can use the right mouse-button to display all the functions you can carry out for an entry.</b>
    What else am I missing here
    Thanks
    Kumar

    Hi Diana,
    Thanks for the inputs. I have rewarded points.
    As per your mail, we could maintain two positions under single organization unit one with the 'head of org unit' check and the other without that. Now they both appear under the same org unit but they appear as two positions (only difference is that the icons are different).
    What I am looking at is, Sales Org 1 should have a sub tree (arrow mark) with Mgr Director position, when I drop down this positions arrow mark, then I only I should be able to see the General Mgr's position (the GM's position should not appear parallel to the MD's position on the tree structure but should be within the MD's position)
    Can we assign any position to the head position by any standard means ?
    Hope you got my requirement clear, else let me know I can explain in more detail.
    Thanks
    Kumar

  • How to obtain position/view within PDF

    There is much information regarding how to open a PDF at a particular page etc. from the command line.
    How can the data be obtained and stored externally while reading the document.
    Perhaps more precisely, if I edited a page and then later wanted to open the PDF at a specific edit from, say, a shortcut, because I don't wish to write down the page number how might I go about obtaining the data to add to the shortcut command line?
    Thank you

    Thank you.
    I have read from the link you provided but it only tells me what I knew regarding how to achieve this manually not programmatically.
    I can see that I have not explained very well.
    I wish through external means (a program/script I will write), to click a button at any time and multiple times, while reading a PDFand have the program obtain (from somewhere/anywhere/even Windows itself) the position I am at while reading a PDF and inject it into a url.
    The end result will be a list (in an HTML page?) of the url's I have saved. i.e. the same as internal bookmarks but external.
    The information exists because a PDF can be re-opened at the current page when closing by it saving that information.
    I do understand that I can do it by noting the position myself and injecting it.
    Useage example:
    While editing video's I am reading from several PDF's at the same time, with differing viewpoints, and at various stages I want to bookmark and make a comment from whichever PDF my eyes are on (thus effectively at random).
    Doing it within the PDF does not tell me (later, externally) which PDF or the order in which the bookmarks were made, if I wish to recreate the learning process.
    All I can at present do is open each PDF and got to its various bookmarks out of sequence both within the book and choice of book.
    Clearly the bookmarks need to appear in a list in the order created and each must select the appropriate book and page within that book. Then the previous session's progress can be recreated.
    Perhaps it is now clearer.
    I can write the program but where do I obtain, programmatically when I click the button, the current PDF title (file url) and page number within it, to place in the list of url's?
    Any suggestions please

  • Position parameter within 3D nested groups?

    I have a total of six drop zones in 3D space. They are vertical, while the animated background is slanted in the x-axis beneath them. I'm getting a little confused as to the x, y, z coordinates of the drop zones, as they do not seem to be relative to the 0,0,0 xyz coordinates of the canvas. Is there a way to take a screenprint of the canvas and layers tab for me to post? Until then, here is how the nesting looks within the layers tab:
    -user content
    -drop zone 3
    -drop zone 3 portrait
    -drop zone 3 landscape
    -drop zone 2
    -drop zone 2 portrait
    -drop zone 2 landscape
    -drop zone 1
    -drop zone 1 portrait
    -drop zone 1 landscape
    I have the entire user content group dropping vertically down, and then animate each of the drop zones. My confusion comes in that I've been keyframing the positions, which I find easier than the record button. But, the positions of the individual portrait and landscape drop zones seem to take their 0,0,0 relative to the position of the group they are within, rather than the absolute zero of the canvas. For instance, when drop zone 3 appears to be right in the center of the canvas, it's x and y coordinates are somewhere around 260, -200, which is its position relative to the user content group, not the canvas as a whole. Should I animate them all individually instead of in groups to get actual x,y,z coordinates? or does it even matter?

    I should have previewed the post as it took away the formatting for the nesting. The user content group has drop zones 1, 2, and 3 nested within it. Each drop zone group has the portrait and landscape drop zone (with applied effects) nested within it. The x,y,z coordinates of the actual drop zones appear to be relative to the top level group, rather than to the 0,0,0 of the canvas. Wow, that was a much more concise way of explaining the issue.

  • Positioning text within block

    Hi
    I am wanting to postion text within a Box/block, these are list items that I have used as navigation buttons.
    I have set the box size and have selected "center" for text positioning, this positions the text in the centre horizontally ok.
    I would like to know how to position the text centrally verticially aswell?
    Many thanks
    Mark

    Hi
    Thanks for quick answer.
    I can get the padding within a div option to work, but one of the List  items/ button texts needs different padding to the others because it is two lines of text.
    Can I differentiate the treatment of one "Li" ??
    Cheers
    Mark

  • Resizing & Positioning Children within a Panel

    I'm trying to insert an element into a Panel that has a vertical layout, and create a transition that smoothly inserts the new item in between 2 existing items in the base state of the application.  My goal is for the bottom text field to remain anchored to the bottom of the panel as the panel resizes, instead of jumping to its new position, so that the middle text input can then gracefully fade in.
    Am I just missing something in how I'm defining the transitions, or will the effects not yet account for the positioning of items from layout?  Attached is the MXML app and the compiled SWF.
    Thanks.

    This will get you what you want. There's a tricky interaction between adding the new element and the vertical layout. The third item won't make room for the second one unless the second one is actually added to the parent. But adding it will immediately make it visible, which is not what you want. So I tweaked the effect to add it but make it non-visible (alpha==0), then Resize the second element itself (the panel will resize automatically), *then* fade in the second element.
                <s:Sequence>
                    <s:SetAction target="{secondTxt}" property="alpha" value="0"/>
                    <s:Resize target="{secondTxt}" heightFrom="0"/>
                    <s:Parallel>
                        <s:Move target="{thirdTxt}" />
                        <s:Fade target="{secondTxt}" alphaTo="1"/>
                    </s:Parallel>
                </s:Sequence>
    Chet.

  • How to play sound from a proprietary format

    I would like to convert a small java applet to flex as3
    The current applet connects  to a remote server to receive audio in a proprietry compressed and encrypted format using a tcp connection (the data is encoded as text)
    It then decrypts, decompresses the audio and uses java sound to play it.
    Looking at the as3 classes all I could find is a sound object that seems to only play mp3 audio and a urlrequest object that is used to download (what about streaming) mp3 audio from a server.
    I am looking for a simple sample that will incorporate retreving data from a server (perhaps using the http service) into e.g. a byte array, and playing pcm audio from a byte array.
    Ideally it would be a small set of files (1?) that I can compile using mxmlc; I am not good with IDEs, linux command line is my thing
    Thanks

    Maciek, many thanks!
    Here's sample code showing how to stream audio in arbitrary format and play it
    // File: Player.as
    // When running from local storage (during developement)
    // compile mxmlc -use-network=false Player.as
    // otherwise loading the local raw audio file fails with error 2148
    // The input audio format is 16 bit little endian 44.1Khz mono.
    package
        import flash.display.Sprite;
        import flash.text.TextField;
        import flash.media.Sound;
        import flash.media.SoundChannel;
        import flash.events.Event;
        import flash.events.SampleDataEvent;
        import flash.net.URLRequest;
        import flash.net.URLStream;
        public class Player extends Sprite
            private var sourceUri:String = "audio.44.raw";
            private var sound:Sound = new Sound();
            private var soundChannel:SoundChannel = new SoundChannel();
            private var playing:Boolean;
            private var stream:URLStream;
            private var request:URLRequest;
            private var statusLine:TextField = new TextField();
            public function Player()
                statusLine.width = 400;
                statusLine.text = "Starting...";
                addChild(statusLine);
                getAudio();
                start();
            public function getAudio():void
                stream = new URLStream();
                request = new URLRequest(sourceUri);
                try {
                    stream.load(request);
                } catch (error:Error) {
                    statusLine.text = "Failed to load " + request.url + " : " + err!
            private function playCallback(event:SampleDataEvent):void
                var value:Number;
                var i:int, cnt:int;
                // Input is 16bit PCM, each sample occupies 2 bytes
                cnt = stream.bytesAvailable / 2;
                if (cnt >= 8192 || playing) {
                    playing = true;
                    statusLine.text = request.url + " : playing...";
                    if (cnt > 8192)
                        cnt = 8192;
                    for (i = 0; i < cnt; i++) {
                        // Convert 16bit little edndian pcm samples to numbers
                        value = stream.readUnsignedByte() + 256 * stream.readUnsign!
                        if (value > 32767)
                            value -= 65536;
                        value /= 10000; //Adjust the volume
                        // Input is mono, write to both channels
                        event.data.writeFloat(value);
                        event.data.writeFloat(value);
                    if (cnt < 2048)
                        statusLine.text = request.url + " : done...";              !
                else {
                    // Wait until enough data is bufferred
                    statusLine.text = request.url + " : buffering...";
                    for (i = 0; i < 8192; i++) {
                        event.data.writeFloat(0);
                        event.data.writeFloat(0);
            private function start():void
                soundChannel.stop();
                sound.removeEventListener(SampleDataEvent.SAMPLE_DATA,playCallback);
                playing = false;
                sound.addEventListener(SampleDataEvent.SAMPLE_DATA,playCallback);
                soundChannel = sound.play();

  • Serious Help! Handling Sound Position And Speed!

    Take a look at this: https://sites.google.com/site/pardeepgames/Untitled-1.swf. It may take some time to load, sound is 42 seconds, see the second text field for time buffering.
    I recommend reading the Source Code below first.
    Now as you can see the pitch and speed functions are working perfectly, but the problem is that when you move the slider, the songTime text field dosen't work correctly. When you raise the pitch the songTime should just speed up the counting not change it's position, same when you lower the pitch, it should just slow down the counting not change it's position. Well that isn't working for me. The Source Code is there for you below and all the information you need is in the comments in the code. Please help me out. Oh and I recommend focusing on the songTime text field and then moving the slider.
    Source Code:
    Name of the slider: "slider".
    Name of the first text field: "songTime".
    Name of the second text field: "songTotalTime".
    import flash.events.Event;
    import flash.events.SampleDataEvent;
    import flash.media.Sound;
    import flash.net.URLRequest;
    import flash.utils.ByteArray;
    import fl.events.SliderEvent;
    import flash.media.SoundChannel;
    var _playbackSpeed:Number = 2;
    var sound:Sound;
    var sound2:Sound; // Copy of the original sound, to get the right information about the sound because the pitch shifting for the original sound variable ruins it up.
    var myChannel:SoundChannel = new SoundChannel();
    var _loadedMP3Samples:ByteArray;
    var _phase:Number;
    var _numSamples:int;
    var request:URLRequest = new URLRequest("https://sites.google.com/site/pardeepgames/Not%20Afraid%20Instrumental.mp3");
    var songTimeTime:Number = 1000; // The variable that allows the songTime's speed to change accoriding to the value of the slider. See in line 32.
    loadAndplay10(request);
    addEventListener(Event.ENTER_FRAME, enterFrame);
    function enterFrame(event:Event):void
      progressBar.scaleX = myChannel.position / sound2.length;
      _playbackSpeed = slider.value;
      songTimeTime = 1000 / slider.value;
      songTime.text = convertTime(myChannel.position);
      songTotalTime.text = convertTimeLength(sound2.length);
    function loadAndplay10(request:URLRequest):void
      sound = new Sound();
      sound2 = new Sound();
      sound.addEventListener(Event.COMPLETE, mp3Complete);
      sound.load(request);
      sound2.load(request);
    function playLoadedSound(s:Sound):void
      var bytes:ByteArray = new ByteArray();
      s.extract(bytes, int(s.length * 44.1));
      play10(bytes);
    function mp3Complete(event:Event):void
      playLoadedSound(sound);
    function play10(bytes:ByteArray):void
      stop10();
      sound = new Sound();
      sound.addEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData);
      _loadedMP3Samples = bytes;
      _numSamples = bytes.length / 8;
      _phase = 0;
      myChannel = sound.play();
    function stop10():void
      if (sound)
      sound.removeEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData);
      myChannel.stop();
    function onSampleData( event:SampleDataEvent ):void
      var l:Number;
      var r:Number;
      var outputLength:int = 0;
      while (outputLength < 2048)
      // until we have filled up enough output buffer
      // move to the correct location in our loaded samples ByteArray
      _loadedMP3Samples.position = int(_phase) * 8;// 4 bytes per float and two channels so the actual position in the ByteArray is a factor of 8 bigger than the phase
      // read out the left and right channels at this position
      l = _loadedMP3Samples.readFloat();
      r = _loadedMP3Samples.readFloat();
      // write the samples to our output buffer
      event.data.writeFloat(l);
      event.data.writeFloat(r);
      outputLength++;
      // advance the phase by the speed...
      _phase +=  _playbackSpeed;
      // and deal with looping (including looping back past the beginning when playing in reverse)
      if (_phase < 0)
      _phase +=  _numSamples;
      else if (_phase >= _numSamples)
      _phase -=  _numSamples;
    function convertTime(milliSeconds:Number):String
      var Minutes:Number = (milliSeconds % (songTimeTime * 60 * 60)) / (songTimeTime * 60);
      var Seconds:Number = (milliSeconds % (songTimeTime * 60 * 60)) % (songTimeTime * 60) / songTimeTime;
      if (Minutes < 10)
      var displayMinutes:String = "0" + Math.floor(Minutes);
      else
      displayMinutes = Math.floor(Minutes).toString();
      if (Seconds < 10)
      var displaySeconds:String = "0" + Math.floor(Seconds);
      else
      displaySeconds = Math.floor(Seconds).toString();
      return displayMinutes + ":" + displaySeconds;
    function convertTimeLength(milliSeconds:Number):String
      var Minutes2:Number = (milliSeconds % (1000 * 60 * 60)) / (1000 * 60);
      var Seconds2:Number = (milliSeconds % (1000 * 60 * 60)) % (1000 * 60) / 1000;
      if (Minutes2 < 10)
      var displayMinutes2:String = "0" + Math.floor(Minutes2);
      else
      displayMinutes2 = Math.floor(Minutes2).toString();
      if (Seconds2 < 10)
      var displaySeconds2:String = "0" + Math.floor(Seconds2);
      else
      displaySeconds2 = Math.floor(Seconds2).toString();
      return displayMinutes2 + ":" + displaySeconds2;

    this is a public forum.  no one here (or anywhere else that i know of) is obligated to work for you for free.
    your options are to keep working on this yourself or hire someone to help you.  if you can narrow down the problem's location and post the problematic code you could still get free help.
    or just wait.  given enough time maybe someone willing to donate their time to help you will read your post.

  • Record Mic using SampleDataEvent works only on some computers.

    I made a swf that records your mic and allows you to play it back.  I load the soundBytes into a float and play the float back.  It works fine on the computer I developed it on (in IE, Chrome and Firefox) .  It does not work on my second laptop.  And a few people in some forums have said it is not working either.
    Here is the file.  http://www.buttonbeats.com/images/MicCapture.html
    Here is the code.  Do I need certain plugins besides the flash player?
    micRec.addEventListener(MouseEvent.CLICK,recordMic);
    function recordMic(event:MouseEvent){
    micRec.x = -250;
    stopRecord.x = 0;
    const DELAY_LENGTH:int = 4000;
    var mic:Microphone = Microphone.getMicrophone();
    mic.setSilenceLevel(0, DELAY_LENGTH);
    mic.gain = 80;
    mic.rate = 40;
    mic.addEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);
    stopRecord.addEventListener(MouseEvent.CLICK,SREC);
    var soundBytes:ByteArray = new ByteArray();
    function micSampleDataHandler(event:SampleDataEvent):void
        while(event.data.bytesAvailable)
            var sample:Number = event.data.readFloat();
            soundBytes.writeFloat(sample);
    function SREC(event:MouseEvent):void
    stopRecord.x = -250;
        mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);
        soundBytes.position = 0;
        var sound:Sound = new Sound();
        sound.addEventListener(SampleDataEvent.SAMPLE_DATA, playbackSampleHandler);
    soundPlay.addEventListener(MouseEvent.CLICK,SP1);
    function SP1(event:MouseEvent){
      soundBytes.position = 0;
        sound.play();
    function playbackSampleHandler(event:SampleDataEvent):void
        for (var i:int = 0; i < 8192 && soundBytes.bytesAvailable > 0; i++)
            var sample:Number = soundBytes.readFloat();
            event.data.writeFloat(sample);
            event.data.writeFloat(sample);

    you need fp 10.  what's the problematic player version?

  • Using a class within a Vector

    ok,
    I writing a bank program where a user types in a string which is then broken into tokens. The tokens are separated using .nextToken( ) and the first token is used to determine what command the user wants to perform.
    My problem is that I am trying to place a class that Ive created within the vector and I cant seem to be able to get the tokens into the right place or retrieve them when they are needed.
    Here is what I have so far, ps I am very new to java.
    Project3Functions func = new Project3Functions();
    Vector vect = new Vector();
    do
    String firstLine = func.getLineInput();
    StringTokenizer tok = new StringTokenizer(firstLine," ");
    String hold = tok.nextToken();
    if(hold.equals("newAccount"))
    int index = Integer.parseInt(tok.nextToken());
    vect.setSize(index);
    vect.add(index, new Account());
    vect.add(index, Account.firstname = tok.nextToken());
    vect.add(index, Account.lastname = tok.nextToken());
    System.out.println("a new account was created");
    public class Account
    static String firstname = "";
    static String lastname = "";
    I am trying to create a new Account in the position <index> within the vector but I dont think Im referencing firstname and lastname correctly. Also how would I get firstname and lastname out of the vertoc to print them on the screen?
    Please someone help me.

    Your first problem is that you are defining firstname and lastname as static in your Account class. This means that no matter how many new accounts you create, there will only be one firstname and lastname, which are shared between them. their value will be whatever you set them to most recently.
    I think I know why you think you did that, however, and that leads to your second problem. You got complaints from the compiler because you tried to use Account.firstname to set firstname, etc. This only works for static variables. With your code, you are adding three new items to your vector for each new account you create, and you are adding them all to the same index. The last one wins! The other two die.
    Make your Account variables non-static and change the adding code:vect.add(index, newAcct = new Account());
    newAcct.firstname = tok.nextToken();
    newAcct.lastname = tok.nextToken();You should also take care that you only vect.setSize(index); when vect.size() < index; otherwise, if you have items up to 10, and then add an item at 6, items 7 through 10 will be irretrievably lost.
    Doug

  • Imported image's position moves when updated in Indesign CS6. Why??

    After modifying an imported image from illustrator, the imported image's position moves within the frame of Indesign CS6 when the link is updated.

    You have not provided any relevant information, so nobody can know. you can simply have added content that expands the bounding box. Well, whatever, ask in the relevant forums and be much more specific.
    Mylenium

Maybe you are looking for