Microphone controlled animation in Papervision3D

March 15, 2009 · Posted in wow 

Bartek Drozdz posted and impressive implementation using Flash microphone access and Papervision 3D.

The demo responds to microphone activity by swirling leaves in the air. You blowing into the microphone simulates the wind circulating the leaves. It’s a super fresh idea.

Check it out — so cool!

Comments

4 Responses to “Microphone controlled animation in Papervision3D”

  1. ron on March 21st, 2009 7:25 am

    “It’s a super fresh idea.”

    really? i feel like “director in 1999″ all over again…

  2. Jaakko Karhu on March 25th, 2009 7:30 pm

    Hi,

    I’m media design student from Finland, and I’m having a huge problem with an Flash application which I’m developing in a great hurry. My applications idea is that it runs different animations based on a values gotten from Mirophone.ActivityLevel, just like in this fine tutorial: http://www.wuup.co.uk/as3-basics-using-the-microphone-in-actionscript-30/. The difference is that my application is meant to be working with music. So I have line from my computers output to microphone input via stereo amplifier. When high frequenzies are cut out animation synchronizes to beat.

    Ok, my idea works out just fine theoretically and practically… for a while. After 30 minutes animation suddenly freezes and Flash player CPU usage jumps to 100%. Until that everything works perfectly, no sign of slowing down, no nothing.

    Code:

    import flash.events.*;
    import flash.display.*;
    import flash.utils.*;

    // —– MUUTTUJAT —– //

    var i = “nan”;
    var current:Number = new Number;
    var hold:Number = new Number;
    var clr:Object = new Object;
    clr = clr1;
    cbr.monitor.text = “Monitor”;
    var mph:Microphone = Microphone.getMicrophone();
    var t:SoundTransform = mph.soundTransform;
    var maxMry:Number = new Number(); //muista, että maxMry number on numeroarvo ja cbr.maxMry on tekstikenttä
    var mxrFps:Timer = new Timer(20);
    var resetNum:Number = new Number;
    var reseted:Number = new Number;

    // Kalibrointi

    cbr._system.text = “System: ” + Capabilities.os;
    cbr.runtimeEnv.text = “Runtime environment: ” + Capabilities.playerType;
    cbr._lang.text = “Language: ” + Capabilities.language;
    var showCbr:Number = new Number;
    cbr.alpha = 0;

    // —- VIRTUAALIMIKSERI JA KALIBROINTI—- //

    mph.setLoopBack(true);
    mph.gain =80;
    t.volume = 0;
    mph.soundTransform = t;

    mxrFps.addEventListener(TimerEvent.TIMER, visualize, false, 0, true);
    mxrFps.start();

    function visualize(e:TimerEvent):void {

    graph.run();
    e.updateAfterEvent();
    resetNum++;

    if (maxMry 1) {

    this.clr.stop();
    this.clr.prevFrame();
    trace(this.clr.currentFrame);

    }

    else {

    clearInterval(i);
    trace(”clear”);

    }

    }

    function hopeThisWorks() {

    removeEventListener(TimerEvent.TIMER, visualize);
    flash.system.System.gc();
    mxrFps.addEventListener(TimerEvent.TIMER, visualize, false, 0, true);
    trace(”reset”);
    cbr.monitor.text = “reseted ” + reseted + ” times”;

    }

    // —

    var holdCheck = function() {

    if(hold == 1) {

    clearInterval(i);
    this.clr.gotoAndPlay(11);
    cbr.monitor.text =”hold on”;

    }

    else {

    this.clr.gotoAndStop(current);

    }

    }

    // ——– NÄPPÄINKOMENNOT ——- //

    stage.addEventListener(KeyboardEvent.KEY_DOWN, keydown);
    stage.addEventListener(KeyboardEvent.KEY_UP, keyrelease);

    // =======ON PRESS======== //

    function keydown(event:KeyboardEvent):void {

    cbr.tellKey.text = “Keycode: ” + event.keyCode;

    // —- VALOKONTROLLI —- //

    if (event.keyCode == 16) { // Shift

    clearInterval(i);
    this.clr.gotoAndPlay(11);
    hold = 0;
    trace(”painettu”);

    }

    //—- NÄYTÄ KALIBROINTI —- //

    if (event.keyCode == 106) {

    if (showCbr == 1) {

    cbr.alpha = 0;
    showCbr = 0;

    }

    else {

    cbr.alpha = 1;
    showCbr = 1;

    }

    }

    // —- HOLD —- //

    if (event.keyCode == 220) { // Tähti

    hold = 1;
    trace(”holdi päällä”);
    cbr.monitor.text =”hold pushed”;

    }

    // —- VÄRIT —- //

    if (event.keyCode == 49) {

    current = this.clr.currentFrame;
    this.clr.gotoAndStop(1);
    clr = clr1; //Valkoinen
    holdCheck();

    }

    if (event.keyCode == 50) {

    current = this.clr.currentFrame;
    this.clr.gotoAndStop(1);
    clr = clr2; // Turkoosi
    holdCheck();

    }

    // —- PÄÄKLIPIT —- //

    if (event.keyCode == 81) {

    gotoAndStop(1);
    trace(”q pressed”);

    }

    if (event.keyCode == 87) {

    gotoAndStop(2);
    trace(”w pressed”);

    }

    }

    // ====== ON RELEASE ====== //

    function keyrelease(event:KeyboardEvent):void {

    // —– VALOKONTROLLI —— //

    if (event.keyCode == 16) {

    i = setInterval(rwd, 20);

    }

    }

    stop();

    Link to .swf: http://www.karhucreations.fi/koostotesti.swf
    Link to .fla: http://www.karhucreations.fi/koostotesti.fla

    I made a little calibration app which comes visible when numpad * is pressed. Colours can be controlled a little bit with shift, *, 1 and 2 -buttons. I’d like to remind that my keyboard is finnish so some differences my come up. And somehow colors aren’t running right on browser, but they work only in standalone player.

    Yeah, I know… technically my code… well sucks. But still I don’t know how it explains my mysterious problem and I’m not able to track down the problem. After all, as I mentioned, I’m media designer, not coder. The code might seem messy, but I left my desperate attempts to figure this issue out to be seen. I’ve been readin whole bunch of articles and forums, and I just can’t find any solution to this. I’m using newest Flash Player version and my operating system is Mac OS X 10.5.6.

    The reason why I’m so conserned about this issue is that I’ve promised to handle visualisations in an event on 4th april, so there is only 1,5 weeks left to deadline. Visualisations are projected on the wall with four projectors, so when I screw up, there is no doubt about that everybody in the club will know who did it…

    You might wonder, why I started making Video Jocky -application with Flash? Well, I checked out some VJ applications, and they seemed pretty, how would I put it, lame to me. Yes, I could easily sync some videoclips to music with them, but honestly I think this way I get more freedom for my creativity and later developement. Am I stubborn? Well, might be. Am I stupid? Definetly. But I can’t emphasize enough how much I would appreciate if someone helps me to solve this annoying problem.

    Feel free to also contact me straight to e-mail: karhunjaakko@hotmail.com.

    Best regards,

    Jaakko Karhu,
    Finland

    PS. this blog is awesome idea!

  3. mark on April 14th, 2009 7:55 pm

    It is the coolest site,keep so!

  4. mark on April 15th, 2009 10:21 am

    thanks !! very helpful post!