Could not run the sketch (Target VM failed to initialize)

Help, I am getting this error message every time a run a code: Could not run the sketch (Target VM failed to initialize). have tried to run other included examples and they work pretty well, but not my code.
here it is:

import processing.sound.;
import processing.serial.

SoundFile sample;
FFT fft;
AudioDevice device;

Serial myPort;

float[] spectrum =new float[3];
float r, g, b;

float smoothing = 0.2;

public void setup() {
size(640, 360); // Size of the serial window

device = new AudioDevice(this, 44000, 3);

sample = new SoundFile(this, “TwentyOnePilotsOdeToSleep.mp3”); // select your music here

fft = new FFT(this, 3);

myPort = new Serial (this, “COM3”, 9600); // Set the com port and the baud rate according to the Arduino IDE

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


spectrum[0] += (fft.spectrum[0] - spectrum[0]) * smoothing;
spectrum[1] += (fft.spectrum[1] - spectrum[1]) * smoothing;
spectrum[2] += (fft.spectrum[2] - spectrum[2]) * smoothing;

r = spectrum[0]height4;
g = spectrum[1]height4;
b = spectrum[2]height4;

line( width/3 - 50, height, width/3 - 50, height - r );
line( 2width/3 - 50, height, 2width/3 - 50, height - g);
line( width - 50, height, width - 50, height - b );

myPort.write((int)r % 255);
myPort.write((int)g % 255);
myPort.write((int)b % 255);


Great you tested with some simpler files. I suggest you use the minim library for your project instead. As it is right now, the sound library is being revamped via a GSOC project. You might want to reach the current developers and comment about your problem or go ahead and use minim, which you can be installed via the Contribution Manager in the PDE.


Thank kfrajer. I will try with the minim library.

@jkarlos4, I think the problem is with

fft = new FFT(this, 3);

because the FFT’s size parameter can only be a power of 2 (i.e. 2, 4, 8, 16, 32,…). Even if it worked with an odd number such as 3, a spectral analysis on such few samples wouldn’t really give you meaningful results, it will mostly look like noise. Maybe try again with values of 64 or higher and take sums across the 64 values of spectrum to create the RGB values?

You can probably also remove the following line altogether, it’s not really necessary as long as your FFT size parameter isn’t greater than 128:

device = new AudioDevice(this, 44000, 3);

Let us know if it works!

I confirm, this is the error you get:

ERROR: /synth/map/input: Audio input index 0 out of range for synth 2
Could not run the sketch (Target VM failed to initialize).
Make sure that you haven't set the maximum available memory too high.
For more information, read revisions.txt and Help ? Troubleshooting.

when you set the buffer size to 3. I tried 64 and 512 and it worked (I commented out serial related lines).

Check previous FFT post if you want to see previous demos and their code.


This is a great community.
Thanks Kfrajer and Kevinstadler for your help. I have tried by changing the values of the buffer size to 512, as you told me, and it work.

device = new AudioDevice(this, 44000, 512);
fft = new FFT(this, 512);

Now I got a decent RGB tape that light by music.

1 Like

I have got this error once. I don’t know why. It just seems like there is a random chance of it happening. (Processing 4 beta)