Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Sound Library

$
0
0

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() { size(320,240); background(0);

// 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"); sample.play(); // Create and patch the FFT analyzer fft=new FFT(this,bands); fft.input(sample); }

void draw() { background(0); fill(0,128,255); noStroke(); fft.analyze(); for (int i = 0; i < bands; i++) { //sum[i] += (fft.spectrum[i] - sum[i]) * smooth_factor; sum[i]=fft.spectrum[i]; rect( ir_width, height, r_width, -sum[i]height*scale ); } }


Viewing all articles
Browse latest Browse all 2896

Trending Articles