audioinputprocessingminim

How to get the currently playing audio as audio input in Processing?


I am creating a simple audio visualizer. Here is the code

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

Minim minim;
AudioInput in;
FFT fft;

int w;

PImage fade;

void setup() {
  size(640,480); // draw screen
  minim = new Minim(this); // new minim object

  in = minim.getLineIn(Minim.STEREO,512); // audio input from microphone (have to change this to get currently playing audio)

  fft = new FFT(in.bufferSize(),in.sampleRate()); // new fft object

  fft.logAverages(60,7);

  stroke(255); 
  w=width/fft.avgSize();
  strokeWeight(w); // display lines as bars

  background(0);

}

void draw() {
  background(0);
  fft.forward(in.mix); //generate fourier series

  for(int i = 0; i < fft.avgSize(); i++) {
    line((i*w)+(w/2),height, (i*w)+(w/2), height - fft.getAvg(i)*4); // draw bars
  }
}

Here in = minim.getLineIn(Minim.STEREO,512); gives the audio input from the from the microphone. But I need to get currently playing audio (What you hear from the speaker or headphone) of the computer and visualize it.

If there is any method or any other way to get currently playing audio as the input please mention. Thanks in advance :)


Solution

  • Questions like this are best answered by reading the reference:

    An AudioInput is a connection to the current record source of the computer. How the record source for a computer is set will depend on the soundcard and OS, but typically a user can open a control panel and set the source from there. Unfortunately, there is no way to set the record source from Java.

    In other words, this is a setting that the user has to change in their control panel. This seems to be confirmed here and here.