/Users/richardeakin/projects/libsms/trunk/src/harmDetection.c File Reference

Detection of a given harmonic. More...

#include "sms.h"
Include dependency graph for harmDetection.c:

Defines

#define N_FUND_HARM   6
#define N_HARM_PEAKS   4
#define FREQ_DEV_THRES   .07
#define MAG_PERC_THRES   .6
#define HARM_RATIO_THRES   .8

Functions

static int GetClosestPeak (int iPeakCandidate, int nHarm, SMS_Peak *pSpectralPeaks, int *pICurrentPeak, int iRefHarmonic)
 get closest peak to a given harmonic of the possible fundamental
static int ComparePeak (sfloat fRefHarmMag, SMS_Peak *pSpectralPeaks, int nCand, sfloat fRefHarmMagDiffFromMax)
 checks if peak is substantial
int CheckIfHarmonic (sfloat fFundFreq, SMS_HarmCandidate *pCHarmonic, int nCand)
 check if the current peak is a harmonic of one of the candidates
static int GoodCandidate (int iPeak, SMS_Peak *pSpectralPeaks, SMS_HarmCandidate *pCHarmonic, int nCand, SMS_PeakParams *pPeakParams, sfloat fRefFundamental)
 consider a peak as a possible candidate and give it a weight value,
static int GetBestCandidate (SMS_HarmCandidate *pCHarmonic, int iRefHarmonic, int nGoodPeaks, sfloat fPrevFund)
 choose the best fundamental out of all the candidates
void sms_harmDetection (SMS_AnalFrame *pFrame, sfloat fRefFundamental, SMS_PeakParams *pPeakParams)
 main harmonic detection function

Detailed Description

Detection of a given harmonic.


Define Documentation

#define FREQ_DEV_THRES   .07

threshold for deviation from perfect harmonics

Referenced by GoodCandidate().

#define HARM_RATIO_THRES   .8

threshold for percentage of harmonics found

Referenced by GoodCandidate().

#define MAG_PERC_THRES   .6

threshold for magnitude of harmonics with respect to the total magnitude

Referenced by GoodCandidate().

#define N_FUND_HARM   6

number of harmonics to use for fundamental detection

Referenced by ComparePeak(), and GoodCandidate().

#define N_HARM_PEAKS   4

number of peaks to check as possible ref harmonics

Referenced by sms_harmDetection().


Function Documentation

int CheckIfHarmonic ( sfloat  fFundFreq,
SMS_HarmCandidate pCHarmonic,
int  nCand 
)

check if the current peak is a harmonic of one of the candidates

Parameters:
fFundFreq frequency of peak to be tested
pCHarmonic all candidates accepted
nCand location of las candidate
Returns:
1 if it is a harmonic, 0 if it is not

Referenced by GoodCandidate().

static int ComparePeak ( sfloat  fRefHarmMag,
SMS_Peak pSpectralPeaks,
int  nCand,
sfloat  fRefHarmMagDiffFromMax 
) [static]

checks if peak is substantial

check if peak is larger enough to be considered a fundamental without any further testing or too small to be considered

Parameters:
fRefHarmMag magnitude of possible fundamental
pSpectralPeaks all the peaks
nCand number of existing candidates
fRefHarmMagDiffFromMax value to judge the peak based on the difference of its magnitude compared to the reference
Returns:
1 if big peak, -1 if too small , otherwise return 0

References SMS_Peak::fMag, N_FUND_HARM, and sfloat.

Referenced by GoodCandidate().

static int GetBestCandidate ( SMS_HarmCandidate pCHarmonic,
int  iRefHarmonic,
int  nGoodPeaks,
sfloat  fPrevFund 
) [static]

choose the best fundamental out of all the candidates

Parameters:
pCHarmonic array of candidates
iRefHarmonic reference harmonic number
nGoodPeaks number of candiates
fPrevFund reference fundamental
Returns:
the integer number of the best candidate

References SMS_HarmCandidate::fFreq, and sfloat.

Referenced by sms_harmDetection().

static int GetClosestPeak ( int  iPeakCandidate,
int  nHarm,
SMS_Peak pSpectralPeaks,
int *  pICurrentPeak,
int  iRefHarmonic 
) [static]

get closest peak to a given harmonic of the possible fundamental

Parameters:
iPeakCandidate peak number of possible fundamental
nHarm number of harmonic
pSpectralPeaks pointer to all the peaks
pICurrentPeak pointer to the last peak taken
iRefHarmonic reference harmonic number
Returns:
the number of the closest peak or -1 if not found

References sfloat.

Referenced by GoodCandidate().

static int GoodCandidate ( int  iPeak,
SMS_Peak pSpectralPeaks,
SMS_HarmCandidate pCHarmonic,
int  nCand,
SMS_PeakParams pPeakParams,
sfloat  fRefFundamental 
) [static]

consider a peak as a possible candidate and give it a weight value,

Parameters:
iPeak iPeak number to be considered
pSpectralPeaks all the peaks
pCHarmonic all the candidates
nCand candidate number that is to be filled
pPeakParams analysis parameters
fRefFundamental previous fundamental
Returns:
-1 if not good enough for a candidate, return 0 if reached the top frequency boundary, return -2 if stop checking because it found a really good one, return 1 if the peak is a good candidate

Bug:
sfloat comparison to 0

References CheckIfHarmonic(), ComparePeak(), SMS_HarmCandidate::fFreq, SMS_Peak::fFreq, SMS_HarmCandidate::fFreqDev, SMS_HarmCandidate::fHarmRatio, SMS_HarmCandidate::fMag, SMS_Peak::fMag, SMS_HarmCandidate::fMagPerc, SMS_PeakParams::fRefHarmMagDiffFromMax, FREQ_DEV_THRES, GetClosestPeak(), HARM_RATIO_THRES, SMS_PeakParams::iRefHarmonic, SMS_PeakParams::iSoundType, MAG_PERC_THRES, N_FUND_HARM, sfloat, and SMS_SOUND_TYPE_NOTE.

Referenced by sms_harmDetection().

Here is the call graph for this function:

void sms_harmDetection ( SMS_AnalFrame pFrame,
sfloat  fRefFundamental,
SMS_PeakParams pPeakParams 
)

main harmonic detection function

find a given harmonic peak from a set of spectral peaks, put the frequency of the fundamental in the current frame

Parameters:
pFrame pointer to current frame
fRefFundamental frequency of previous frame
pPeakParams pointer to analysis parameters
Todo:

is it possible to use pSpectralPeaks instead of SMS_AnalFrame?

move pCHarmonic array to SMS_AnalFrame structure

  • this will allow for analysis of effectiveness from outside this file This really should only be for sms_analyzeFrame

<

Bug:
sfloat comparison to zero

References SMS_HarmCandidate::fFreq, SMS_Peak::fFreq, SMS_AnalFrame::fFundamental, SMS_PeakParams::fHighestFundamental, SMS_PeakParams::fLowestFreq, SMS_Peak::fMag, GetBestCandidate(), GoodCandidate(), SMS_PeakParams::iRefHarmonic, N_HARM_PEAKS, SMS_AnalFrame::pSpectralPeaks, and sfloat.

Referenced by sms_analyzeFrame().

Here is the call graph for this function:

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Thu Oct 29 04:08:07 2009 for libsms by  doxygen 1.6.1