Check whether an audio input is done initializing?

edited September 2016 in Library Questions

Often when I execute the following code, I'll get a crash. "Java Platform SE binary has stopped working" (Windows 7)

But at the point of the crash, a couple of max values were already printed in the console. All of them being 0.0.

import processing.sound.*;

FFT fft;
AudioIn in;
int bands = 512;
float[] spectrum = new float[bands];

void setup() {
  size(512, 360);

  // Create an Input stream which is routed into the Amplitude analyzer
  fft = new FFT(this, bands);
  in = new AudioIn(this, 0);

  // start the Audio Input

  // patch the AudioIn

void draw() { 
  background(255, 0, 0);

  // have to check somehow whether this is ready

  float max = 0;
  for(int i = 0; i < bands; i++){
    // The result of the FFT is normalized
    // draw the line for frequency band i scaling it up by 5 to get more amplitude.
    line( i, height, i, height - spectrum[i]*height*50 );
    if(spectrum[i]*50 > max)
      max = spectrum[i];

  print(max + "\n");


  • I tested your code and it works fine in 3.1.2

    I will suggest running other examples testing the AudioIn to ensure your sound system is being recognized. This is just a guess and hopefully a starting point.


  • I intentionally wrote "often". ;) Sometimes, it does work just fine.

Sign In or Register to comment.