diff options
author | John Glover <glover.john@gmail.com> | 2010-11-04 14:50:08 +0000 |
---|---|---|
committer | John Glover <glover.john@gmail.com> | 2010-11-04 14:50:08 +0000 |
commit | c741f6ce7bb43b115d08e190b93e0ce090ae3475 (patch) | |
tree | 9ad817d457a0b5595a4de802b069f149745295ac /sms/analysis.c | |
parent | 82ae0ec4aa684dbe6285b265bc6a07c6f555d90d (diff) | |
download | simpl-c741f6ce7bb43b115d08e190b93e0ce090ae3475.tar.gz simpl-c741f6ce7bb43b115d08e190b93e0ce090ae3475.tar.bz2 simpl-c741f6ce7bb43b115d08e190b93e0ce090ae3475.zip |
Fixed a couple of SMSPeakDetection bugs and updated the unit tests
Diffstat (limited to 'sms/analysis.c')
-rw-r--r-- | sms/analysis.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/sms/analysis.c b/sms/analysis.c index 678eb13..84eb28c 100644 --- a/sms/analysis.c +++ b/sms/analysis.c @@ -31,21 +31,20 @@ /*! \brief maximum size for magnitude spectrum */ #define SMS_MAX_SPEC 8192 -void printPeakParams(SMS_PeakParams* params) +void printAnalysisParams(SMS_AnalParams* params) { printf("fLowestFreq: %f\n" "fHighestFreq: %f\n" "fMinPeakMag: %f\n" "iSamplingRate: %d\n" "iMaxPeaks: %d\n" - "nPeaksFound: %d\n" "fHighestFundamental: %f\n" "iRefHarmonic: %d\n" "fMinRefHarmMag: %f\n" "fRefHarmMagDiffFromMax: %f\n" "iSoundType: %d\n", params->fLowestFreq, params->fHighestFreq, params->fMinPeakMag, params->iSamplingRate, - params->iMaxPeaks, params->nPeaksFound, params->fHighestFundamental, params->iRefHarmonic, + params->maxPeaks, params->fHighestFundamental, params->iRefHarmonic, params->fMinRefHarmMag, params->fRefHarmMagDiffFromMax, params->iSoundType); } @@ -91,7 +90,7 @@ void sms_analyzeFrame(int iCurrentFrame, SMS_AnalParams *pAnalParams, sfloat fRe pFMagSpectrum, pFPhaSpectrum, pCurrentFrame->pSpectralPeaks, - &pAnalParams->peakParams); + pAnalParams); /* find a reference harmonic */ if (pCurrentFrame->nPeaks > 0 && @@ -115,10 +114,10 @@ void sms_analyzeFrame(int iCurrentFrame, SMS_AnalParams *pAnalParams, sfloat fRe */ static int ReAnalyzeFrame(int iCurrentFrame, SMS_AnalParams *pAnalParams) { - sfloat fFund, fLastFund, fDev; + sfloat fFund, fLastFund, fDev; int iNewFrameSize, i; sfloat fAvgDeviation = sms_fundDeviation(pAnalParams, iCurrentFrame); - int iFirstFrame = iCurrentFrame - pAnalParams->minGoodFrames; + int iFirstFrame = iCurrentFrame - pAnalParams->minGoodFrames; /*! \todo mae this a < 0 check, but first make sure sms_fundDeviation does not return values below zero */ @@ -218,16 +217,17 @@ int sms_findPeaks(int sizeWaveform, sfloat *pWaveform, SMS_AnalParams *pAnalPara pAnalParams->sizeNextRead = MAX(0, (pAnalParams->windowSize+1)/2 - iExtraSamples); ReAnalyzeFrame(iCurrentFrame, pAnalParams); - /* return peaks */ + /* save peaks */ pSpectralPeaks->nPeaksFound = pAnalParams->ppFrames[iCurrentFrame]->nPeaks; - pSpectralPeaks->nPeaks = pAnalParams->peakParams.iMaxPeaks; + pSpectralPeaks->nPeaks = pAnalParams->maxPeaks; pSpectralPeaks->pSpectralPeaks = pAnalParams->ppFrames[iCurrentFrame]->pSpectralPeaks; + /* convert peak amps to linear */ for(i = 0; i < pSpectralPeaks->nPeaksFound; i++) { - pSpectralPeaks->pSpectralPeaks[i].fMag = sms_dBToMag(pSpectralPeaks->pSpectralPeaks[i].fMag); + pSpectralPeaks->pSpectralPeaks[i].fMag = pow(10.0, 0.05*(pSpectralPeaks->pSpectralPeaks[i].fMag)); } - return pSpectralPeaks->nPeaksFound; + return pSpectralPeaks->nPeaks; } else { |