Free audio library that can detect input tone frequency.
Hey there.
Im looking to find an audio library, and have only one special need: To get the frequency of the incoming tone from a soundcard input.
Does anyone know of any? CVMichael perhaps?
Re: Free audio library that can detect input tone frequency.
Well, the link is only to give you an idea of what FFT is...
You don't really need to know the details on how it works. You just need to find code that is using FFT, and figure out how to use the FFT function.
[Edit]
I worked with FFT before, (just playing around with it, I did not do too much), so I should find some code with the FFT function. But now I'm at work, and latelly I don't touch my computer when I get home. Hopefully I'll remember to look for the code when I get home.
Last edited by CVMichael; Oct 28th, 2008 at 03:11 PM.
Re: Free audio library that can detect input tone frequency.
Thanks man I hope you can find something for me when you get home. I found this, it might be something good...
I figured I should read the entire wikipedia article to get somewhat of an understanding of whats going on, but I suppose I can do that later
I posted in general development because my question wasnt really language-specific
Re: Free audio library that can detect input tone frequency.
Hi Atheist,
Unfortunatelly this is all I found... I could not find any project using the FFT functions sorry...
I copied & pasted the C code that I had in a DLL, and I attached VB6 bas file.
Also, I did not keep the reference where I got the functions from, I did not write any of it...
But one important thing that made me undertand how it works is that the FFT does not tell you when the frequency starts, it only tells you that it is there ! (and it's amplitude).
So if you need to find out when the frequency starts, then you have to do something like this:
Start to process FFT from 0 to 512 samples (the array of samples must be a power of 2, i.e. 128, 512, 1024, etc.)
So, from 0 to 512, then process again from 32 to 544, then 64 to 576, and so on... (that is just an example, you will have to find the propper values), of course processing like this takes a lot of CPU because many samples get re-processed many times.
If you give FFT to few samples (128 or less), then it won't catch lower frequencies because one impulse (like base/brums) can take longer than 128 samples, but this depends on your samples per second (of course). So you will have to do a little math, and a lot of testing.
Sorry I don't have any ready code for you (I did not play with FFT a lot either)
Code:
/*
x and y are real and imaginary arrays of 2^m points.
dir = 1 gives forward transform
dir = -1 gives reverse transform
*/
_declspec(dllexport) void _stdcall FFT_Double(int dir, int m, double *x, double *y)
{
int n,i,i1,j,k,i2,l,l1,l2;
double c1,c2,tx,ty,t1,t2,u1,u2,z;
/* Number of points */
n = 1;
for (i=0;i<m;i++)
n *= 2;
/* Bit reversal */
i2 = n >> 1;
j = 0;
for (i=0;i < n-1; i++) {
if (i < j) {
tx = x[i];
ty = y[i];
x[i] = x[j];
y[i] = y[j];
x[j] = tx;
y[j] = ty;
}
k = i2;
while (k <= j) {
j -= k;
k >>= 1;
}
j += k;
}
//for (i=0;i < n; i++) {
// printf("x[%i] = %f y[%i] = %f\n", i, x[i], i, y[i]);
//}
//printf("-------------------------\n");
/* compute the FFT */
c1 = -1.0;
c2 = 0.0;
l2 = 1;
for (l=0;l<m;l++) {
l1 = l2;
l2 <<= 1;
u1 = 1.0;
u2 = 0.0;
for (j=0;j<l1;j++) {
for (i=j;i<n;i+=l2) {
i1 = i + l1;
t1 = u1 * x[i1] - u2 * y[i1];
t2 = u1 * y[i1] + u2 * x[i1];
x[i1] = x[i] - t1;
y[i1] = y[i] -t2;
x[i] += t1;
y[i] += t2;
}
z = u1 * c1 -u2 * c2;
u2 = u1 * c2 + u2 * c1;
u1 = z;
}
c2 = sqrt((1.0 - c1) / 2.0);
if (dir == 1)
c2 = -c2;
c1 = sqrt((1.0 + c1) / 2.0);
}
/* scaling for forward transform */
if (dir == 1) {
for (i=0;i<n;i++) {
x[i] /= n;
y[i] /= n;
}
}
return;
}
Last edited by CVMichael; Oct 28th, 2008 at 08:11 PM.