diff options
author | John Glover <glover.john@gmail.com> | 2010-11-24 23:26:43 +0000 |
---|---|---|
committer | John Glover <glover.john@gmail.com> | 2010-11-24 23:26:43 +0000 |
commit | 5e25edb1b78f28bee09bd7513a80fb500bbd59c4 (patch) | |
tree | 9290c3757abdecf2525c68cd5e5082fa9604ca61 /sms/peakDetection.c | |
parent | 580dd2e019e9666dc5f4771dedeb0720aa8d1d07 (diff) | |
download | simpl-5e25edb1b78f28bee09bd7513a80fb500bbd59c4.tar.gz simpl-5e25edb1b78f28bee09bd7513a80fb500bbd59c4.tar.bz2 simpl-5e25edb1b78f28bee09bd7513a80fb500bbd59c4.zip |
Updated libsms to the latest version (1.15), includes some memory management improvements/simplifications but the basic API is the same. Also started updating the unit tests, which will now use the nose framework
Diffstat (limited to 'sms/peakDetection.c')
-rw-r--r-- | sms/peakDetection.c | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/sms/peakDetection.c b/sms/peakDetection.c index 1bbe713..fc40e69 100644 --- a/sms/peakDetection.c +++ b/sms/peakDetection.c @@ -165,31 +165,20 @@ static sfloat GetPhaseVal (sfloat *pPhaseSpectrum, sfloat fPeakLoc) int sms_detectPeaks(int sizeSpec, sfloat *pMag, sfloat *pPhase, SMS_Peak *pSpectralPeaks, SMS_AnalParams *pAnalParams) { - static int iFirstBin, iHighestBin, sizeFft; - static sfloat fInvSizeFft; - static int sizeSpecStatic = 0; - - /* allocate memory if sizeSpec has changed or this is the first run */ - if(sizeSpecStatic != sizeSpec) - { - sizeSpecStatic = sizeSpec; - sizeFft = sizeSpec << 1; - fInvSizeFft = 1.0 / sizeFft; - /* make sure to start on the 2nd bin so interpolation is possible QUESTION: why not allow a peak in bin 1 or 0? */ - /* rte: changed the first argument of MAX from 2 to 1 */ - iFirstBin = MAX(1, sizeFft * pAnalParams->fLowestFreq / pAnalParams->iSamplingRate); - iHighestBin = MIN(sizeSpec-1, sizeFft * pAnalParams->fHighestFreq / pAnalParams->iSamplingRate); - } + int sizeFft = sizeSpec << 1; + sfloat fInvSizeFft = 1.0 / sizeFft; + int iFirstBin = MAX(1, sizeFft * pAnalParams->fLowestFreq / pAnalParams->iSamplingRate); + int iHighestBin = MIN(sizeSpec-1, sizeFft * pAnalParams->fHighestFreq / pAnalParams->iSamplingRate); /* clear peak structure */ memset(pSpectralPeaks, 0, pAnalParams->maxPeaks * sizeof(SMS_Peak)); /* set starting search values */ int iCurrentLoc = iFirstBin; - int iPeak = 0; /* index for spectral search */ - sfloat fPeakMag = 0.0; /* magnitude of peak */ - sfloat fPeakLoc = 0.0; /* location of peak */ - + int iPeak = 0; /* index for spectral search */ + sfloat fPeakMag = 0.0; /* magnitude of peak */ + sfloat fPeakLoc = 0.0; /* location of peak */ + /* find peaks */ while((iPeak < pAnalParams->maxPeaks) && (FindNextPeak(pMag, iHighestBin, &iCurrentLoc, &fPeakMag, |