Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Computespectrum not computing all values

    Ok here is a really odd one. I can't find where the error is.
    I have an mp3 which is 10,728 seconds long exactly. I do a computespectrum on it using the code shown below. It is supposed to run every 50ms.... and when it does trigger, it sends the values to an array in javascript. So i was expecting that my array would have 214 values but lo and behold it has only 195. not only that,, but when i play the mp3, i am hearing an echo.... what the?

    What am i missing here?


    Code:
    var url:String = "mysong.php";
    var requestt:URLRequest = new URLRequest(url);
    var s:Sound = new Sound();
    s.addEventListener(Event.COMPLETE, completeHandler);
    s.load(requestt);
    var song:SoundChannel = s.play();
    song.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
    var ba:ByteArray = new ByteArray();
    var time:Timer = new Timer(50);
    time.addEventListener(TimerEvent.TIMER, timerHandler);
    time.start();
    
    function completeHandler(event:Event):void 
    {event.target.play();}
    
    function soundCompleteHandler(event:Event):void 
    {time.stop();}
    
    function timerHandler(event:TimerEvent):void {
    	SoundMixer.computeSpectrum(ba, true);	
    	var a:int=ba[100];				
    
    	ExternalInterface.call("addtoarray", a);
    }
    Last edited by gani; 12-03-2008 at 02:26 PM. Reason: simplifying

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    The timing issues with Flash are that it doesn't run EXACTLY every 50 milliseconds (which is a rather frequent) so it runs ABOUT every 50 milliseconds. Its also going to vary from computer to computer, based on how many processes are running and so forth.

    Not likely an error, just a software limitation.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so i will trigger the timerHandler function from javascript then.... see how it goes .... will let you know

  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    It is likely to be even slower since you will have to connect from JS to Flash and then run the function. May I ask exactly why it requires to be exact?
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #5
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I want to use it for lipsync... so it has to be super exact.... but i just do not how to get spectrum data in its proper entirety.... i can not have missing segments....

    I have given up the javascript hack because i don't even know how to do it

    Is there anyway to get the spectrum data of the whole mp3 and save it into an array for later use?

  • #6
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    I don't know much but there is a tutorial about similar things on http://www.gotoandlearn.com/.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #7
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it seems that there is no way to get entire spectrum data in advance ...... oh well..... i guess i will have to give it up. Thanks Jeremy

  • #8
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Sorry, but I think that unless you do some kind of prework on the audio, that its too intensive for Flash to handle such a function. Best of luck though.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #9
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You know what's funny though? When i increase the rate from 50 to 25ms, it manages to trigger the function at that faster rate. So it seems that there is something that is slowing the triggering of the function but it is not cpu related

    update:
    Now i know i have scripted this thing wrong. I removed the compute spectrum entirely and just left the timerHandler function to add ones to the array. I get the same number of array variables as with the computespectrum. So the computespectrum was not slowing anything down.... What is happening here??
    Last edited by gani; 12-03-2008 at 07:58 PM.

  • #10
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok next update.

    after removing the computespectrum, I added code which would show me how often the 50ms timer was being called. And it seems that actionscript timers skip calls randomly for no apparent reason. When I triggered the timer from javascript into the flash, all triggers were called perfectly on time. not a single trigger missed.

    through actionscript I get 185 from an expected 206
    through javascript I get 206 from an expected 206

    So I guess my next question would be... How do I trigger the timerHandler function from javascript. The problem is that it is located inside another function as shown in the script above.

    Thanks in advance


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •