Some questions about sound/audio in Stencyl...

redpesto

  • Posts: 134
Hi, I'm making a game that relies on sounds being played at very specific times.

There is some background music playing, its 16 beats long at 120bpm. When you activate a block it will play a duck quack sound every four seconds. Now this should play over and be perfectly in time with the backing music - but it very often goes out of sync.

My questions are:
1) Any way to make this tighter? Would steps be better than seconds?
2) How come the background music loops perfectly sometimes and at others it has a slight pause when it loops? Any way to fix this?
3) Has the sound engine been improved with Flash 11? If so, will the better audio handling eventually come into Stencyl?
4) How's the audio working on iDevices once rendered out of iStencyl? Will I still have the same problems.
5) I've noticed the audio channels block has the Flash logo, that means it won't work in iStencyl right?
6) If so, is there any benefit/loss from having all the music and sounds come out of the same channel, won't they start cutting over each other?
7) Audio in Flash just sucks right?

Think that's it for now haha, any more and I'll post them up. Many thanks for your time!

redpesto

  • Posts: 134
No audiophiles eh?

Was actually reading this article http://blog.bluetubeinteractive.com/2009/03/flash-audio-hell-how-to-loop-audio-in-flash.html

Will Stencyl ever support .WAV and will I be able to used Sync :Event and Repeat 9999 in a code block?

I really need some help with getting my audio playing in sync with each other as its totally essential to my game. Thank you!

theabbott

  • Posts: 271
Hi There,

You can download a beat timer that you can use to do exactly what you're asking here:

http://community.stencyl.com/index.php/topic,2060.msg14319.html#msg14319

Just set your sound fx to trigger on each beat measure and it should work perfect.

SquareNote

  • Posts: 20
Let me know how that works for you both because I was still having trouble with it the last time I was using it.

SquareNote

  • Posts: 20
Also, I would love a more sophisticated response from the Stencyl devs about audio sync'ing in Stencyl, because trying to work on audio-based games has been extremely frustrating and I don't really have a handle on what Stencyl is capable of or isn't capable of in that regard (and I'm really not much of a programmer). I'd like to know if I'm wasting my time trying to figure it out.

Specifically talking about looping tracks, playing multiple sound files at the same time in order to fade in different loops and have them all still be in-sync, and playing an extended bit of audio and having animations and behaviors that are triggered according to a calculated tempo remain in sync with the audio. I think the fact that they eventually drift out of sync is related to framerates somehow and that's what Hectate was helping me unravel in that linked thread, but I still don't really understand it.

« Last Edit: March 23, 2012, 02:28:39 pm by SquareNote »

theabbott

  • Posts: 271
Hey Squarenote,

First up thanks for exploring this stuff, i too, would love to know the sound capabilities and have a stencyl expert speak on this and have more sound features added in future.

Using your beat timer code i've been able to get my actor to move on beat quite well and it will stay in sync for electronic-produced music for well over 3 minutes.

I think the problem with it slowly getting out of sync is related to at least of couple of things:

1) the BPM calculation, in that its never 100% perfect no matter what you're using to calculate it. So every measure will slowly push the event out of sync. e.g. the 'true' BPM of Song X is 120.25 BPM but its calculated at 125.00 BPM so it's off by 0.25 every measure and the longer it plays the more the offset becomes audible/visible. Some sort of periodic re-syncing code should fix this well enough to keep the illusion of things syncing perfectly.

2) Also the type of music you're using, Stuff that's not made by a computer, band-music, live music etc will never be able to be synced perfect as the song has an ever changing tempo/bpm. Humans never play exactly on beat.

For seamlessly looping mp3s it can definitely be done - I see Stencyl uses Flixel (import org.flixel.*;) I'm not sure how the "stencyl.api.engine.sound." was created and maybe im barking up the wrong tree but on the Flixel forums people have managed to update the FlxSound Class with seamless looping:

http://www.piposplayhouse.com/FlxSound.as

There's also some 3rd party classes that allow for dynamic pitch shifting here:

http://forums.flixel.org/index.php?topic=2540.0


I've also found some amazing real-time DSP stuff thats written in AS3 - (http://www.anttikupila.com/flash/soundfx-out-of-the-box-audio-filters-with-actionscript-3/)

All this suggesting that sound in Flash is not as crappy as it's made out to be.

But implementing this stuff in Stencyl is way above my level, The source is there in AS3 i would really love a Stencly pro to speak on whether we can import this as an .swc or just create custom blocks that would allow for these features? 


theabbott

  • Posts: 271
~bump~

Would any Stencyl experts weigh-in on this and let us know if we could get some of the real-time DSP stuff working in Stencyl??

Quote
I've also found some amazing real-time DSP stuff thats written in AS3 - (http://www.anttikupila.com/flash/soundfx-out-of-the-box-audio-filters-with-actionscript-3/)

hansbe

  • Posts: 262
Just for synchronization of sound effects and actor animations I think a lot could be done based on  flash.utils.getTimer()

When you start the background track you need to know its BPM and a starting offset, then you record the starting time. Then you can make a sound event queue in a couple of lists. Events would trigger a callback based on if you passed the relevant time or beat.

theabbott

  • Posts: 271
Thanks Hansbe,

Squarenote got a pretty good BPM counter working already, My question is specifically about getting real-time digital signal processing working , such as a real-time reverb effect or flange etc. I know actionscript is capable of this and here's a link to exactly what I'm trying to get working in Stencyl,

http://www.anttikupila.com/flash/soundfx-out-of-the-box-audio-filters-with-actionscript-3/


 If anyone could help me out (custom code block anyone?) I will forever be in their debt!


hansbe

  • Posts: 262
I don't know the best way.
I got a custom package to work by copying it into the preview folder.
Not sure if it is safe there though, so you should keep a copy.

SquareNote

  • Posts: 20
Good news theabbott, it sounds like this is on their radar at least. Scroll down to "The Future" section on the sounds page in Stencylpedia:
http://www.stencyl.com/help/view/playing-sounds-and-music/


Thanks Hansbe,

Squarenote got a pretty good BPM counter working already, My question is specifically about getting real-time digital signal processing working , such as a real-time reverb effect or flange etc. I know actionscript is capable of this and here's a link to exactly what I'm trying to get working in Stencyl,

http://www.anttikupila.com/flash/soundfx-out-of-the-box-audio-filters-with-actionscript-3/


 If anyone could help me out (custom code block anyone?) I will forever be in their debt!

theabbott

  • Posts: 271
Sweet! Any ETA on this Stencyl team?

irock

  • *
  • Posts: 2882
Squarenote got a pretty good BPM counter working already, My question is specifically about getting real-time digital signal processing working , such as a real-time reverb effect or flange etc. I know actionscript is capable of this and here's a link to exactly what I'm trying to get working in Stencyl,

http://www.anttikupila.com/flash/soundfx-out-of-the-box-audio-filters-with-actionscript-3/

If anyone could help me out (custom code block anyone?) I will forever be in their debt!
I actually discovered that that page recently because I thought it would be cool to do a low pass filter on the music when the player's underwater.

theabbott

  • Posts: 271
Squarenote got a pretty good BPM counter working already, My question is specifically about getting real-time digital signal processing working , such as a real-time reverb effect or flange etc. I know actionscript is capable of this and here's a link to exactly what I'm trying to get working in Stencyl,

http://www.anttikupila.com/flash/soundfx-out-of-the-box-audio-filters-with-actionscript-3/

If anyone could help me out (custom code block anyone?) I will forever be in their debt!
I actually discovered that that page recently because I thought it would be cool to do a low pass filter on the music when the player's underwater.

And??? did you get anything working? - getting filters working would be cool!

irock

  • *
  • Posts: 2882
No because I have no idea how to do that.