Sound Library

MacBook Pro, OSX 10.13.4, Processing 3.3.7. Sound Library example sketch, when run no sound on the left channel, and it crashes on exit.

 * Processing Sound Library, Example 5
 * This sketch shows how to use the FFT class to analyze a stream  
 * of sound. Change the variable bands to get more or less 
 * spectral bands to work with. The smooth_factor variable determines 
 * how much the signal will be smoothed on a scale form 0-1.

import processing.sound.*;
SoundFile   sample;
FFT         fft;
AudioDevice device;

// Declare a scaling factor
int scale = 10;

// Define how many FFT bands we want
int bands = 16;

// declare a drawing variable for calculating rect width
float r_width;

// Create a smoothing vector
float[] sum = new float[bands];

// Create a smoothing factor
//float smooth_factor = 0.2;

void setup() {

  // If the Buffersize is larger than the FFT Size, the FFT will fail
  // so we set Buffersize equal to bands
  device=new AudioDevice(this,44100,bands);

  // Calculate the width of the rects depending on how many bands we have
  r_width = width/float(bands);

  // Load and play a soundfile and loop it. This has to be called 
  // before the FFT is created.
  // loop() crashes at end of file !!!
  sample=new SoundFile(this,"test.mp3");;
  // Create and patch the FFT analyzer
  fft=new FFT(this,bands);

void draw() {
  for (int i = 0; i < bands; i++) {
    //sum[i] += (fft.spectrum[i] - sum[i]) * smooth_factor;
    rect( i*r_width, height, r_width, -sum[i]*height*scale );


  • Answer ✓

    edit post, highlight code , press ctrl-o to format.

    minim is more mature than the sound library, try that.

  • Thanks, I will give it a try 8^)))

  • It appears the errors when using SoundFile. If, instead, I use the mic as input there are no errors.

  • I would double check your mp3.

  • Thanks koogs. To be more specific, if I comment out the camera and analyze code, the sound file plays in stereo (no missing channel) with no errors. I'm pretty sure it's not the mp3.

  • This is the error message - "ERROR: /synth/map/input: Audio input index 0 out of range for synth 2"

Sign In or Register to comment.