Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

PitchDetector Class Reference

#include <PitchDetector.h>

Inheritance diagram for PitchDetector:

Inheritance graph
[legend]
List of all members.

Detailed Description

Generates a PitchEvent whenever a notable frequency is detected using FFT.

Definition at line 10 of file PitchDetector.h.

Public Member Functions

 PitchDetector ()
 constructor
 ~PitchDetector ()
 destructor, asserts that pitch_info and pitch_bin have been deleted by DoStop()
virtual void DoStart ()
 allocates and sets up pitch_info and pitch_bin, relies on EventGeneratorBase to manage event subscriptions
virtual void DoStop ()
 deletes pitch_info and pitch_bin
virtual void processEvent (const EventBase &event)
 if autolistening, will receive EventRouter events concerning our own listeners
virtual std::string getDescription () const
 Gives a short description of what this particular instantiation does (in case a more specific description is needed on an individual basis).

Static Public Member Functions

static std::string getClassDescription ()
 Gives a short description of what this class of behaviors does... you should override this (but don't have to).

Static Public Attributes

static const unsigned int fft_frames = 4
 number frames to use for fft
static const unsigned int num_pitches = 60
 5 octaves, 12 pitches per octave
static const float base_pitch = 110.0f
 two octaves below tuning A (440)
static const float half_step = 1.0594630943593f
 twelfth root of two: $ \sqrt[12]{2} $
static const float sqrt_2_pi = 2.506628274631f
 set to $ \sqrt{2\pi} $

Protected Member Functions

float confidence (unsigned int p, float strength)
 returns a confidence estimate of a pitch in bin p... (actual computation used is not obvious, you'll have to stare at the code /ejt)

Static Protected Member Functions

static bool is_pitch (float conf)
 returns true if the confidence is above a threshold obtained from configuration
static float gaussian_pdf (float mu, float sigma, float x)
 returns the value at x of a gaussian with the parameters mu and sigma
static const char * pitch_name (unsigned int i)
 returns a string representing the musical note of a given frequency
static void hamming (NEWMAT::ColumnVector &v)
 unknown calculation, does some kind of rescaling of v (/ejt)

Protected Attributes

NEWMAT::ColumnVector left
 the waveform of the left channel
NEWMAT::ColumnVector right
 the waveform of the right channel
NEWMAT::ColumnVector iml
 imaginary outputs of the FFT for left channel
NEWMAT::ColumnVector imr
 imaginary outputs of the FFT for right channel
NEWMAT::ColumnVector rel
 real outputs of the FFT for the left channel
NEWMAT::ColumnVector rer
 real outputs of the FFT for the right channel
NEWMAT::ColumnVector pol
 absolute value (magnitude) of results of FFT for left channel
NEWMAT::ColumnVector por
 absolute value (magnitude) of results of FFT for right channel
NEWMAT::ColumnVector po
 average of pol and por for each bin
unsigned int frame_sz
 number of samples given by system for each frame (assumed that once started, this won't change)
unsigned int win_sz
 number of samples to be recorded before running FFT (frame_sz * fft_frames)
unsigned int rate
 sampling frequence (Hz)
unsigned int cur_frame
 the current frame index to be filled in next, up to fft_frames, when the FFT is run
unsigned int local_maxes
 number of individual peaks
PitchInfopitch_info
 an array of PitchInfos, one for each of num_pitches, allocated for scope spanning DoStart()/DoStop()
float * pitch_bin
 array, holds current amplitude for each num_pitches (mono)
bool have_fft
 set to true after FFT has been computed, differentiates first filling of buffers from subsequent rewrites

Private Member Functions

 PitchDetector (const PitchDetector &)
 don't call (copy constructor)
PitchDetectoroperator= (const PitchDetector &)
 don't call (assignment operator)

Classes

struct  PitchInfo
 stores info about the pitch currently being detected More...


Member Function Documentation

static std::string PitchDetector::getClassDescription (  )  [inline, static]

Gives a short description of what this class of behaviors does... you should override this (but don't have to).

If you do override this, also consider overriding getDescription() to return it

Reimplemented from BehaviorBase.

Definition at line 34 of file PitchDetector.h.

Referenced by getDescription().

virtual std::string PitchDetector::getDescription (  )  const [inline, virtual]

Gives a short description of what this particular instantiation does (in case a more specific description is needed on an individual basis).

By default simply returns getName(), because any calls from a BehaviorBase function to getClassDescription() are going to call BehaviorBase::getClassDescription(), not ~YourSubClass~getClassDescription(), because static functions can't be virtual in C++ (doh!)

This means that getDescription called on a pointer to a BehaviorBase of unknown subtype would always return an empty string, which is pretty useless. So instead we return the name in this situation. If you want getDescription to return getClassDescription, you'll have to override it in your subclass to do so.

Reimplemented from BehaviorBase.

Definition at line 35 of file PitchDetector.h.

void PitchDetector::processEvent ( const EventBase event  )  [virtual]

if autolistening, will receive EventRouter events concerning our own listeners

This will automatically reduce overhead by eliminating chains of events thrown that don't have any end listeners. However, this might mean your subclass's processEvent will be receiving the events from erouterEGID, and will need to call EventGeneratorBase::processEvent() in order to allow them to be used

Reimplemented from EventGeneratorBase.

Definition at line 66 of file PitchDetector.cc.


The documentation for this class was generated from the following files:

Tekkotsu v3.0
Generated Fri May 11 20:08:32 2007 by Doxygen 1.4.7