Stuck on a project
in
Core Library Questions
•
2 years ago
Hi all,
i have a university project to record a sample of my voice,use fft on it, find the fundamental frequency of it and find which is the nearest note of this frequency. Final step is to turn the audio into midi using the promidi library.
So far i have done this:
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
AudioInput in;
Minim minim;
FFT fft;
void setup()
{
minim = new Minim(this);
in = minim.getLineIn(Minim.MONO, 16384, 44100);
fft = new FFT(in.bufferSize(), in.sampleRate());
}
void draw()
{
fft.forward(in.mix);
PlotSpectrum();
}
void PlotSpectrum()
{
for(int i=1; i < fft.specSize() - 1; i++)
{
line(width * i / fft.specSize(), height - 20*log10(fft.getBand(i)),width * (i-1) / fft.specSize(), height - 20*log10(fft.getBand(i-1
)));
}
}
int getMaxFreqIndex()
{
int maxi=1;
float maxSpec = fft.getBand(1);
for(int i=2; i < fft.specSize(); i++)
{
if(maxSpec < fft.getBand(i))
{
maxSpec=fft.getBand(i);
maxi=1;
}
}
return maxi;
}
float log10(float x)
{
return (log(x)/log(10));
}
Could anyone help to go any further?
i have a university project to record a sample of my voice,use fft on it, find the fundamental frequency of it and find which is the nearest note of this frequency. Final step is to turn the audio into midi using the promidi library.
So far i have done this:
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
AudioInput in;
Minim minim;
FFT fft;
void setup()
{
minim = new Minim(this);
in = minim.getLineIn(Minim.MONO, 16384, 44100);
fft = new FFT(in.bufferSize(), in.sampleRate());
}
void draw()
{
fft.forward(in.mix);
PlotSpectrum();
}
void PlotSpectrum()
{
for(int i=1; i < fft.specSize() - 1; i++)
{
line(width * i / fft.specSize(), height - 20*log10(fft.getBand(i)),width * (i-1) / fft.specSize(), height - 20*log10(fft.getBand(i-1
)));
}
}
int getMaxFreqIndex()
{
int maxi=1;
float maxSpec = fft.getBand(1);
for(int i=2; i < fft.specSize(); i++)
{
if(maxSpec < fft.getBand(i))
{
maxSpec=fft.getBand(i);
maxi=1;
}
}
return maxi;
}
float log10(float x)
{
return (log(x)/log(10));
}
Could anyone help to go any further?
1