How do I get the amplitude from an audio file?

import processing.sound.*;
Amplitude amp;
AudioIn in;
SoundFile file;
float[] amp_values;

void setup()
{
  file = new SoundFile(this, "audio.mp3");
  
  in = new AudioIn(this);
  file.play();
  in.start();
  
  amp.input(in);
}

void draw()
{
  println(amp.analyze());
}

So currently this is my code to attempt to get the audio from the audio file but here is the error message:

Jul 26, 2020 2:54:18 PM com.jsyn.devices.javasound.JavaSoundAudioDevice <init>
INFO: JSyn: default output latency set to 80 msec for Windows 10
NullPointerException
Could not run the sketch (Target VM failed to initialize).
For more information, read revisions.txt and Help ? Troubleshooting.

I am not too sure why this is happening

Edit: I have the audio.mp3 in the same directory as my project.

Hello,

There are lots of examples that come with Processing:

image

:)

I understand that but why is this failing though, I also keep getting a null pointer exception with amp.input(in); Not too sure why this is the case.

You are missing something in your code.

https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html

Look at this example:
image

:)

1 Like