# How do I get the amplitude from an audio file?

**URL:** https://discourse.processing.org/t/how-do-i-get-the-amplitude-from-an-audio-file/22845
**Category:** Libraries
**Created:** [July 26, 2020, 5:00am UTC](https://discourse.processing.org/t/how-do-i-get-the-amplitude-from-an-audio-file/22845 "2020-07-26T05:00:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![anon76195010](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@anon76195010](https://discourse.processing.org/u/anon76195010)
#### Post date: [July 26, 2020, 5:00am UTC](https://discourse.processing.org/t/how-do-i-get-the-amplitude-from-an-audio-file/22845/1 "2020-07-26T05:00:51Z")

</div>

```auto
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:

```auto
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.

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [July 26, 2020, 2:43pm UTC](https://discourse.processing.org/t/how-do-i-get-the-amplitude-from-an-audio-file/22845/2 "2020-07-26T14:43:19Z")

</div>

Hello,

There are lots of examples that come with Processing:

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6d44ca5034c95f3d36a412f5c36538c5d6534776.png)

`:)`

---

<div class="post-metadata">

### Author: ![anon76195010](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@anon76195010](https://discourse.processing.org/u/anon76195010)
#### Post date: [July 27, 2020, 3:14am UTC](https://discourse.processing.org/t/how-do-i-get-the-amplitude-from-an-audio-file/22845/3 "2020-07-27T03:14:36Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [July 27, 2020, 11:39am UTC](https://discourse.processing.org/t/how-do-i-get-the-amplitude-from-an-audio-file/22845/4 "2020-07-27T11:39:06Z")

</div>

You are missing something in your code.

[https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html](https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html)

Look at this example:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/ae2f5f833dd72ccf45dc63cc5c4111c046fd3d77.png)

`:)`
