Using Minim, when getting loudness of the song, how come I sometimes get a negative value?

import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim;
AudioPlayer audio;
final int BUFFERSIZE = 2048;




void setup()
{
  minim = new Minim(this);
  audio = minim.loadFile("audio.mp3");//, BUFFERSIZE);
  audio.play();
  size(800, 800);
  stroke(0);
}



void draw()
{
  println(audio.left.get(1)); // Sometimes I get negative value
  background(255);
  ellipse(200, 400, audio.left.get(1)*800, audio.left.get(1)*800);
  ellipse(600, 400, audio.right.get(1)*800, audio.right.get(1)*800);
  //audio.drawShape();
  
}

How is it possible for me to get a negative value? Shouldn’t it only be positive value?

Not sure per say, but have you tried taking the absolute value?

1 Like

Audio is a waveform, every sample you select could be above or below zero.
If you want to get the loudness, you should be using level(), which is the average level of the whole song
http://code.compartmental.net/minim/audiobuffer_method_level.html

1 Like