15th May 2008

Astro Dynamic Sound!

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:

Actionscript:
  1. var sound:Sound = new Sound();
  2. sound.addEventListener(Event.SAMPLES_CALLBACK, onSamplesCallback);
  3. sound.play();
  4.  
  5. var freq:Number = 440;
  6. var rate:Number = 44100;
  7. var phase:Number = 0;
  8.  
  9. function onSamplesCallback(event:Event):void
  10. {
  11.     for(var i:int = 0; i <512; i++)
  12.     {
  13.         phase += freq / rate;
  14.         var phaseAngle:Number = phase * Math.PI * 2;
  15.         var sample:Number = Math.sin(phaseAngle);
  16.         sound.samplesCallbackData.writeFloat(sample);
  17.         sound.samplesCallbackData.writeFloat(sample);
  18.     }
  19. }

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

posted in Flash | 14 Comments

12th May 2008

Malfatti Circles

We have a winner. Daniel Langh was the first one to get a solution to me. Here is it is:

And the source.

Just realized there's a whole other class that goes with this. Here is its:

Line.as

A few others got solutions as well. Hope you had fun doing it. :)

posted in Flash | 4 Comments

11th May 2008

Mathworld Problem of the Week (free book!)

This week's subject is Malfatti Cirlces:

http://mathworld.wolfram.com/MalfattiCircles.html

They look something like this:

Basically, tangent circles, but each circle is also tangent to two sides of the given triangle.

The challenge would be to take the file below:

http://www.bit-101.com/blog/wp-content/uploads/2008/05/malfatti_circles.fla

and fill in the drawMalfattiCircles() method with some code that will actually draw correct Malfatti Circles. Feel free to create additional helper functions as needed. The function will be called once in the beginning and then whenever any of the triangle points are drawn.

Again, the prize is a copy of Foundation ActionScript 3.0 Animation: Making Things Move! to the first person who sends in a correct solution (or convincing enough to make me believe it is correct).

posted in Flash | 4 Comments

11th May 2008

New Blog

For the non-Flash stuff:

http://keith.bit-101.com/

posted in Flash | 1 Comment

9th May 2008

AS3 Animation in Japanese

IMG_1055

Three of these arrived today. Very impressive!

posted in Flash | 5 Comments

7th May 2008

Butterfly Function

Here's another one from MathWorld, the Butterfly Function. Non-interactive, but pretty. :)

[Just updated this one. Inadvertently left an enterFrame function in there that was redrawing it on each frame, killing the CPU. Sorry bout that.]

Source.

posted in Flash | 2 Comments

7th May 2008

Soddy Circles

We have a winner! At 4:05 a.m., I received the following from Ryan Phelan, who will get a free copy of Foundation ActionScript Animation 3.0: Making Things Move!

And the source.

As you can see, a Soddy Circle is one of the two circles which are tangent to the other three tangent circles. The inner Soddy Circle is between the three, and the outer one surrounds the three if possible, or lies off to the side if necessary.

Ryan beat out Jason Fistner by about 21 minutes, and Anselm Bradford came in less than an hour later. All three were awesome and as far as I can tell are technically accurate and well coded. Ryan was just first. I'd show the rest, but a Soddy Circle is a Soddy Circle is a Soddy Circle. :)

I think I might do a little contest like this on a regular basis, as long as my supply of books holds up.

posted in Flash | 6 Comments

6th May 2008

Tangent Circles

If you are ever a bit bored and looking for some cool material for some Flash Math Experimentation (surely there are one or two of you out there besides myself who do stuff like this), check out Wolfram Mathworld. Start browsing til you find something interesting and try to do it in Flash.

Tonight I wandered across the page on Tangent Circles and created the following piece:

Drag around by the inner circles. Any anatomical resemblance is a product of coincidence and your own imagination.

Source here.

Free copy of Foundation ActionScript 3.0: Making Things Move! to the first person who sends back the FLA altered to draw the inner and outer Soddy circles. Seriously. [Sorry, we have a winner. Contest closed.]

posted in Flash | 7 Comments

3rd May 2008

PseudoBiotic

David Tudury is a guy who used to be on the Flash forums back in the day. I remember he did some crazy 3D stuff back before Papervision was even a dream. After a long hiatus, he is back with PseudoBiotic. Nice to see some old school Flash experimentation going on. :)

posted in Flash | 4 Comments

28th April 2008

Keith Peters on Film in Toronto, co-starring, Erik Natzke, Hugh Elliot, and Phillip Kerman!

posted in General | 2 Comments

Who is reading BIT-101?
  • Advertising

  • Calendar

  • May 2008
    M T W T F S S
    « Apr    
     1234
    567891011
    12131415161718
    19202122232425
    262728293031