Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

PitchDetector Class Reference

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

#include <PitchDetector.h>

Inheritance diagram for PitchDetector:

Detailed Description

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

Definition at line 10 of file PitchDetector.h.

List of all members.

Classes

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

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 doEvent ()
 Delegate function for event processing, the event itself is pointed to (only for the duration of the doEvent() call!) by event.
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()
floatpitch_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)

Constructor & Destructor Documentation

PitchDetector::PitchDetector (  ) 

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 25 of file PitchDetector.cc.

PitchDetector::PitchDetector ( const PitchDetector  )  [private]

don't call (copy constructor)


Member Function Documentation

float PitchDetector::confidence ( unsigned int  p,
float  strength 
) [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 doEvent().

void PitchDetector::doEvent (  )  [virtual]

Delegate function for event processing, the event itself is pointed to (only for the duration of the doEvent() call!) by event.

Default implementation watches for 'private' text message events (those forwarded by a BehaviorSwitchControl from ControllerGUI input) and will publically rebroadcast them. The idea is that your own processEvent gets first dibs, but if the behavior doesn't handle the text message, it will be handed off for others.

Reimplemented from BehaviorBase.

Definition at line 67 of file PitchDetector.cc.

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 30 of file PitchDetector.cc.

void PitchDetector::doStop (  )  [virtual]

deletes pitch_info and pitch_bin

Reimplemented from EventGeneratorBase.

Definition at line 54 of file PitchDetector.cc.

static float PitchDetector::gaussian_pdf ( float  mu,
float  sigma,
float  x 
) [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 doEvent().

static std::string PitchDetector::getClassDescription (  )  [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 [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.

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

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

Definition at line 110 of file PitchDetector.h.

Referenced by doEvent().

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

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

Definition at line 209 of file PitchDetector.cc.

Referenced by doEvent().

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

don't call (assignment operator)

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

returns a string representing the musical note of a given frequency

Definition at line 101 of file PitchDetector.h.

Referenced by doEvent().


Member Data Documentation

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

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 doEvent(), and doStart().

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

number frames to use for fft

Definition at line 12 of file PitchDetector.h.

Referenced by doEvent().

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 doEvent().

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

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 doEvent(), and doStart().

imaginary outputs of the FFT for left channel

Definition at line 56 of file PitchDetector.h.

Referenced by doEvent().

imaginary outputs of the FFT for right channel

Definition at line 56 of file PitchDetector.h.

Referenced by doEvent().

the waveform of the left channel

Definition at line 56 of file PitchDetector.h.

Referenced by doEvent().

unsigned int PitchDetector::local_maxes [protected]

number of individual peaks

Definition at line 65 of file PitchDetector.h.

Referenced by confidence(), and doEvent().

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(), doEvent(), and doStart().

array, holds current amplitude for each num_pitches (mono)

Definition at line 71 of file PitchDetector.h.

Referenced by doEvent(), doStart(), doStop(), and ~PitchDetector().

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(), doEvent(), doStart(), doStop(), and ~PitchDetector().

average of pol and por for each bin

Definition at line 56 of file PitchDetector.h.

Referenced by doEvent().

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

Definition at line 56 of file PitchDetector.h.

Referenced by doEvent().

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

Definition at line 56 of file PitchDetector.h.

Referenced by doEvent().

unsigned int PitchDetector::rate [protected]

sampling frequence (Hz)

Definition at line 65 of file PitchDetector.h.

Referenced by doEvent().

real outputs of the FFT for the left channel

Definition at line 56 of file PitchDetector.h.

Referenced by doEvent().

real outputs of the FFT for the right channel

Definition at line 56 of file PitchDetector.h.

Referenced by doEvent().

the waveform of the right channel

Definition at line 56 of file PitchDetector.h.

Referenced by doEvent().

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

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 doEvent().


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

Tekkotsu v5.1CVS
Generated Mon May 9 04:59:14 2016 by Doxygen 1.6.3