How To Get The Colors To Stay Transparent

edited November 2016 in Library Questions

Ok! So I have this code where I want to change the color of a photo based off of the input audio the code receives. I got it to do this, however, the biggest issue is that after saying a few words it changes to a solid color and stays that way. Does anyone know how to make it stay transparent? Help is appreciated! I'll post the code below.

import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
PImage img;

Minim minim;
AudioInput in;

void setup()
{
    size( 540, 687 );
    img = loadImage("Ash.jpg");
    image(img,0,0);
    }

 {   
    minim = new Minim( this );

    in = minim.getLineIn( Minim.STEREO, 512 );
}

void draw()
{
      float p = 0;
    for ( int i = 0; i < in.bufferSize(); i++ ) {
        p += abs( in.mix.get( i ) ) * 1;
    }
  loadPixels();

    for (int i=0; i<(width*height); i++){
      float r = red(pixels[i]);
      float g = green(pixels[i]);
      float b = blue(pixels[i]);

      pixels[i] = color(r*p,g/p,b+p);

}
  updatePixels();
}

void stop()
{
    in.close();
    minim.stop();
    super.stop();
}

Answers

  • This is not a solution to your problem but an alternate code. Check it out.

    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);
      loadPixels(); 
      int halfImage = width*height/2;
      for (int i = 0; i < halfImage; i++) {
        pixels[i+halfImage] = color(constrain((pixels[i]>>16)*round(random(ampt)*100),0,255) & 0xff,pixels[i]>>8 & 0xff,pixels[i]&0xff);
      }
      updatePixels();
    }
    
  • Move line 14 to within your draw method.

    Kf

Sign In or Register to comment.