Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-03-2008, 02:23 PM   PM User | #1
gani
Regular Coder

 
Join Date: Nov 2008
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
gani is an unknown quantity at this point
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
gani is offline   Reply With Quote
Old 12-03-2008, 03:05 PM   PM User | #2
gnomeontherun
Senior Coder

 
gnomeontherun's Avatar
 
Join Date: Sep 2007
Location: Houston
Posts: 2,846
Thanks: 10
Thanked 238 Times in 229 Posts
gnomeontherun will become famous soon enoughgnomeontherun will become famous soon enough
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.
gnomeontherun is offline   Reply With Quote
Old 12-03-2008, 05:03 PM   PM User | #3
gani
Regular Coder

 
Join Date: Nov 2008
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
gani is an unknown quantity at this point
so i will trigger the timerHandler function from javascript then.... see how it goes .... will let you know
gani is offline   Reply With Quote
Old 12-03-2008, 05:06 PM   PM User | #4
gnomeontherun
Senior Coder

 
gnomeontherun's Avatar
 
Join Date: Sep 2007
Location: Houston
Posts: 2,846
Thanks: 10
Thanked 238 Times in 229 Posts
gnomeontherun will become famous soon enoughgnomeontherun will become famous soon enough
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.
gnomeontherun is offline   Reply With Quote
Old 12-03-2008, 05:33 PM   PM User | #5
gani
Regular Coder

 
Join Date: Nov 2008
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
gani is an unknown quantity at this point
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?
gani is offline   Reply With Quote
Old 12-03-2008, 05:41 PM   PM User | #6
gnomeontherun
Senior Coder

 
gnomeontherun's Avatar
 
Join Date: Sep 2007
Location: Houston
Posts: 2,846
Thanks: 10
Thanked 238 Times in 229 Posts
gnomeontherun will become famous soon enoughgnomeontherun will become famous soon enough
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.
gnomeontherun is offline   Reply With Quote
Old 12-03-2008, 05:52 PM   PM User | #7
gani
Regular Coder

 
Join Date: Nov 2008
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
gani is an unknown quantity at this point
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
gani is offline   Reply With Quote
Old 12-03-2008, 06:14 PM   PM User | #8
gnomeontherun
Senior Coder

 
gnomeontherun's Avatar
 
Join Date: Sep 2007
Location: Houston
Posts: 2,846
Thanks: 10
Thanked 238 Times in 229 Posts
gnomeontherun will become famous soon enoughgnomeontherun will become famous soon enough
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.
gnomeontherun is offline   Reply With Quote
Old 12-03-2008, 07:29 PM   PM User | #9
gani
Regular Coder

 
Join Date: Nov 2008
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
gani is an unknown quantity at this point
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..
gani is offline   Reply With Quote
Old 12-03-2008, 11:17 PM   PM User | #10
gani
Regular Coder

 
Join Date: Nov 2008
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
gani is an unknown quantity at this point
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
gani is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:18 AM.


Advertisement
Log in to turn off these ads.