Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Problem sensing microphone

$
0
0
Hi, I´m using the Minim library to use the microphone of my mac computer, I want to play my violin and sensing the sound (with this microphone) then I want to convert the frecuency in midi notes to compare each note with a midi score that I have in processing, the problem is when I play my violin don´t sensing correctly the note, more in the bass string and have a delay to detect with note is. I don´t know if I need a calibrator and how can I do it? or if I need other thing? This is the code for sensing the microphone and convert to midi note


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

Minim minim;
AudioInput in;
FFT fft;
float pitch;
float highestAmp = 0, freq, frequency;
float amplitude;

void setup()
{
  size(512, 200, P2D);
  minim = new Minim(this);
  minim.debugOn();
  in = minim.getLineIn(Minim.STEREO);
  fft = new FFT(in.bufferSize(), in.sampleRate());
}

void draw()
{
  background(0);
  stroke(255);

  fft.forward(in.mix);
  highestAmp = 0;
  
   for(int i = 0; i<20000; i++){
     amplitude = fft.getFreq(i);
     if(amplitude>highestAmp){
       highestAmp = amplitude;
       frequency = i;
     }  
   }    
   pitch = round(69 + 12*(log(frequency/440.0)/log(2.0)));             
   println(pitch);
}

void stop()
{
  minim.stop();  
  super.stop();
}

Viewing all articles
Browse latest Browse all 1768

Trending Articles