diff options
author | John Glover <glover.john@gmail.com> | 2010-12-08 18:45:14 +0000 |
---|---|---|
committer | John Glover <glover.john@gmail.com> | 2010-12-08 18:45:14 +0000 |
commit | d7eb9bcda3848ce1b3816d428e8dd66d9b0e02d8 (patch) | |
tree | fa51471e087d8d116bffb4969a4c1b14b0438cfe /sms/sms.c | |
parent | 2a7cc2153f7445453422d74d87d2ce0cf9de51ff (diff) | |
download | simpl-d7eb9bcda3848ce1b3816d428e8dd66d9b0e02d8.tar.gz simpl-d7eb9bcda3848ce1b3816d428e8dd66d9b0e02d8.tar.bz2 simpl-d7eb9bcda3848ce1b3816d428e8dd66d9b0e02d8.zip |
SMSPeakDetection bug fixes
Diffstat (limited to 'sms/sms.c')
-rw-r--r-- | sms/sms.c | 97 |
1 files changed, 39 insertions, 58 deletions
@@ -386,44 +386,6 @@ int sms_initAnalysis(SMS_AnalParams *pAnalParams) return 0; } -void sms_changeHopSize(int hopSize, SMS_AnalParams *pAnalParams) -{ - pAnalParams->sizeHop = hopSize; - pAnalParams->iFrameRate = pAnalParams->iSamplingRate / hopSize; - int sizeBuffer = (pAnalParams->iMaxDelayFrames * pAnalParams->sizeHop) + SMS_MAX_WINDOW; - - /* if storing residual phases, restrict number of stochastic coefficients to the size of the spectrum (sizeHop = 1/2 sizeFft)*/ - if(pAnalParams->iStochasticType == SMS_STOC_IFFT) - pAnalParams->nStochasticCoeff = sms_power2(pAnalParams->sizeHop); - - /* sound buffer */ - SMS_SndBuffer *pSoundBuf = &pAnalParams->soundBuffer; - - free(pSoundBuf->pFBuffer); - pSoundBuf->pFBuffer = calloc(sizeBuffer, sizeof(sfloat)); - if(pSoundBuf->pFBuffer == NULL) - { - sms_error("could not allocate memory"); - return; - } - pSoundBuf->iMarker = -sizeBuffer; - pSoundBuf->iFirstGood = sizeBuffer; - pSoundBuf->sizeBuffer = sizeBuffer; - - /* deterministic synthesis buffer */ - SMS_SndBuffer *pSynthBuf = &pAnalParams->synthBuffer; - pSynthBuf->sizeBuffer = pAnalParams->sizeHop << 1; - - free(pSynthBuf->pFBuffer); - pSynthBuf->pFBuffer = calloc(sizeBuffer, sizeof(sfloat)); - if(pSynthBuf->pFBuffer == NULL) - { - sms_error("could not allocate memory"); - return; - } - pSynthBuf->iMarker = pSynthBuf->sizeBuffer; -} - /*! \brief give default values to an SMS_SynthParams struct * * This will initialize an SMS_SynthParams with values that work @@ -511,26 +473,6 @@ int sms_initSynth(SMS_SynthParams *pSynthParams) return SMS_OK; } -int sms_changeSynthHop(SMS_SynthParams *pSynthParams, int sizeHop) -{ - int sizeFft = sizeHop * 2; - - pSynthParams->pSynthBuff = (sfloat *) realloc(pSynthParams->pSynthBuff, sizeFft * sizeof(sfloat)); - pSynthParams->pSpectra = (sfloat *) realloc(pSynthParams->pSpectra, sizeFft * sizeof(sfloat)); - pSynthParams->pMagBuff = (sfloat *) realloc(pSynthParams->pMagBuff, sizeHop * sizeof(sfloat)); - pSynthParams->pPhaseBuff = (sfloat *) realloc(pSynthParams->pPhaseBuff, sizeHop * sizeof(sfloat)); - pSynthParams->pFStocWindow = - (sfloat *) realloc(pSynthParams->pFStocWindow, sizeFft * sizeof(sfloat)); - sms_getWindow( sizeFft, pSynthParams->pFStocWindow, SMS_WIN_HANNING ); - pSynthParams->pFDetWindow = - (sfloat *) realloc(pSynthParams->pFDetWindow, sizeFft * sizeof(sfloat)); - sms_getWindow(sizeFft, pSynthParams->pFDetWindow, SMS_WIN_IFFT); - - pSynthParams->sizeHop = sizeHop; - - return(SMS_OK); -} - /*! \brief free analysis data * * frees all the memory allocated to an SMS_AnalParams by @@ -607,6 +549,45 @@ void sms_freeSynth(SMS_SynthParams *pSynthParams) sms_freeFrame(&pSynthParams->prevFrame); } +/*! \brief Allocate memory for an array of spectral peaks + * + * Creates memory and sets default values. + * + * \param peaks the spectral peaks + * \param n number of peaks + * \return 0 on success, -1 on error + */ +int sms_initSpectralPeaks(SMS_SpectralPeaks* peaks, int n) +{ + peaks->nPeaks = n; + peaks->nPeaksFound = 0; + + peaks->pSpectralPeaks = (SMS_Peak *)malloc(n * sizeof(SMS_Peak)); + if(peaks->pSpectralPeaks == NULL) + { + sms_error("could not allocate memory for spectral peaks"); + return -1; + } + return 0; +} + +/*! \brief Deallocate memory for an array of spectral peaks + * + * \param peaks the spectral peaks + */ +void sms_freeSpectralPeaks(SMS_SpectralPeaks* peaks) +{ + if(!peaks) + return; + if(peaks->nPeaks <= 0) + return; + + if(peaks->pSpectralPeaks) + free(peaks->pSpectralPeaks); + peaks->nPeaks = 0; + peaks->nPeaksFound = 0; +} + /*! \brief set window size for next frame * * adjusts the next window size to fit the currently detected fundamental |