Next Previous Contents

4. Tutorial

4.1 An example

Here's a minimal application that listens to a microphone connected to the soundcard and prints the frequency estimation of the current pitch on the console.

#include <iostream.h>

#include <libpt/libpt.hh>
#include <libpt/listener.hh>
#include <libpt/audiosource.hh>
#include <libpt/pitchquantizer.hh>

const int N = 1024;         // FFT length
const int FACTOR = 4;       // Decimation

void
main(void)
{
  AudioADC source(N/FACTOR, 1.0, srate, MIC);
  Listener listener(source, N, FACTOR, 0.05, 100.0, 
                    0, "sample.wisdom");

  while (1 == 1)
    {
      freq = listener.EstimateFrequency();

      if (freq > Listener::UNDEFINITE)  
        cout "\r           " << freq;
    }
}

Next Previous Contents