[Flashcoders] Audio lag on KeyboardEvent.KEY_DOWN

2008-12-08 Thread [EMAIL PROTECTED]
Hi List,

I'm dipping my toe into AS3 and thought I'd play around with sound by making
a little piano keyboard which is played by pressing keys on the computer
keyboard.

It works - the appropriate sounds play on KeyboardEvent.KEY_DOWN - however,
I've noticed that there is often a lag between the keyboard event and the
actual sound playing. The occurrence of the lag seems pretty random.

The sounds are MP3s which are load()ed into Sound objects on init(). On
KeyboardEvent.KEY_DOWN, the appropriate Sound is play()ed.

I've checked all the MP3s, and they don't have extra silence at the
beginning. I don't think it has to do with the number of MP3s involved (14),
because I noticed the lag even when I was testing it out with 2 sounds.

Has anyone dealt with this before, and know what the problem might be? You
can see (or rather, hear) the lag for yourself here:
http://snipurl.com/7ndr2-meep

Thanks!

In hope,
CB.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Audio lag on KeyboardEvent.KEY_DOWN

2008-12-08 Thread allandt bik-elliott (thefieldcomic.com)
did you use updateAfterEvent() to force it to play immediately? if not, it
might be waiting for the next frame to process the event

On Mon, Dec 8, 2008 at 12:14 PM, [EMAIL PROTECTED] 
[EMAIL PROTECTED] wrote:

 Hi List,

 I'm dipping my toe into AS3 and thought I'd play around with sound by
 making
 a little piano keyboard which is played by pressing keys on the computer
 keyboard.

 It works - the appropriate sounds play on KeyboardEvent.KEY_DOWN - however,
 I've noticed that there is often a lag between the keyboard event and the
 actual sound playing. The occurrence of the lag seems pretty random.

 The sounds are MP3s which are load()ed into Sound objects on init(). On
 KeyboardEvent.KEY_DOWN, the appropriate Sound is play()ed.

 I've checked all the MP3s, and they don't have extra silence at the
 beginning. I don't think it has to do with the number of MP3s involved
 (14),
 because I noticed the lag even when I was testing it out with 2 sounds.

 Has anyone dealt with this before, and know what the problem might be? You
 can see (or rather, hear) the lag for yourself here:
 http://snipurl.com/7ndr2-meep

 Thanks!

 In hope,
 CB.
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Audio lag on KeyboardEvent.KEY_DOWN

2008-12-08 Thread jonathan howe
I'm very interested in the solution to this. I notice it on certain machines
and not others... it does not seem to have anything to do with the input
part, and in some cases can stutter the display updating. For example, if
you were to have a timer trigger the sound and print something at the
screen, they would both 'appear' at the same time but if you also measured
the time difference between the trigger's execution and after the sound
call, there would be latency.

The superstitious/uneducated part of me supposes that Flash is establishing
a modal call to the sound card, and some perform cards respond faster than
others.
-jonathan


On Mon, Dec 8, 2008 at 2:37 PM, allandt bik-elliott (thefieldcomic.com) 
[EMAIL PROTECTED] wrote:

 did you use updateAfterEvent() to force it to play immediately? if not, it
 might be waiting for the next frame to process the event

 On Mon, Dec 8, 2008 at 12:14 PM, [EMAIL PROTECTED] 
 [EMAIL PROTECTED] wrote:

  Hi List,
 
  I'm dipping my toe into AS3 and thought I'd play around with sound by
  making
  a little piano keyboard which is played by pressing keys on the
 computer
  keyboard.
 
  It works - the appropriate sounds play on KeyboardEvent.KEY_DOWN -
 however,
  I've noticed that there is often a lag between the keyboard event and the
  actual sound playing. The occurrence of the lag seems pretty random.
 
  The sounds are MP3s which are load()ed into Sound objects on init(). On
  KeyboardEvent.KEY_DOWN, the appropriate Sound is play()ed.
 
  I've checked all the MP3s, and they don't have extra silence at the
  beginning. I don't think it has to do with the number of MP3s involved
  (14),
  because I noticed the lag even when I was testing it out with 2 sounds.
 
  Has anyone dealt with this before, and know what the problem might be?
 You
  can see (or rather, hear) the lag for yourself here:
  http://snipurl.com/7ndr2-meep
 
  Thanks!
 
  In hope,
  CB.
  ___
  Flashcoders mailing list
  Flashcoders@chattyfig.figleaf.com
  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




-- 
-jonathan howe
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Audio lag on KeyboardEvent.KEY_DOWN

2008-12-08 Thread Sidney de Koning

Hi Jonathan,

You say: The sounds are MP3s which are load()ed into Sound objects on  
init().
Does this mean you preload the sounds? If so;  If you press a key  
before the whole sound is loaded in it takes some time to play it,  
because it is still loading. You can make sure of this by showing the  
application AFTER all the sounds are loaded in, this can be done by  
creating a loader que (place items in an array after they are loaded  
and check if the total amount of items loaded in is equal to the array  
length).
This way you always know that nothing shows up before all the sounds  
are loaded.


Hope this helps you,

Sid

On Dec 8, 2008, at 4:31 PM, jonathan howe wrote:

I'm very interested in the solution to this. I notice it on certain  
machines
and not others... it does not seem to have anything to do with the  
input
part, and in some cases can stutter the display updating. For  
example, if

you were to have a timer trigger the sound and print something at the
screen, they would both 'appear' at the same time but if you also  
measured
the time difference between the trigger's execution and after the  
sound

call, there would be latency.

The superstitious/uneducated part of me supposes that Flash is  
establishing
a modal call to the sound card, and some perform cards respond  
faster than

others.
-jonathan


On Mon, Dec 8, 2008 at 2:37 PM, allandt bik-elliott  
(thefieldcomic.com) 

[EMAIL PROTECTED] wrote:

did you use updateAfterEvent() to force it to play immediately? if  
not, it

might be waiting for the next frame to process the event

On Mon, Dec 8, 2008 at 12:14 PM, [EMAIL PROTECTED] 
[EMAIL PROTECTED] wrote:


Hi List,

I'm dipping my toe into AS3 and thought I'd play around with sound  
by

making
a little piano keyboard which is played by pressing keys on the

computer

keyboard.

It works - the appropriate sounds play on KeyboardEvent.KEY_DOWN -

however,
I've noticed that there is often a lag between the keyboard event  
and the

actual sound playing. The occurrence of the lag seems pretty random.

The sounds are MP3s which are load()ed into Sound objects on  
init(). On

KeyboardEvent.KEY_DOWN, the appropriate Sound is play()ed.

I've checked all the MP3s, and they don't have extra silence at the
beginning. I don't think it has to do with the number of MP3s  
involved

(14),
because I noticed the lag even when I was testing it out with 2  
sounds.


Has anyone dealt with this before, and know what the problem might  
be?

You

can see (or rather, hear) the lag for yourself here:
http://snipurl.com/7ndr2-meep

Thanks!

In hope,
CB.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders





--
-jonathan howe
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Sidney de Koning
Flash / AIR Developer @ www.funky-monkey.nl
Technical writer @ www.insideria.com




___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Audio lag on KeyboardEvent.KEY_DOWN

2008-12-08 Thread jonathan howe
That part was actually confusticate's and I do believe that he was implying
that the sounds had load() called prior to the KeyboardEvent, and the
latency happens on the 100th keystroke as well as the first.

By way of comparison, I had the same problem in sounds attached from the
library.

I wonder if it would make a difference if new Sound objects (in AS2) or
SoundChannels (in AS3) were or weren't instantiated every time.
On Mon, Dec 8, 2008 at 4:49 PM, Sidney de Koning [EMAIL PROTECTED]wrote:

 Hi Jonathan,

 You say: The sounds are MP3s which are load()ed into Sound objects on
 init().
 Does this mean you preload the sounds? If so;  If you press a key before
 the whole sound is loaded in it takes some time to play it, because it is
 still loading. You can make sure of this by showing the application AFTER
 all the sounds are loaded in, this can be done by creating a loader que
 (place items in an array after they are loaded and check if the total amount
 of items loaded in is equal to the array length).
 This way you always know that nothing shows up before all the sounds are
 loaded.

 Hope this helps you,

 Sid


 On Dec 8, 2008, at 4:31 PM, jonathan howe wrote:

 I'm very interested in the solution to this. I notice it on certain
 machines
 and not others... it does not seem to have anything to do with the input
 part, and in some cases can stutter the display updating. For example, if
 you were to have a timer trigger the sound and print something at the
 screen, they would both 'appear' at the same time but if you also measured
 the time difference between the trigger's execution and after the sound
 call, there would be latency.

 The superstitious/uneducated part of me supposes that Flash is
 establishing
 a modal call to the sound card, and some perform cards respond faster than
 others.
 -jonathan


 On Mon, Dec 8, 2008 at 2:37 PM, allandt bik-elliott (thefieldcomic.com) 
 [EMAIL PROTECTED] wrote:

 did you use updateAfterEvent() to force it to play immediately? if not, it
 might be waiting for the next frame to process the event

 On Mon, Dec 8, 2008 at 12:14 PM, [EMAIL PROTECTED] 
 [EMAIL PROTECTED] wrote:

 Hi List,

 I'm dipping my toe into AS3 and thought I'd play around with sound by
 making
 a little piano keyboard which is played by pressing keys on the

 computer

 keyboard.

 It works - the appropriate sounds play on KeyboardEvent.KEY_DOWN -

 however,

 I've noticed that there is often a lag between the keyboard event and
 the
 actual sound playing. The occurrence of the lag seems pretty random.

 The sounds are MP3s which are load()ed into Sound objects on init(). On
 KeyboardEvent.KEY_DOWN, the appropriate Sound is play()ed.

 I've checked all the MP3s, and they don't have extra silence at the
 beginning. I don't think it has to do with the number of MP3s involved
 (14),
 because I noticed the lag even when I was testing it out with 2 sounds.

 Has anyone dealt with this before, and know what the problem might be?

 You

 can see (or rather, hear) the lag for yourself here:
 http://snipurl.com/7ndr2-meep

 Thanks!

 In hope,
 CB.
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




 --
 -jonathan howe
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


 Sidney de Koning
 Flash / AIR Developer @ www.funky-monkey.nl
 Technical writer @ www.insideria.com





 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




-- 
-jonathan howe
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Audio lag on KeyboardEvent.KEY_DOWN

2008-12-08 Thread Olivier Besson

Hi,
a colleague of mine noticed the same problem with attached sounds in as3.
He had to start music loops simultaneously and it turn out impossible by 
actionscript alone, because of a random lag.


The only solution he found was to launch the sounds in the same keyframe 
in the timeline.
Perhaps a timeline-based solution of your problem is possible: for 
example using the keys to controls movieClips with different labels 
(each label having one sound), and using updateAfterEvent as advised 
previsously. Or, one clip per sound.
If it solves your problem, you can still control the volume of an 
IDE-specfied sound by using the soundChannel property of movieClips.


  Olivier


jonathan howe a écrit :

That part was actually confusticate's and I do believe that he was implying
that the sounds had load() called prior to the KeyboardEvent, and the
latency happens on the 100th keystroke as well as the first.

By way of comparison, I had the same problem in sounds attached from the
library.

I wonder if it would make a difference if new Sound objects (in AS2) or
SoundChannels (in AS3) were or weren't instantiated every time.
On Mon, Dec 8, 2008 at 4:49 PM, Sidney de Koning [EMAIL PROTECTED]wrote:

  

Hi Jonathan,

You say: The sounds are MP3s which are load()ed into Sound objects on
init().
Does this mean you preload the sounds? If so;  If you press a key before
the whole sound is loaded in it takes some time to play it, because it is
still loading. You can make sure of this by showing the application AFTER
all the sounds are loaded in, this can be done by creating a loader que
(place items in an array after they are loaded and check if the total amount
of items loaded in is equal to the array length).
This way you always know that nothing shows up before all the sounds are
loaded.

Hope this helps you,

Sid


On Dec 8, 2008, at 4:31 PM, jonathan howe wrote:

I'm very interested in the solution to this. I notice it on certain


machines
and not others... it does not seem to have anything to do with the input
part, and in some cases can stutter the display updating. For example, if
you were to have a timer trigger the sound and print something at the
screen, they would both 'appear' at the same time but if you also measured
the time difference between the trigger's execution and after the sound
call, there would be latency.

The superstitious/uneducated part of me supposes that Flash is
establishing
a modal call to the sound card, and some perform cards respond faster than
others.
-jonathan


On Mon, Dec 8, 2008 at 2:37 PM, allandt bik-elliott (thefieldcomic.com) 
[EMAIL PROTECTED] wrote:

did you use updateAfterEvent() to force it to play immediately? if not, it
  

might be waiting for the next frame to process the event

On Mon, Dec 8, 2008 at 12:14 PM, [EMAIL PROTECTED] 
[EMAIL PROTECTED] wrote:

Hi List,


I'm dipping my toe into AS3 and thought I'd play around with sound by
making
a little piano keyboard which is played by pressing keys on the

  

computer



keyboard.

It works - the appropriate sounds play on KeyboardEvent.KEY_DOWN -

  

however,



I've noticed that there is often a lag between the keyboard event and
the
actual sound playing. The occurrence of the lag seems pretty random.

The sounds are MP3s which are load()ed into Sound objects on init(). On
KeyboardEvent.KEY_DOWN, the appropriate Sound is play()ed.

I've checked all the MP3s, and they don't have extra silence at the
beginning. I don't think it has to do with the number of MP3s involved
(14),
because I noticed the lag even when I was testing it out with 2 sounds.

Has anyone dealt with this before, and know what the problem might be?

  

You



can see (or rather, hear) the lag for yourself here:
http://snipurl.com/7ndr2-meep

Thanks!

In hope,
CB.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
  

Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




--
-jonathan howe
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

  

Sidney de Koning
Flash / AIR Developer @ www.funky-monkey.nl
Technical writer @ www.insideria.com





___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders






  



--
Olivier Besson (gludion) - (33 1) 44 64 78 99
http://.gludion.com
http://blog.gludion.com

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Audio lag on KeyboardEvent.KEY_DOWN

2008-12-08 Thread Todd Kerpelman
I'm actually running into a very similar problem trying to create my little
flash-based drum machine. I've got a 100 ms .wav that I'm trying to play on
a regular basis and no matter what I try, it comes out sounding weird and
erratic. I was hoping there was some magic Here's how you compress and/or
pre-load the sound so that it plays instantly trick that I was missing.

I've done several tests -- from playing the sound every x frames, to playing
the sound every x ms, to keeping two identical copies of the same sound and
alternating between them, but nothing seems to help much.

I'd be glad to share some test code if anybody's interested in trying this
at home, but it sounds like maybe the problem is Flash's and not mine. Maybe
I'll put together some hacked-together timeline solution and see if that
helps at all...

CB, when this is all over, your piano and my drummer can jam.

--T





On Mon, Dec 8, 2008 at 10:13 AM, Olivier Besson [EMAIL PROTECTED] wrote:

 Hi,
 a colleague of mine noticed the same problem with attached sounds in as3.
 He had to start music loops simultaneously and it turn out impossible by
 actionscript alone, because of a random lag.

 The only solution he found was to launch the sounds in the same keyframe in
 the timeline.
 Perhaps a timeline-based solution of your problem is possible: for example
 using the keys to controls movieClips with different labels (each label
 having one sound), and using updateAfterEvent as advised previsously. Or,
 one clip per sound.
 If it solves your problem, you can still control the volume of an
 IDE-specfied sound by using the soundChannel property of movieClips.

  Olivier


 jonathan howe a écrit :

  That part was actually confusticate's and I do believe that he was
 implying
 that the sounds had load() called prior to the KeyboardEvent, and the
 latency happens on the 100th keystroke as well as the first.

 By way of comparison, I had the same problem in sounds attached from the
 library.

 I wonder if it would make a difference if new Sound objects (in AS2) or
 SoundChannels (in AS3) were or weren't instantiated every time.
 On Mon, Dec 8, 2008 at 4:49 PM, Sidney de Koning [EMAIL PROTECTED]
 wrote:



 Hi Jonathan,

 You say: The sounds are MP3s which are load()ed into Sound objects on
 init().
 Does this mean you preload the sounds? If so;  If you press a key before
 the whole sound is loaded in it takes some time to play it, because it is
 still loading. You can make sure of this by showing the application AFTER
 all the sounds are loaded in, this can be done by creating a loader que
 (place items in an array after they are loaded and check if the total
 amount
 of items loaded in is equal to the array length).
 This way you always know that nothing shows up before all the sounds are
 loaded.

 Hope this helps you,

 Sid


 On Dec 8, 2008, at 4:31 PM, jonathan howe wrote:

 I'm very interested in the solution to this. I notice it on certain


 machines
 and not others... it does not seem to have anything to do with the input
 part, and in some cases can stutter the display updating. For example,
 if
 you were to have a timer trigger the sound and print something at the
 screen, they would both 'appear' at the same time but if you also
 measured
 the time difference between the trigger's execution and after the sound
 call, there would be latency.

 The superstitious/uneducated part of me supposes that Flash is
 establishing
 a modal call to the sound card, and some perform cards respond faster
 than
 others.
 -jonathan


 On Mon, Dec 8, 2008 at 2:37 PM, allandt bik-elliott (thefieldcomic.com)
 
 [EMAIL PROTECTED] wrote:

 did you use updateAfterEvent() to force it to play immediately? if not,
 it


 might be waiting for the next frame to process the event

 On Mon, Dec 8, 2008 at 12:14 PM, [EMAIL PROTECTED] 
 [EMAIL PROTECTED] wrote:

 Hi List,


 I'm dipping my toe into AS3 and thought I'd play around with sound by
 making
 a little piano keyboard which is played by pressing keys on the



 computer



 keyboard.

 It works - the appropriate sounds play on KeyboardEvent.KEY_DOWN -



 however,



 I've noticed that there is often a lag between the keyboard event and
 the
 actual sound playing. The occurrence of the lag seems pretty random.

 The sounds are MP3s which are load()ed into Sound objects on init().
 On
 KeyboardEvent.KEY_DOWN, the appropriate Sound is play()ed.

 I've checked all the MP3s, and they don't have extra silence at the
 beginning. I don't think it has to do with the number of MP3s involved
 (14),
 because I noticed the lag even when I was testing it out with 2
 sounds.

 Has anyone dealt with this before, and know what the problem might be?



 You



 can see (or rather, hear) the lag for yourself here:
 http://snipurl.com/7ndr2-meep

 Thanks!

 In hope,
 CB.
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com