Click to See Complete Forum and Search --> : Sound syncing Project - Completed Download Avail
blanius
03-31-2006, 10:29 PM
Ok I'm working on something. I've made a little program that lets you generate an array of markers for an MP3 file that you can import into KM.
I'm trying to figure out the best way to now track the sound and trigger events based on the markers.
Right now I'm generating the following code
markerArray=new Array("2631","one","6269","two","10031","three");
where the number is the position in the song and the next item is the action or label
Any AS guru's want to help point me in the right direction?
blanius
03-31-2006, 11:26 PM
Here's what I've got so far and it seems to work
_global markerArray=new Array("2563","one","6273","two","10100","three");
mySound=new Sound()
mySound.loadSound("scenes.mp3",false);
mySound.onLoad=function(){
mySound.isLoaded=true
mySound.start()
c_marker=markerArray.shift()
txt3.text=c_marker
c_action=markerArray.shift()
}
markers=function(audio){
pos=audio.position;
txt1.text=pos
checkIt(audio)
}
checkIt=function(audio){
if (audio.position>=c_marker){
txt2.text=c_action
c_marker=markerArray.shift()
//txt3.text=c_marker
c_action=markerArray.shift()
}
}
setInterval(markers,1,mySound)
stop()
I think it might be better if I could use listeners that and some sort of EVENT system. I hope Wilbert sees this and I can pick his brain.
w.brants
04-01-2006, 12:56 AM
Bret,
Can you be a bit more specific what kind of listener function you had in mind ?
Maybe this old thread can also be of some help
http://www.flashkit.com/board/showthread.php?&threadid=623645
Wilbert
blanius
04-01-2006, 08:43 AM
That's pretty much what I had in mind.
I don't quite understand it, you use features that I don't understand......
I could make the program I made output code like you have
mySoundEvents.push ( { sp:1500, o:_root.mc1, f:'gotoAndStop', p:['eeks'] } );
mySoundEvents.push ( { sp:2000, o:_root.mc1, f:'gotoAndStop', p:[1] } );
mySoundEvents.push ( { sp:3000, o:_root.mc2, p:'_visible', v:false } );
mySoundEvents.push ( { sp:3500, o:_root.mc2, p:'_visible', v:true } );
Maybe I don't need to understand your code so much as appriciate at and make use of it.
:)
I hadn' thought of assigning object and paramaters to the event, I was just using markers. I didn't realize that could be done.
w.brants
04-01-2006, 10:49 AM
There's so many ways one can implement such a synchronization routine.
Another way could be to implement an onPos event....// Extending the sound object
// syncStart([secondOffset:Number], [loops:Number], [msecAccuracy:Number])
Sound.prototype.syncStart = function(){
var f;
this._ev = [];
for (f in this) if (f.substr(0,5) == 'onPos' || f.substr(0,5) == 'onpos') this._ev.push({p:f.substr(5),o:this[f]});
this._ev.sortOn('p',Array.NUMERIC);
this._ce = 0;
if (this._id != null) clearInterval(this._id);
this._id = setInterval(this, '_sync', arguments.length > 2 ? arguments[2] : 100);
this.start.apply(this,arguments);
}
Sound.prototype._sync = function(){
if (this.position >= this._ev[this._ce].p){
this._ev[this._ce].o.apply(this);
if (this._ce++ == this._ev.length) clearInterval(this._id);
arguments.callee.apply(this);
}
}
// using it
mySound = new Sound();
mySound.loadSound('myMP3file.mp3',true);
mySound.onPos5500 = function(){ _root.txt1.text = '5.5 seconds passed'; }
mySound.onPos6500 = function(){ _root.txt1.text = '6.5 seconds passed'; }
mySound.syncStart();
Notes:
- It only works the first time the sound plays if you use a sound from the symbol library and loop it. If you want it to work for each loop you have to modify the code.
- Another possible problem is if you implement forward and backward buttons so the user can jump back. Again, in that case you would have to modify the code to calculate the new _ce value (current event).
- Flash 7 is required for numeric sorting of arrays.
Wilbert
blanius
04-01-2006, 11:01 AM
Playing with the code from your other thread but can't get it to work.
Have stopped movie with four frames as mc1 in root. Frame 2-4 are named one, two, three
update=function(){
_root.txt1.text=_root.mySound.position
}
setInterval(update,50);
/ Extending the sound object
Sound.prototype.setSoundEvents = function( events, accuracy ){
_root.txt1.text=this.position
this.events = events;
this.current_event = 0;
if (this.interval_id != null) clearInterval(this.interval_id);
this.interval_id = setInterval(this, 'sync', accuracy);
}
Sound.prototype.sync = function(){
if (this.position >= this.events[this.current_event].sp){
var event = this.events[this.current_event];
if (event.f != null){
var func = event.o[event.f];
func.apply(event.o, event.p );
} else if (event.p != null){
event.o[event.p] = event.v;
}
this.current_event = this.current_event + 1;
if (this.current_event == this.events.length) clearInterval(this.interval_id);
this.sync();
}
}
// using it
mySoundEvents = new Array();
mySoundEvents.push ( { sp:2660, o:_root.mc1, f:'gotoAndStop', p:['one'] } );
mySoundEvents.push ( { sp:6383, o:_root.mc1, f:'gotoAndStop', p:['two'] } );
mySoundEvents.push ( { sp:10090, o:_root.mc1, f:'gotoAndStop', p:['three'] } );
mySoundEvents.sortOn('sp');
mySound = new Sound();
mySound.setSoundEvents( mySoundEvents, 10 ); accuracy 50 msec
mySound.loadSound('Scenes.mp3',true);
mySound.start();
blanius
04-01-2006, 11:09 AM
Also if you wanted the object to be _root would you put _root in the o:?
Some of this syntax is very hard to follow.
w.brants
04-01-2006, 11:39 AM
Yes, you would put _root in there.
I don't understand why it doesn't work. If I copy the code you post it doesn't work, if I copy the code from the original thread it does :confused:
blanius
04-01-2006, 02:11 PM
very odd...... Only thing I changed was some of the array elements and the name of the mp3 file. What else could have changed I wonder.
Trying to debug I notice that if I look at mySoundEvents[0].sp it's the last marker not the first if I comment out the mySoundEvents.sortOn('sp'); it's the first marker. shouldn't it be the first one?
blanius
04-01-2006, 02:16 PM
can you explain this line more?
func.apply(event.o, event.p );
how does this work? apply is not a keyword is it? Hard to debug when I can't quite understand what you've done. :)
w.brants
04-01-2006, 03:02 PM
can you explain this line more?
func.apply(event.o, event.p );
how does this work? apply is not a keyword is it? Hard to debug when I can't quite understand what you've done. :)
As for your previous post, When testing the original code I didn't encounter the sort problem since I only seem to have used values between 1000 and 9999. To get a correct sort at all times you should use a numeric sort like I did in the other code example.
apply is a keyword !
You can look it up in the actionscript dictionary (see Function).
If you have a function, you can apply it to an object and pass a parameter array. In this case func contains the function. The object is will consider 'this' is event.o and the array that contains the parameters is event.p .
blanius
04-01-2006, 08:43 PM
BINGO that does it. Ok this works now. I'll rewrite my utility to generate this style of array.
blanius
04-01-2006, 11:28 PM
Ok who wants to test it?
file removed download the Zip file http://bretlanius.com/flash/mp3markerscreenshot.jpg
Example of sync audio
http://bretlanius.com/flash/markers.html
to use it paste the generated code into
Sound.prototype.setSoundEvents = function( events, accuracy ){
this.events = events;
this.current_event = 0;
if (this.interval_id != null) clearInterval(this.interval_id);
this.interval_id = setInterval(this, 'sync', accuracy);
}
Sound.prototype.sync = function(){
if (this.position >= this.events[this.current_event].sp){
var event = this.events[this.current_event];
if (event.f != null){
var func = event.o[event.f];
func.apply(event.o, event.p );
} else if (event.p != null){
event.o[event.p] = event.v;
}
this.current_event = this.current_event + 1;
if (this.current_event == this.events.length) clearInterval(this.interval_id);
this.sync();
}
}
// using it
mySoundEvents = new Array();
/****************************Paste the code here********************/
mySound = new Sound();
mySound.setSoundEvents( mySoundEvents, 10 ); accuracy 50 msec
mySound.loadSound('scenes.mp3',true);
mySound.start();
stop()
possum3
04-02-2006, 02:29 PM
Thank you Bret! How did you know I needed help with a sound sync project? This really has helped. I did notice when resetting the sound the counter does not return to zero. Thanks again Bret
blanius
04-02-2006, 02:45 PM
Yeah I don't know why. I assume that the MCI interface in Windows is not reporting it correctly.
blanius
04-02-2006, 03:59 PM
Forgot to put back the track bar for the mp3, this lets you back up or jump forward when you need to. Also put together example fun and doc explaining how to use.
Finished project here:
http://koolexchange.com Look under Tools.
blanius
04-02-2006, 04:01 PM
If anyone uses this to make something please share it with us. I know I really enjoy it when someone gets something usefull from my efforts. I spend alot of time working things out but never get to see what people are doing with it.
possum3
04-04-2006, 10:37 PM
Bret I tried out your MP3 Marker and it worked like a charm! This is just a quick sample. The mouth movements are just open and closed. http://home.att.net/~pos3sum/toad/mark1.html
Thanks Bret
blanius
04-04-2006, 11:53 PM
cool
Dr_John
04-05-2006, 12:51 PM
And the "KoolMan" medal for best code and DOCUMENTATION goes to ..... (wait 22 seconds before you read on) ...... (you're still waiting, right?) ..... Bret Lanius and the gang! TADA - drum roll
Thanks Bret, that's a great project that will come in handy sooner or later here too. Sorry I haven't posted much ... things are crazy here. Yesterday I was on TV .... life is good. Why am I telling you this? lol
blanius
04-05-2006, 03:13 PM
remember 99.9% of the actionscript is Wilbert's
Dr_John
04-05-2006, 03:38 PM
ahhhhh let's see ... that leaves you still with .1% of the medal. And don't forget, the medal is a BIG one ;-)
docree
04-05-2006, 04:35 PM
Ok, good program a lil rough sailing... Cause, it's not what I'm used to.
My suggestions:
Allow us to preset marks before we synch...
In other words, I would like to preset what happens when the mark is layed,
before I lay down the synch marks. And when ever I click or type a key the
mark is layed with the preset actions...
The technique I'm familiar with is called a tap synch.
A recorder is turned on [say for the mouth actions] and when the
operator "taps" a button [mouse click or key press] the signal [mark]
is layed on the track [action scripted array / timeline].
Now, if you add presets can we have multiple???
Example:
For every press of M lay down a mark for mouth actions... [Makes mouth open.]
For every press of B lay down a mark for tail actions... [Makes tail wiggle.]
Thanks,
I don't think I have any more suggestions.
DocRee
_____________________________
On a similar note...
Didn't we have someone with a nice mouth synching program before?
blanius
04-05-2006, 05:05 PM
Yes there was another mouth sync program. It did not use the sound's actual position but it did work nicely as I understand it. The biggest problem with that one is that there is nothing "holding" it in sync so if for example the audio was delayed you would loose sync.
Also this was an attempt to allow more than just lipsync. Many times I want an animation to start on a sound point. In the past I just hard coded it, but have long wanted something better.
I considered doing the sync they way you suggested and may look into that.
If you layout what you think it should look like I'll give it a go. I'm not a hard core programmer but the folks at Ibasic forum are very helpfull. (the program is written in Ibasic Pro http://pyxia.com)
FLASHPULSE
04-06-2006, 01:51 PM
Nice work Blanius. My suggestion would be to have an option to be able to create the entire code and copy it to the clip board. That would make a one shot paste for quicker use. Also, if you're looking to create a lipsync program with this, I could share my lipsync code with you? I've been thinking of making it freeware anyway.
w.brants
04-06-2006, 02:01 PM
Hi Joe, long time no see.
I'm checking your domain now and then to be surprised by your newest creation but it still isn't there :confused:
Yes, Bret did a great job. It would have been nice if you would have used the same basic compiler. That way it would be easy for you to exchange code.
docree
04-06-2006, 04:34 PM
Ooooh, I just realized a way to export to .as ...
[If you can perform a "find and replace text" with IBasic...]
So one could just click the "Append File Contents" button [open folder icon]
in KoolMoves' Action Script editor.
I may look into IBasic if my free time allows...
blanius
04-06-2006, 09:54 PM
Ooooh, I just realized a way to export to .as ...
[If you can perform a "find and replace text" with IBasic...]
So one could just click the "Append File Contents" button [open folder icon]
in KoolMoves' Action Script editor.
I may look into IBasic if my free time allows...
Ok this has been done. And the new ZIP has been uploaded to my site.
Try it out. It now has a copy to clipboard button that puts the entire AS code in the clipboard including the mp3 file name without path. Then just PASTE in KM Actionscript editor.
blanius
04-06-2006, 10:03 PM
BTW anyone interested in the basic source It's available as well.
Hey Flashpulse what did you program yours in? I'd love to see the source
w.brants
04-07-2006, 01:13 AM
That's a pretty short source Bret :), I'd expected it to be longer.
I haven't seen the LipSync source Joe created using PureBasic (http://www.purebasic.com) but there are quite a few language differences (I also have a PureBasic license). I'm sure Joe can tell you all about it.
blanius
04-07-2006, 08:39 AM
I bought Ibasic when the developer was struggling and having a hard time putting food on the table. I bought it mostly to support his efforts, but it's turned out to be a great piece of software. Biggest limitation in my opinion is the visual form builder is pretty limited.
FLASHPULSE
04-07-2006, 12:01 PM
Thanks for sharing Bret! ;) I post mine soon. It's currently 2323 lines of code. I have to remove the registration feature, then I will post it. :D
blanius
04-07-2006, 01:14 PM
WOW 2323 lines no wonder you were charging for it :) If I'd spent that kind of time on it I'd want to get paid too..... Now I'mreally interested to see what you did, Curious about how much of that is due to the compiler.
FLASHPULSE
04-07-2006, 02:24 PM
Well here it is. Images, icon, and the help file. I even made a compiled executable for those who don't program. I got it down to 1978 lines after removing the registration stuff. :D
Oh, make sure you keep the image folder next to the source when compiling or you might get an error.
DOWNLOAD (http://www.flashpulse.com/fls_free.zip)
FLASHPULSE
04-08-2006, 02:41 AM
This one compiles with the latest PureBasic, 4.0 beta 9. Haven't fully tested it but all should be fine.
ginsueye
06-07-2006, 01:21 PM
Thank you all. You have taken me past a huge roadblock in a short time. I have written Blanius with the offer to buy him a beer
blanius
06-07-2006, 04:50 PM
Thank you all. You have taken me past a huge roadblock in a short time. I have written Blanius with the offer to buy him a beer
I'll be taking you up on it
Bob Hartzell
07-08-2006, 01:14 PM
Bret, your email has apparently changed. Please email me your new email address.
The link to the tutorials on the koolmoves support page no longer works.
flashkit.com
Copyright WebMediaBrands Inc., All Rights Reserved.