Content

Bill Gates Touched My Mac Book Pro

Astro Dynamic Sound!

Thursday 15 May 2008 - Filed under Flash

Andre Michelle and others have been telling Adobe to Make Some Noise, and Adobe has listened!

A preview release of Flash Player 10 “Astro” was released today, and in it is the capability to dynamically create sounds. See this demo (of course you’ll need the new player installed):

http://www.bit-101.com/astro/sound01.html

Here I’m creating two wave forms, one controlled by the mouse’s X position, and one by the Y, and combining them into a single dynamic sound, also visualized.

The way the new sound creation works is you listen for a “SAMPLES_CALLBACK” event on the sound object. This is fired when the playing sound object is almost out of sound to play. In the event handler for this event, you fill up the sound’s sampleCallbackData property with a bunch of new sample. This property is a byte array, so you write a bunch of floating point numbers to it. One for the left channel, then one for the right channel.

Here is about the simplest example:

[as]var sound:Sound = new Sound();
sound.addEventListener(Event.SAMPLES_CALLBACK, onSamplesCallback);
sound.play();

var freq:Number = 440;
var rate:Number = 44100;
var phase:Number = 0;

function onSamplesCallback(event:Event):void
{
for(var i:int = 0; i < 512; i++)
{
phase += freq / rate;
var phaseAngle:Number = phase * Math.PI * 2;
var sample:Number = Math.sin(phaseAngle);
sound.samplesCallbackData.writeFloat(sample);
sound.samplesCallbackData.writeFloat(sample);
}
}[/as]

Note that these are beta APIs and are likely to change. If you are viewing this post any time after spring / early summer 2008, the above code will probably not compile, and I can't even guarantee that the SWF will work in future versions of the player. But this is a glimpse of what is to come.

freq is the frequency of the sound you want to create. rate is 44100 samples per second, which is what the new model uses. Use phase to hold a number, multiplied times 2PI to give you the angle, take the sine of that angle to get a sine wave. We write that to samplesCallbackData twice - once for left, once for right. You could write different values here to go stereo. Here, we write 512 samples at a time. When those are almost used up, we'll get another callback and write another 512, so the sound will continue to play.

Thanks to Tinic Uro for pushing this one through! A lot more (and more accurate and better coded) information here: http://www.kaourantin.net/2008/05/adobe-is-making-some-noise-part-2.html

2008-05-15  »  keith

Talkback x 30

  1. Hrundik
    15 May 2008 @ 7:20 am

    How do you compile it?

  2. kp
    15 May 2008 @ 7:46 am

    You can’t right now. When some version of Flash CS4 is released, you’ll be able to.

  3. Iain
    15 May 2008 @ 8:30 am

    How do YOU Keith Peters compile it?

  4. kp
    15 May 2008 @ 8:45 am

    haha. OK, OK, sorry to be the big mystery man. :)

    Obviously, I have an unreleased version of a Flash authoring program that will compile to this player. Adobe has been cool enough to let those with access to this post samples to show off the new player features, but has asked that we limit the discussion to the player features, not the authoring program. Hopefully they will release some kind of public beta at some point so that everyone can play with it, not just drool over it.

  5. Iain
    15 May 2008 @ 9:01 am

    Are you allowed to share any documentation you were given? Would be nice to see the specific new classes/functions that are available.

  6. kp
    15 May 2008 @ 9:09 am

    hmm… I was probably pushing it showing code, as the APIs are likely going to change, but Tinic had already released stuff. I’ll wait for Adobe people to release code and documentation.

  7. Saeed Ashour
    15 May 2008 @ 10:53 am

    Hi ….

    are you planing to show more demos in the near future? like demo about the new text engine .

    thanks

  8. kp
    15 May 2008 @ 11:02 am

    yes, I’m sure I’ll be showing more stuff.

  9. Adobe Flash Player 10 | Astro | Beta Release | Circle Cube Studio
    15 May 2008 @ 11:07 am

    [...] is also reworking the Sound API as well, here’s an example from Keith and Tinic’s Posts (as always with much detail): Adobe is Making Some Noise Part 1, Part 2, [...]

  10. Danny
    15 May 2008 @ 11:25 am

    Keith,
    How much faster is F10 when compiled to it? For example, a regular for loop in F9 vs a regular for loop in F10…

    Does your confidential authoring tool support ECMA 4 (or AS4)??

    This is so exciting!

  11. BrandonKoopa
    15 May 2008 @ 1:02 pm

    Yesss!!! As a musician and flash lover, this excites me terribly.

  12. ethan
    15 May 2008 @ 1:20 pm

    Keith, will you be able to show samples of the p2p and local load/save file abilities?

  13. lunetta
    15 May 2008 @ 8:45 pm

    Get your wiimote and be the first to build a truly authentic flash theremin.

  14. sascha/hdrs
    15 May 2008 @ 11:53 pm

    this is cool news! anyone know if and where a standalone version of astro is available?

  15. roScripts - Webmaster resources and websites
    16 May 2008 @ 5:15 am

    Astro Dynamic Sound! » BIT-101 Blog…

    Astro Dynamic Sound…

  16. KS
    16 May 2008 @ 5:26 pm

    Why hasn’t anyone asked the Flash Platform Evangelist!?!

    http://theflashblog.com/

  17. iGman
    17 May 2008 @ 5:51 am

    Good news!
    Flashdevelop with FP10 support:
    http://www.flashdevelop.org/community/viewtopic.php?t=3039

  18. Jason Fistner
    17 May 2008 @ 3:43 pm

    @lunetta: A theremin- what an awesome idea!

    i think everyone knows this but no one posted it…
    you can compile F10 using the flex sdk

  19. Juan
    18 May 2008 @ 1:48 am

    Awsome!.

    fp10 is going to be great.

    Kieth come by my blog. well everyone is invited.

  20. A-SFUG: Another Singapore Flash User Group » New features in Flash 10
    18 May 2008 @ 7:31 am

    [...] Sound Generation: You can directly talk to the sound card (sort of)! Try Keith Peter’s demo and be a musician using your [...]

  21. Sönke Rohde » Flash Player 10 Links
    19 May 2008 @ 6:25 am

    [...] Astro Dynamic Sound [...]

  22. Tenegri’s blog » Blog Archive » Useful resources for Flash 10
    19 May 2008 @ 4:30 pm

    [...] Tinic Uro: Adobe is making some noise. Part 2 3. Tinic Uro: Adobe is making some noise. Part 3 4. Keith Peters: Astro dynamic sound! This entry was posted on Monday, May 19th, 2008 at 21:28 and is filed under Actionscript, Flash, [...]

  23. Free Adobe - Macromedia Flash Web Site Design Tips, Flash Tutorials » New Flash Collection: Flash (Player) 10
    21 May 2008 @ 3:35 am

    [...] Astro Dynamic Sound! by Keith Peters [...]

  24. FlashPlayer 10 is making noise (links) at Adobe, MAKE SOME NOISE
    21 May 2008 @ 4:12 am

    [...] Keith Peters (Bit-101) – Astro Dynamic Sound! Joa Ebert – Simple Astro Synthesizer (polyphone!) Joa Ebert – Astroboy (8Bitboy updated) [...]

  25. 一个很棒的flash player 10相关列表 , 谈了了
    22 May 2008 @ 12:39 pm

    [...] Astro Dynamic Sound! by Keith Peters [...]

  26. {Code}Trip » Astro - FileReference + Sound API
    23 May 2008 @ 11:47 pm

    [...] Astro Dynamic Sound, por Keith Peters [...]

  27. A-SFUG: New features in Flash 10
    9 September 2008 @ 5:41 am

    [...] Sound Generation: You can directly talk to the sound card (sort of)! Try Keith Peter’s demo and be a musician using your [...]

  28. Dimitris
    17 September 2008 @ 3:58 pm

    Would it be easy sb to update this code to the new Sound API, please?

  29. Andy Hulstkamp: From cacophony to music. Trying to create bearable evolving music in flash 10 (beta).
    25 September 2008 @ 8:07 am

    [...] make some noise Astro Dynamic Sound [...]

  30. MacOSCoders » Blog Archive » Adobe Flash Player 10 Features
    30 May 2009 @ 2:51 am

    [...] Sound class – This class has two new functions and that’s all we need… The Sound.extract command will pull out audio data as a ByteArray so you can manipulate it as you please. Using samplesCallbackData, you can then write those data back to the audio stream. Keith Peters has a great sample with code on his blog. [...]

Share your thoughts

Re: Astro Dynamic Sound!







Tags you can use (optional):
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>