Omar
Omar

Reputation: 1091

Find volume of mic input using minim lib in Processing

I'm trying to get the volume level from my mic to adjust the size of a box (louder = bigger). But I have the following issues: a) getGain seems to be giving me -64 constantly b) getVolume doesnt seem to be available

I edited a Processing example to respond to the mic rather than the audio file provided but could not figure out how to get the volume

Here is what I have

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

Minim       minim;
AudioInput  accessMic;
FFT         fft;
float boxSize;

void setup () {
  size(512, 200, P3D);
  minim = new Minim(this);
  accessMic = minim.getLineIn();
  rectMode(CENTER);

}

void draw() {
  background(255);
  boxSize = accessMic.getGain();
  stroke(255);
  println(boxSize);
  fill(0);
  rect(width/2,height/2,boxSize,boxSize);
}

Any help you can give me would be greatly appreciated Thanks

Upvotes: 3

Views: 3567

Answers (2)

K F
K F

Reputation: 1546

Have you considered using the sound library in Processing?

Here is an example.

In minim, you have to use the AudioBuffer which is exactly what in.left() and in.right() are. This should give you the same results as the Amplitude() function.

Upvotes: 0

Reed Tothong
Reed Tothong

Reputation: 41

I had similar problem with .getGain(); in minim
I got around to something similar by using left.level(); which returns float between 0 and 1. And obviously that only take into account one of the stereo input, you can totally also do .right.level(); for result from another channel there.

so your code could lookin kinda like
boxSize = accessMic.left.level() * 100;
and you'll get box with a size bouncing between 0 and 100!

hope that helps!

Upvotes: 1

Related Questions