How to control tint of image in Processing with audio output volume

elfelf
edited August 2016 in Library Questions

Ok, so I'd like to project a few pictures to the wall. I'd like the tint to change gradually, depending on the volume of audio output. The audio is coming from audio samples (so not MIDI instruments, if that makes any difference) in Ableton Live Suite, which I'm controlling in real-time. Any codes/links would be super helpful - stressed postgrad student :) Thank you!

Answers

  • Answer ✓

    Minim or the sound library will let you access the wave form of the input.

    Maybe there root mean squared value from that (which I think you'll need to calculate yourself) will give you one value that you can map to the colour (see colormode hsb in reference). It might not be as gradual as you want though but you might be able to smooth it.

  • elfelf
    edited August 2016

    Thank you! I made it work like this in the end.

    import processing.sound.*;
        Amplitude amp;
        AudioIn in;
        float ampt;
        PImage photo;
    
        void setup() {
          size(1200, 800);
          background(255);
    
          // Create an Input stream which is routed into the Amplitude analyzer
          amp = new Amplitude(this);
          in = new AudioIn(this, 0);
          in.start();
          amp.input(in);
          photo = loadImage("<filename>");
        }      
    
        void draw() {
          background(255);
          ampt = amp.analyze();
          println(ampt);
    
          float myColor = ampt*1000; 
           tint(noise(myColor)*100, noise(myColor)*200, noise(myColor)*300);
           image(photo, 0, 0, width, height);
        }
    
  • This next code reacts to the magnitude if the input sound:

    Kf

    import processing.sound.*;
        Amplitude amp;
        AudioIn in;
        float ampt;
        PImage photo;
    
        void setup() {
          size(1200, 800);
          background(255);
    
          // Create an Input stream which is routed into the Amplitude analyzer
          amp = new Amplitude(this);
          in = new AudioIn(this, 0);
          in.start();
          amp.input(in);
          photo = loadImage("fig.jpg");
        }      
    
        void draw() {
          background(255);
          ampt = amp.analyze();
          println(ampt);
    
          float myColor = ampt*256; 
           tint((myColor), (myColor), (myColor));
           image(photo, 0, 0, width, height);
        }
    
  • I like the last code. Tried with one of my pictures and it reminds me as it looks when I am blinking eyes. Its all dark, but the sound wakens it up.

Sign In or Register to comment.