Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

PitchDetector Class Reference

#include <PitchDetector.h>

Inheritance diagram for PitchDetector:

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...

Constructor & Destructor Documentation

PitchDetector::PitchDetector (  )  [inline]

constructor

Definition at line 19 of file PitchDetector.h.

PitchDetector::~PitchDetector (  ) 

destructor, asserts that pitch_info and pitch_bin have been deleted by DoStop()

Definition at line 24 of file PitchDetector.cc.

PitchDetector::PitchDetector ( const PitchDetector  )  [private]

don't call (copy constructor)


Member Function Documentation

void PitchDetector::DoStart (  )  [virtual]

allocates and sets up pitch_info and pitch_bin, relies on EventGeneratorBase to manage event subscriptions

Reimplemented from EventGeneratorBase.

Definition at line 29 of file PitchDetector.cc.

void PitchDetector::DoStop (  )  [virtual]

deletes pitch_info and pitch_bin

Reimplemented from EventGeneratorBase.

Definition at line 53 of file PitchDetector.cc.

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.

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.

bool PitchDetector::is_pitch ( float  conf  )  [static, protected]

returns true if the confidence is above a threshold obtained from configuration

Definition at line 210 of file PitchDetector.cc.

Referenced by processEvent().

float PitchDetector::confidence ( unsigned int  p,
float  strength 
) [inline, protected]

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)

Definition at line 79 of file PitchDetector.h.

Referenced by processEvent().

static float PitchDetector::gaussian_pdf ( float  mu,
float  sigma,
float  x 
) [inline, static, protected]

returns the value at x of a gaussian with the parameters mu and sigma

Definition at line 95 of file PitchDetector.h.

Referenced by processEvent().

static const char* PitchDetector::pitch_name ( unsigned int  i  )  [inline, static, protected]

returns a string representing the musical note of a given frequency

Definition at line 101 of file PitchDetector.h.

Referenced by processEvent().

static void PitchDetector::hamming ( NEWMAT::ColumnVector v  )  [inline, static, protected]

unknown calculation, does some kind of rescaling of v (/ejt)

Definition at line 110 of file PitchDetector.h.

Referenced by processEvent().

PitchDetector& PitchDetector::operator= ( const PitchDetector  )  [private]

don't call (assignment operator)


Member Data Documentation

const unsigned int PitchDetector::fft_frames = 4 [static]

number frames to use for fft

Definition at line 12 of file PitchDetector.h.

Referenced by processEvent().

const unsigned int PitchDetector::num_pitches = 60 [static]

5 octaves, 12 pitches per octave

Definition at line 13 of file PitchDetector.h.

Referenced by confidence(), DoStart(), and processEvent().

const float PitchDetector::base_pitch = 110.0f [static]

two octaves below tuning A (440)

Definition at line 14 of file PitchDetector.h.

Referenced by DoStart().

const float PitchDetector::half_step = 1.0594630943593f [static]

twelfth root of two: $ \sqrt[12]{2} $

Definition at line 15 of file PitchDetector.h.

Referenced by DoStart().

const float PitchDetector::sqrt_2_pi = 2.506628274631f [static]

set to $ \sqrt{2\pi} $

Definition at line 16 of file PitchDetector.h.

Referenced by gaussian_pdf().

the waveform of the left channel

Definition at line 56 of file PitchDetector.h.

Referenced by processEvent().

the waveform of the right channel

Definition at line 56 of file PitchDetector.h.

Referenced by processEvent().

imaginary outputs of the FFT for left channel

Definition at line 56 of file PitchDetector.h.

Referenced by processEvent().

imaginary outputs of the FFT for right channel

Definition at line 56 of file PitchDetector.h.

Referenced by processEvent().

real outputs of the FFT for the left channel

Definition at line 56 of file PitchDetector.h.

Referenced by processEvent().

real outputs of the FFT for the right channel

Definition at line 56 of file PitchDetector.h.

Referenced by processEvent().

absolute value (magnitude) of results of FFT for left channel

Definition at line 56 of file PitchDetector.h.

Referenced by processEvent().

absolute value (magnitude) of results of FFT for right channel

Definition at line 56 of file PitchDetector.h.

Referenced by processEvent().

average of pol and por for each bin

Definition at line 56 of file PitchDetector.h.

Referenced by processEvent().

unsigned int PitchDetector::frame_sz [protected]

number of samples given by system for each frame (assumed that once started, this won't change)

Definition at line 65 of file PitchDetector.h.

Referenced by processEvent().

unsigned int PitchDetector::win_sz [protected]

number of samples to be recorded before running FFT (frame_sz * fft_frames)

Definition at line 65 of file PitchDetector.h.

Referenced by confidence(), and processEvent().

unsigned int PitchDetector::rate [protected]

sampling frequence (Hz)

Definition at line 65 of file PitchDetector.h.

Referenced by processEvent().

unsigned int PitchDetector::cur_frame [protected]

the current frame index to be filled in next, up to fft_frames, when the FFT is run

Definition at line 65 of file PitchDetector.h.

Referenced by DoStart(), and processEvent().

unsigned int PitchDetector::local_maxes [protected]

number of individual peaks

Definition at line 65 of file PitchDetector.h.

Referenced by confidence(), and processEvent().

an array of PitchInfos, one for each of num_pitches, allocated for scope spanning DoStart()/DoStop()

Definition at line 70 of file PitchDetector.h.

Referenced by confidence(), DoStart(), DoStop(), processEvent(), and ~PitchDetector().

float* PitchDetector::pitch_bin [protected]

array, holds current amplitude for each num_pitches (mono)

Definition at line 71 of file PitchDetector.h.

Referenced by DoStart(), DoStop(), processEvent(), and ~PitchDetector().

bool PitchDetector::have_fft [protected]

set to true after FFT has been computed, differentiates first filling of buffers from subsequent rewrites

Definition at line 72 of file PitchDetector.h.

Referenced by DoStart(), and processEvent().


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

Tekkotsu v4.0
Generated Thu Nov 22 00:58:35 2007 by Doxygen 1.5.4