Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : Do you know whether it is possible or not to put minim and video together in one sketch?

$
0
0
Thank you for answering me !!  I didn't know how to make a question m.m 

Here is First code
-






import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim;
AudioInput voice;
FFT fft;
float volume;
float dampedVolume;
float daming = 0.005;
boolean debug = false;
float filtering = 100;
float volumeThreshold = 100;

void setup()
{
  size(512, 512);
  minim = new Minim(this);
  voice = minim.getLineIn(Minim.STEREO, 2048);
  fft = new FFT(voice.bufferSize(), voice.sampleRate());
  smooth();
}

void draw()
{
  background(0);
  stroke(255);
  fft.forward(voice.mix);
  volume = 0;
  for(int i = 0; i < filtering; i++){
    if(debug)  {line(i, height, i, height - fft.getBand(i)*4);}
    volume += fft.getBand(i);
  }
  volume *= 0.25;
  dampedVolume = dampedVolume + (volume - dampedVolume)*daming;

  
  ellipse(width/2, height/2, dampedVolume, dampedVolume);
}

void keyPressed() {
   if(key == 'a')  debug = !debug; 
}

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









-
This code works!
and
with this code, I want to apply this code to every pixel on the video!
so I tried like this.
(Second trial  :  First code + 'Mirror' from the example)
-








Balloon [] balloons;

 
import processing.video.*;


int cellSize = 5;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;


void setup() {
  size(640, 480, P2D);
  frameRate(30);
  cols = width / cellSize;
  rows = height / cellSize;
  colorMode(RGB, 255, 255, 255, 100);

  // Uses the default video input, see the reference if this causes an error
  video = new Capture(this, width, height, 20);
  
  background(0);
  
  balloons = new Balloon [width*height/cellSize];
  for (int i = 0; i < balloons.length; i++) {
    balloons[i] = new Balloon((video.width - x - 1) + y*video.width;  );
  }
}
  



void draw() { 
  if (video.available()) {
    video.read();
    video.loadPixels();
    
    // Not bothering to clear background
    // background(0);
  
    // Begin loop for columns
    for (int i = 0; i < cols; i++) {
      // Begin loop for rows
      for (int j = 0; j < rows; j++) {
      
        // Where are we, pixel-wise?
        int x = i*cellSize;
        int y = j*cellSize;
        int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image
      
        float r = red(video.pixels[loc]);
        float g = green(video.pixels[loc]);
        float b = blue(video.pixels[loc]);
        // Make a new color with an alpha component
        color c = color(r, g, b, 75);
      
        // Code for drawing a single rect
        // Using translate in order for rotation to work properly
       
        rectMode(CENTER);
        fill(c);
        noStroke();
        // Rects are larger than the cell for some overlap
        rect(0, 0, cellSize+6, cellSize+6);
       
      }
    }
  }
    for(int i=0; i< 640/5 + 480/5; i++){
   balloon.drawdraw i;
}
}





class Balloon{
  
 
  import ddf.minim.*;
  import ddf.minim.analysis.*;

  Minim minim;
  AudioInput voice;
  FFT fft;
  float volume; 
  float dampedVolume;
  float daming = 0.005;
  boolean debug = false;
  float filtering = 100;
  float volumeThreshold = 100;
  int a;
  int b;
  
  
  
  Balloon (int xpos, int ypos){
    a = xpos;
    b = ypos;
  }
  

void setupsetup()
{
  minim = new Minim(this);
  voice = minim.getLineIn(Minim.STEREO, 2048);
  fft = new FFT(voice.bufferSize(), voice.sampleRate());
  smooth();
}

void drawdraw()
{
  noStroke();
  fft.forward(voice.mix);
  volume = 0;
  for(int i = 0; i < filtering; i++){
    volume += fft.getBand(i);
  }
  volume *= 0.25;
  dampedVolume = dampedVolume + (volume - dampedVolume)*daming;

  
  ellipse(a, b, dampedVolume, dampedVolume);
}


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











It didn't work... even for me, It wasn't strange that this code doesn't work.

So, I decided to make a small step - Making just array with the First code.

like this

(third trial : just array the First code)

-











Balloon[] balloons;

  import ddf.minim.*;
  import ddf.minim.analysis.*;

  Minim minim;
  AudioInput voice;
  FFT fft;

void setup(){
  size(600,600);
  
  minim = new Minim(this);
  voice = minim.getLineIn(Minim.STEREO, 2048);
  fft = new FFT(voice.bufferSize(), voice.sampleRate());
  smooth();

}

void draw(){
  background(255);
  
  for(int i=0; i<balloons.length; i++){
    balloons[i].live(i*50,100);
  }
}


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



class Balloon{


float volume;
float dampedVolume;
float daming = 0.005;
float filtering = 100;
float volumeThreshold = 100;


void live(int a,int b)
{
  
  fft.forward(voice.mix);
  volume = 0;
  for(int i = 0; i < filtering; i++){
    
    volume += fft.getBand(i);
  }
  volume *= 0.25;
  dampedVolume = dampedVolume + (volume - dampedVolume)*daming;

  ellipse(a, b, dampedVolume, dampedVolume);
}




}












the outcome was just full gray box...
with this message :    NullPointerException


well... my Final goal was to mix the first code with video(Mirror)code.
however, now I just want to know how to array the minim code,
and If possible, how to apply the First code to pixel in the picture(PImage).

Please...
 Masters help... m






Viewing all articles
Browse latest Browse all 1768

Trending Articles