Results 1 to 6 of 6

Thread: Free audio library that can detect input tone frequency.

  1. #1

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Free audio library that can detect input tone frequency.

    Well, if you don't know the frequency, then the only way is FFT

    You should be able to find code that is using FFT, and see how it works.

    PS. Why did you post in General Developer Forum ?

  3. #3

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Free audio library that can detect input tone frequency.

    Thanks. I'll have to read through that article
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  4. #4
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    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.

  5. #5

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    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;
    }
    Attached Files Attached Files
    Last edited by CVMichael; Oct 28th, 2008 at 08:11 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width