diff options
author | John Glover <j@johnglover.net> | 2012-09-13 17:32:35 +0200 |
---|---|---|
committer | John Glover <j@johnglover.net> | 2012-09-13 17:32:35 +0200 |
commit | abfe14097571c0cbcd683e1d121eb80f8999c4c2 (patch) | |
tree | 9052a132c3f92de05e2d4c93163f7c073f5f130c /src | |
parent | db34982fdd84bf9b336f00207a1060f68b7d3ee3 (diff) | |
download | simpl-abfe14097571c0cbcd683e1d121eb80f8999c4c2.tar.gz simpl-abfe14097571c0cbcd683e1d121eb80f8999c4c2.tar.bz2 simpl-abfe14097571c0cbcd683e1d121eb80f8999c4c2.zip |
[sms] Allow SMSResidual objects to use different
frame and hop sizes.
Fix bug in SMSPeakDetection when operating in
real-time mode (audio was not being copied to the
analysis buffer correctly).
Diffstat (limited to 'src')
-rw-r--r-- | src/simpl/peak_detection.cpp | 8 | ||||
-rw-r--r-- | src/simpl/peak_detection.h | 1 | ||||
-rw-r--r-- | src/simpl/residual.cpp | 37 | ||||
-rw-r--r-- | src/simpl/residual.h | 4 | ||||
-rw-r--r-- | src/sms/analysis.c | 102 | ||||
-rw-r--r-- | src/sms/sms.c | 135 |
6 files changed, 159 insertions, 128 deletions
diff --git a/src/simpl/peak_detection.cpp b/src/simpl/peak_detection.cpp index 0f28da3..a8b68f8 100644 --- a/src/simpl/peak_detection.cpp +++ b/src/simpl/peak_detection.cpp @@ -187,7 +187,7 @@ SMSPeakDetection::SMSPeakDetection() { _analysis_params.preEmphasis = 0; _analysis_params.realtime = 0; sms_initAnalysis(&_analysis_params); - _analysis_params.iSizeSound = _hop_size; + _analysis_params.iSizeSound = _frame_size; sms_initSpectralPeaks(&_peaks, _max_peaks); @@ -209,12 +209,16 @@ int SMSPeakDetection::next_frame_size() { return _analysis_params.sizeNextRead; } +void SMSPeakDetection::frame_size(int new_frame_size) { + _frame_size = new_frame_size; + _analysis_params.iSizeSound = _hop_size; +} + void SMSPeakDetection::hop_size(int new_hop_size) { _hop_size = new_hop_size; sms_freeAnalysis(&_analysis_params); _analysis_params.iFrameRate = _sampling_rate / _hop_size; sms_initAnalysis(&_analysis_params); - _analysis_params.iSizeSound = _hop_size; } void SMSPeakDetection::max_peaks(int new_max_peaks) { diff --git a/src/simpl/peak_detection.h b/src/simpl/peak_detection.h index 398c2bf..9a35b52 100644 --- a/src/simpl/peak_detection.h +++ b/src/simpl/peak_detection.h @@ -94,6 +94,7 @@ class SMSPeakDetection : public PeakDetection { SMSPeakDetection(); ~SMSPeakDetection(); int next_frame_size(); + void frame_size(int new_frame_size); void hop_size(int new_hop_size); void max_peaks(int new_max_peaks); int realtime(); diff --git a/src/simpl/residual.cpp b/src/simpl/residual.cpp index b74c1a6..d59e5f2 100644 --- a/src/simpl/residual.cpp +++ b/src/simpl/residual.cpp @@ -65,12 +65,22 @@ Frames Residual::synth(Frames& frames) { Frames Residual::synth(int original_size, sample* original) { Frames frames; + unsigned int pos = 0; + + while(pos <= original_size - _hop_size) { + Frame* f = new Frame(_frame_size, true); + + if((int)pos <= (original_size - _frame_size)) { + f->audio(&(original[pos]), _frame_size); + } + else { + f->audio(&(original[pos]), original_size - pos); + } - for(int i = 0; i <= original_size - _hop_size; i += _hop_size) { - Frame* f = new Frame(_hop_size, true); - f->audio(&original[i]); synth_frame(f); frames.push_back(f); + + pos += _hop_size; } return frames; @@ -88,8 +98,6 @@ SMSResidual::SMSResidual() { _residual_params.hopSize = _hop_size; sms_initResidual(&_residual_params); - _temp_synth = new sample[_hop_size]; - _pd.hop_size(_hop_size); _pd.realtime(1); _synth.hop_size(_hop_size); @@ -99,11 +107,11 @@ SMSResidual::SMSResidual() { SMSResidual::~SMSResidual() { sms_freeResidual(&_residual_params); sms_free(); +} - if(_temp_synth) { - delete[] _temp_synth; - } - _temp_synth = NULL; +void SMSResidual::frame_size(int new_frame_size) { + _frame_size = new_frame_size; + _pd.frame_size(_frame_size); } void SMSResidual::hop_size(int new_hop_size) { @@ -113,10 +121,7 @@ void SMSResidual::hop_size(int new_hop_size) { _residual_params.hopSize = _hop_size; sms_initResidual(&_residual_params); - if(_temp_synth) { - delete[] _temp_synth; - } - _temp_synth = new sample[_hop_size]; + _pd.hop_size(_hop_size); } int SMSResidual::num_stochastic_coeffs() { @@ -138,11 +143,11 @@ void SMSResidual::residual_frame(Frame* frame) { _pt.update_partials(frame); _synth.synth_frame(frame); - sms_findResidual(frame->size(), frame->synth(), - frame->size(), frame->audio(), + sms_findResidual(_hop_size, frame->synth(), + _hop_size, &(frame->audio()[frame->size() - _hop_size]), &_residual_params); - for(int i = 0; i < frame->size(); i++) { + for(int i = 0; i < frame->synth_size(); i++) { frame->residual()[i] = _residual_params.residual[i]; } } diff --git a/src/simpl/residual.h b/src/simpl/residual.h index 8bdd316..e611fce 100644 --- a/src/simpl/residual.h +++ b/src/simpl/residual.h @@ -31,7 +31,7 @@ class Residual { public: Residual(); int frame_size(); - void frame_size(int new_frame_size); + virtual void frame_size(int new_frame_size); int hop_size(); virtual void hop_size(int new_hop_size); int sampling_rate(); @@ -53,7 +53,6 @@ class Residual { // --------------------------------------------------------------------------- class SMSResidual : public Residual { private: - sample* _temp_synth; SMSResidualParams _residual_params; SMSPeakDetection _pd; @@ -63,6 +62,7 @@ class SMSResidual : public Residual { public: SMSResidual(); ~SMSResidual(); + void frame_size(int new_frame_size); void hop_size(int new_hop_size); int num_stochastic_coeffs(); void num_stochastic_coeffs(int new_num_stochastic_coeffs); diff --git a/src/sms/analysis.c b/src/sms/analysis.c index c7aae0b..b904449 100644 --- a/src/sms/analysis.c +++ b/src/sms/analysis.c @@ -1,35 +1,35 @@ -/* +/* * Copyright (c) 2008 MUSIC TECHNOLOGY GROUP (MTG) - * UNIVERSITAT POMPEU FABRA - * - * + * UNIVERSITAT POMPEU FABRA + * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of + * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * + * */ /*! \file analysis.c * \brief main sms analysis routines - * + * * the analysis routine here calls all necessary functions to perform the complete - * SMS analysis, once the desired analysis parameters are set in SMS_AnalParams. + * SMS analysis, once the desired analysis parameters are set in SMS_AnalParams. */ #include "sms.h" /*! \brief maximum size for magnitude spectrum */ -#define SMS_MAX_SPEC 8192 +#define SMS_MAX_SPEC 8192 /*! \brief compute spectrum, find peaks, and fundamental of one frame * @@ -37,19 +37,34 @@ * * \param iCurrentFrame frame number to be computed * \param pAnalParams structure of analysis parameters - * \param fRefFundamental reference fundamental + * \param fRefFundamental reference fundamental */ void sms_analyzeFrame(int iCurrentFrame, SMS_AnalParams *pAnalParams, sfloat fRefFundamental) { - int i, iFrame; SMS_AnalFrame *pCurrentFrame = pAnalParams->ppFrames[iCurrentFrame]; - int iSoundLoc = pCurrentFrame->iFrameSample -((pCurrentFrame->iFrameSize + 1) >> 1) + 1; - sfloat *pFData = &(pAnalParams->soundBuffer.pFBuffer[iSoundLoc - pAnalParams->soundBuffer.iMarker]); + sfloat *pFData; + int i, iFrame, sizeMag; + int sizeWindow = pCurrentFrame->iFrameSize; + + if(pAnalParams->realtime == 0) + { + int iSoundLoc = pCurrentFrame->iFrameSample - + ((pCurrentFrame->iFrameSize + 1) >> 1) + 1; + pFData = &(pAnalParams->soundBuffer.pFBuffer[ + iSoundLoc - pAnalParams->soundBuffer.iMarker + ]); + } + else + { + pFData = &(pAnalParams->soundBuffer.pFBuffer[ + pAnalParams->soundBuffer.sizeBuffer - sizeWindow + ]); + } /* TODO: this doesn't have to be done every time */ - int sizeWindow = pCurrentFrame->iFrameSize; - int sizeMag = sms_power2(sizeWindow); - sms_getWindow(sizeWindow, pAnalParams->spectrumWindow, pAnalParams->iWindowType); + sizeMag = sms_power2(sizeWindow); + sms_getWindow(sizeWindow, pAnalParams->spectrumWindow, + pAnalParams->iWindowType); sms_scaleWindow(sizeWindow, pAnalParams->spectrumWindow); /* compute the magnitude and (zero-windowed) phase spectra */ @@ -69,12 +84,17 @@ void sms_analyzeFrame(int iCurrentFrame, SMS_AnalParams *pAnalParams, sfloat fRe /* find a reference harmonic */ if(pCurrentFrame->nPeaks > 0 && - (pAnalParams->iFormat == SMS_FORMAT_H || pAnalParams->iFormat == SMS_FORMAT_HP)) - pCurrentFrame->fFundamental = sms_harmDetection(pAnalParams->maxPeaks, pCurrentFrame->pSpectralPeaks, - fRefFundamental, pAnalParams->iRefHarmonic, - pAnalParams->fLowestFundamental, pAnalParams->fHighestFundamental, - pAnalParams->iSoundType, pAnalParams->fMinRefHarmMag, - pAnalParams->fRefHarmMagDiffFromMax); + (pAnalParams->iFormat == SMS_FORMAT_H || + pAnalParams->iFormat == SMS_FORMAT_HP)) + { + pCurrentFrame->fFundamental = sms_harmDetection( + pAnalParams->maxPeaks, pCurrentFrame->pSpectralPeaks, + fRefFundamental, pAnalParams->iRefHarmonic, + pAnalParams->fLowestFundamental, pAnalParams->fHighestFundamental, + pAnalParams->iSoundType, pAnalParams->fMinRefHarmMag, + pAnalParams->fRefHarmMagDiffFromMax + ); + } } /*! \brief re-analyze the previous frames if necessary @@ -139,7 +159,7 @@ int sms_findPeaks(int sizeWaveform, sfloat *pWaveform, SMS_AnalParams *pAnalPara sfloat fRefFundamental = 0; /* reference fundamental for current frame */ int i, iError, iExtraSamples; /* samples used for next analysis frame */ SMS_AnalFrame *pTmpAnalFrame; - + /* set initial analysis-window size */ if(pAnalParams->windowSize == 0) pAnalParams->windowSize = pAnalParams->iDefaultSizeWindow; @@ -159,6 +179,13 @@ int sms_findPeaks(int sizeWaveform, sfloat *pWaveform, SMS_AnalParams *pAnalPara if(pAnalParams->ppFrames[iCurrentFrame]->iStatus == SMS_FRAME_READY) { + if(pAnalParams->realtime == 1) + { + pAnalParams->ppFrames[iCurrentFrame]->iFrameSize = sizeWaveform; + pAnalParams->windowSize = sizeWaveform; + pAnalParams->sizeNextRead = sizeWaveform; + } + sfloat fAvgDev = sms_fundDeviation(pAnalParams, iCurrentFrame - 1); /* if single note use the default fundamental as reference */ @@ -173,18 +200,12 @@ int sms_findPeaks(int sizeWaveform, sfloat *pWaveform, SMS_AnalParams *pAnalPara /* compute spectrum, find peaks, and find fundamental of frame */ sms_analyzeFrame(iCurrentFrame, pAnalParams, fRefFundamental); - /* set the size of the next analysis window */ - /* if(pAnalParams->ppFrames[iCurrentFrame]->fFundamental > 0 && */ - /* pAnalParams->iSoundType != SMS_SOUND_TYPE_NOTE) */ - /* { */ - /* pAnalParams->windowSize = sms_sizeNextWindow(iCurrentFrame, pAnalParams); */ - /* } */ - + /* set the size of the next analysis window if not in real-time mode */ if(pAnalParams->realtime == 0) { /* set the size of the next analysis window */ if(pAnalParams->ppFrames[iCurrentFrame]->fFundamental > 0 && - pAnalParams->iSoundType != SMS_SOUND_TYPE_NOTE) + pAnalParams->iSoundType != SMS_SOUND_TYPE_NOTE) { pAnalParams->windowSize = sms_sizeNextWindow(iCurrentFrame, pAnalParams); } @@ -199,11 +220,6 @@ int sms_findPeaks(int sizeWaveform, sfloat *pWaveform, SMS_AnalParams *pAnalPara pAnalParams->sizeNextRead = MAX(0, (pAnalParams->windowSize+1)/2 - iExtraSamples); ReAnalyzeFrame(iCurrentFrame, pAnalParams); } - else - { - pAnalParams->windowSize = sizeWaveform; - pAnalParams->sizeNextRead = sizeWaveform; - } /* save peaks */ pSpectralPeaks->nPeaksFound = pAnalParams->ppFrames[iCurrentFrame]->nPeaks; @@ -213,11 +229,11 @@ int sms_findPeaks(int sizeWaveform, sfloat *pWaveform, SMS_AnalParams *pAnalPara { if(i < pSpectralPeaks->nPeaksFound) { - pSpectralPeaks->pSpectralPeaks[i].fMag = + pSpectralPeaks->pSpectralPeaks[i].fMag = sms_dBToMag(pAnalParams->ppFrames[iCurrentFrame]->pSpectralPeaks[i].fMag); - pSpectralPeaks->pSpectralPeaks[i].fFreq = + pSpectralPeaks->pSpectralPeaks[i].fFreq = pAnalParams->ppFrames[iCurrentFrame]->pSpectralPeaks[i].fFreq; - pSpectralPeaks->pSpectralPeaks[i].fPhase = + pSpectralPeaks->pSpectralPeaks[i].fPhase = pAnalParams->ppFrames[iCurrentFrame]->pSpectralPeaks[i].fPhase; } else @@ -503,13 +519,13 @@ int sms_analyze(int sizeWaveform, sfloat *pWaveform, SMS_Data *pSmsData, SMS_Ana sms_filterHighPass(sizeData, pAnalParams->residualParams.residual, pAnalParams->iSamplingRate); /* approximate residual */ - sms_stocAnalysis(sizeData, pAnalParams->residualParams.residual, pAnalParams->residualParams.fftWindow, + sms_stocAnalysis(sizeData, pAnalParams->residualParams.residual, pAnalParams->residualParams.fftWindow, pSmsData, pAnalParams); } else if(pAnalParams->iStochasticType == SMS_STOC_IFFT) { int sizeMag = sms_power2(sizeData >> 1); - sms_spectrum(sizeData, pAnalParams->residualParams.residual, pAnalParams->residualParams.fftWindow, + sms_spectrum(sizeData, pAnalParams->residualParams.residual, pAnalParams->residualParams.fftWindow, sizeMag, pSmsData->pFStocCoeff, pSmsData->pResPhase, pAnalParams->fftBuffer); } diff --git a/src/sms/sms.c b/src/sms/sms.c index 59e9fa9..ac14694 100644 --- a/src/sms/sms.c +++ b/src/sms/sms.c @@ -1,22 +1,22 @@ -/* +/* * Copyright (c) 2008 MUSIC TECHNOLOGY GROUP (MTG) - * UNIVERSITAT POMPEU FABRA - * - * + * UNIVERSITAT POMPEU FABRA + * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of + * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * + * */ /*! \file sms.c * \brief initialization, free, and debug functions @@ -32,7 +32,7 @@ static char error_message[256]; static int error_status = 0; static sfloat mag_thresh = .00001; /*!< magnitude threshold for db conversion (-100db)*/ static sfloat inv_mag_thresh = 100000.; /*!< inv(.00001) */ -static int initIsDone = 0; /* \todo is this variable necessary? */ +static int initIsDone = 0; /* \todo is this variable necessary? */ #define SIZE_TABLES 4096 #define HALF_MAX 1073741823.5 /*!< half the max of a 32-bit word */ @@ -49,7 +49,7 @@ static int initIsDone = 0; /* \todo is this variable necessary? */ * * \return error code \see SMS_MALLOC or SMS_OK in SMS_ERRORS */ -int sms_init(void) +int sms_init(void) { if (!initIsDone) { @@ -84,17 +84,17 @@ void sms_free() sms_clearSinc(); } -/*! \brief give default values to an SMS_AnalParams struct - * +/*! \brief give default values to an SMS_AnalParams struct + * * This will initialize an SMS_AnalParams with values that work * for common analyses. It is useful to start with and then * adjust the parameters manually to fit a particular sound * - * Certain things are hard coded in here that will have to + * Certain things are hard coded in here that will have to * be updated later (i.e. samplerate), so it is best to call this - * function first, then fill whatever parameters need to be + * function first, then fill whatever parameters need to be * adjusted. - * + * * \param pAnalParams pointer to analysis data structure */ void sms_initAnalParams(SMS_AnalParams *pAnalParams) @@ -177,7 +177,7 @@ void sms_initAnalParams(SMS_AnalParams *pAnalParams) } /*! \brief initialize analysis data structure's arrays - * + * * based on the SMS_AnalParams current settings, this function will * initialize the sound, synth, and fft arrays. It is necessary before analysis. * there can be multple SMS_AnalParams at the same time @@ -197,7 +197,7 @@ int sms_initAnalysis(SMS_AnalParams *pAnalParams) (sfloat) pAnalParams->iFrameRate); /* set the default size window to an odd length */ - pAnalParams->iDefaultSizeWindow = + pAnalParams->iDefaultSizeWindow = (int)((pAnalParams->iSamplingRate / pAnalParams->fDefaultFundamental) * pAnalParams->fSizeWindow / 2) * 2 + 1; @@ -277,7 +277,7 @@ int sms_initAnalysis(SMS_AnalParams *pAnalParams) pAnalParams->pFrames[i].iFrameSample = 0; pAnalParams->pFrames[i].iFrameSize = 0; pAnalParams->pFrames[i].iFrameNum = 0; - pAnalParams->pFrames[i].pSpectralPeaks = + pAnalParams->pFrames[i].pSpectralPeaks = (SMS_Peak *)malloc(pAnalParams->maxPeaks * sizeof(SMS_Peak)); if((pAnalParams->pFrames[i]).pSpectralPeaks == NULL) { @@ -286,7 +286,7 @@ int sms_initAnalysis(SMS_AnalParams *pAnalParams) } (pAnalParams->pFrames[i].deterministic).nTracks = pAnalParams->nGuides; - (pAnalParams->pFrames[i].deterministic).pFSinFreq = + (pAnalParams->pFrames[i].deterministic).pFSinFreq = (sfloat *)calloc(pAnalParams->nGuides, sizeof(sfloat)); if((pAnalParams->pFrames[i].deterministic).pFSinFreq == NULL) { @@ -373,8 +373,8 @@ int sms_initAnalysis(SMS_AnalParams *pAnalParams) return 0; } -/*! \brief give default values to an SMS_SynthParams struct - * +/*! \brief give default values to an SMS_SynthParams struct + * * This will initialize an SMS_SynthParams with values that work * for common analyses. It is useful to start with and then * adjust the parameters manually to fit a particular sound @@ -404,7 +404,7 @@ void sms_initSynthParams(SMS_SynthParams *synthParams) } /*! \brief initialize synthesis data structure's arrays - * + * * Initialize the synthesis and fft arrays. It is necessary before synthesis. * there can be multple SMS_SynthParams at the same time * This function also sets some initial values that will create a sane synthesis @@ -438,7 +438,7 @@ int sms_initSynth(SMS_SynthParams *pSynthParams) pSynthParams->pFDetWindow = (sfloat *)calloc(sizeFft, sizeof(sfloat)); sms_getWindow(sizeFft, pSynthParams->pFDetWindow, SMS_WIN_IFFT); - /* allocate memory for analysis data - size of original hopsize + /* allocate memory for analysis data - size of original hopsize * previous frame to interpolate from */ /* \todo why is stoch coeff + 1? */ sms_allocFrame(&pSynthParams->prevFrame, pSynthParams->nTracks, @@ -461,8 +461,8 @@ int sms_initSynth(SMS_SynthParams *pSynthParams) return SMS_OK; } -/*! \brief give default values to an SMS_ResidualParams struct - * +/*! \brief give default values to an SMS_ResidualParams struct + * * \param residualParams pointer to residual data structure */ void sms_initResidualParams(SMS_ResidualParams *residualParams) @@ -492,7 +492,7 @@ void sms_initResidualParams(SMS_ResidualParams *residualParams) } /*! \brief initialize residual data structure - * + * * \param residualParams pointer to synthesis paramaters * \return 0 on success, -1 on error */ @@ -581,7 +581,7 @@ int sms_initResidual(SMS_ResidualParams *residualParams) } /*! \brief free residual data - * + * * frees all the memory allocated to an SMS_ResidualParams by * sms_initResidual * @@ -617,7 +617,7 @@ void sms_freeResidual(SMS_ResidualParams *residualParams) } /*! \brief free analysis data - * + * * frees all the memory allocated to an SMS_AnalParams by * sms_initAnalysis * @@ -671,7 +671,7 @@ void sms_freeAnalysis(SMS_AnalParams *pAnalParams) } /*! \brief free analysis data - * + * * frees all the memory allocated to an SMS_SynthParams by * sms_initSynthesis * @@ -682,7 +682,7 @@ void sms_freeAnalysis(SMS_AnalParams *pAnalParams) void sms_freeSynth(SMS_SynthParams *pSynthParams) { if(pSynthParams->pFStocWindow) - free(pSynthParams->pFStocWindow); + free(pSynthParams->pFStocWindow); if(pSynthParams->pFDetWindow) free(pSynthParams->pFDetWindow); if(pSynthParams->pSynthBuff) @@ -736,9 +736,9 @@ void sms_freeSpectralPeaks(SMS_SpectralPeaks* peaks) peaks->nPeaksFound = 0; } -/*! \brief set window size for next frame +/*! \brief set window size for next frame * - * adjusts the next window size to fit the currently detected fundamental + * adjusts the next window size to fit the currently detected fundamental * frequency, or resets to a default window size if unstable. * * \param iCurrentFrame number of current frame @@ -761,7 +761,7 @@ int sms_sizeNextWindow(int iCurrentFrame, SMS_AnalParams *pAnalParams) if(sizeWindow > SMS_MAX_WINDOW) { - fprintf(stderr, "sms_sizeNextWindow error: sizeWindow (%d) too big, set to %d\n", sizeWindow, + fprintf(stderr, "sms_sizeNextWindow error: sizeWindow (%d) too big, set to %d\n", sizeWindow, SMS_MAX_WINDOW); sizeWindow = SMS_MAX_WINDOW; } @@ -813,17 +813,17 @@ int sms_clearAnalysisFrame(int iCurrentFrame, SMS_AnalParams *pAnalParams) * * \param iCurrentFrame frame number of current frame in buffer * \param pAnalParams analysis parameters - * \param sizeWindow size of analysis window + * \param sizeWindow size of analysis window * \return -1 on error \todo make this return void */ int sms_initFrame(int iCurrentFrame, SMS_AnalParams *pAnalParams, int sizeWindow) { /* clear deterministic data */ - memset((sfloat *)pAnalParams->ppFrames[iCurrentFrame]->deterministic.pFSinFreq, 0, + memset((sfloat *)pAnalParams->ppFrames[iCurrentFrame]->deterministic.pFSinFreq, 0, sizeof(sfloat) * pAnalParams->nGuides); - memset((sfloat *)pAnalParams->ppFrames[iCurrentFrame]->deterministic.pFSinAmp, 0, + memset((sfloat *)pAnalParams->ppFrames[iCurrentFrame]->deterministic.pFSinAmp, 0, sizeof(sfloat) * pAnalParams->nGuides); - memset((sfloat *)pAnalParams->ppFrames[iCurrentFrame]->deterministic.pFSinPha, 0, + memset((sfloat *)pAnalParams->ppFrames[iCurrentFrame]->deterministic.pFSinPha, 0, sizeof(sfloat) * pAnalParams->nGuides); /* clear peaks */ @@ -838,19 +838,22 @@ int sms_initFrame(int iCurrentFrame, SMS_AnalParams *pAnalParams, int sizeWindow pAnalParams->ppFrames[iCurrentFrame]->nPeaks = 0; pAnalParams->ppFrames[iCurrentFrame]->fFundamental = 0; - pAnalParams->ppFrames[iCurrentFrame]->iFrameNum = - pAnalParams->ppFrames[iCurrentFrame - 1]->iFrameNum + 1; - - /* if first frame set center of data around 0 */ - if(pAnalParams->ppFrames[iCurrentFrame]->iFrameNum == 1) - pAnalParams->ppFrames[iCurrentFrame]->iFrameSample = 0; - /* if not, increment center of data by sizeHop */ - else - pAnalParams->ppFrames[iCurrentFrame]->iFrameSample = - pAnalParams->ppFrames[iCurrentFrame-1]->iFrameSample + pAnalParams->sizeHop; - if(pAnalParams->realtime == 0) { + pAnalParams->ppFrames[iCurrentFrame]->iFrameNum = + pAnalParams->ppFrames[iCurrentFrame - 1]->iFrameNum + 1; + + /* if first frame set center of data around 0 */ + if(pAnalParams->ppFrames[iCurrentFrame]->iFrameNum == 1) + { + pAnalParams->ppFrames[iCurrentFrame]->iFrameSample = 0; + } + else /* if not, increment center of data by sizeHop */ + { + pAnalParams->ppFrames[iCurrentFrame]->iFrameSample = + pAnalParams->ppFrames[iCurrentFrame-1]->iFrameSample + pAnalParams->sizeHop; + } + pAnalParams->ppFrames[iCurrentFrame]->iFrameSize = sizeWindow; /* check for end of sound */ @@ -869,6 +872,8 @@ int sms_initFrame(int iCurrentFrame, SMS_AnalParams *pAnalParams, int sizeWindow } else { + pAnalParams->ppFrames[iCurrentFrame]->iFrameNum = 1; + pAnalParams->ppFrames[iCurrentFrame]->iFrameSample = 0; pAnalParams->ppFrames[iCurrentFrame]->iFrameSize = pAnalParams->iSamplingRate / pAnalParams->iFrameRate; pAnalParams->ppFrames[iCurrentFrame]->iStatus = SMS_FRAME_READY; } @@ -879,7 +884,7 @@ int sms_initFrame(int iCurrentFrame, SMS_AnalParams *pAnalParams, int sizeWindow /*! \brief get deviation from average fundamental *\ * \param pAnalParams pointer to analysis params - * \param iCurrentFrame number of current frame + * \param iCurrentFrame number of current frame * \return deviation value or -1 if really off */ sfloat sms_fundDeviation(SMS_AnalParams *pAnalParams, int iCurrentFrame) @@ -912,14 +917,14 @@ sfloat sms_fundDeviation(SMS_AnalParams *pAnalParams, int iCurrentFrame) } -/*! \brief function to create the debug file +/*! \brief function to create the debug file * * \param pAnalParams pointer to analysis params - * \return error value \see SMS_ERRORS + * \return error value \see SMS_ERRORS */ int sms_createDebugFile(SMS_AnalParams *pAnalParams) { - if((pDebug = fopen(pChDebugFile, "w+")) == NULL) + if((pDebug = fopen(pChDebugFile, "w+")) == NULL) { fprintf(stderr, "Cannot open debugfile: %s\n", pChDebugFile); return SMS_WRERR; @@ -930,15 +935,15 @@ int sms_createDebugFile(SMS_AnalParams *pAnalParams) /*! \brief function to write to the debug file * * writes three arrays of equal size to a debug text - * file ("./debug.txt"). There are three arrays for the - * frequency, magnitude, phase sets. - * + * file ("./debug.txt"). There are three arrays for the + * frequency, magnitude, phase sets. + * * \param pFBuffer1 pointer to array 1 * \param pFBuffer2 pointer to array 2 * \param pFBuffer3 pointer to array 3 * \param sizeBuffer the size of the buffers */ -void sms_writeDebugData(sfloat *pFBuffer1, sfloat *pFBuffer2, +void sms_writeDebugData(sfloat *pFBuffer1, sfloat *pFBuffer2, sfloat *pFBuffer3, int sizeBuffer) { int i; @@ -987,7 +992,7 @@ sfloat sms_dBToMag(sfloat x) /*return pow(10.0, x*0.05);*/ } -/*! \brief convert an array from magnitude to decibel +/*! \brief convert an array from magnitude to decibel * * Depends on a linear threshold that indicates the bottom end * of the dB scale (magnutdes at this value will convert to zero). @@ -1027,18 +1032,18 @@ void sms_arrayDBToMag(int sizeArray, sfloat *pArray) void sms_setMagThresh(sfloat x) { /* limit threshold to -100db */ - if(x < 0.00001) + if(x < 0.00001) mag_thresh = 0.00001; else mag_thresh = x; inv_mag_thresh = 1. / mag_thresh; } -/*! \brief get a string containing information about the error code +/*! \brief get a string containing information about the error code * * \param pErrorMessage pointer to error message string */ -void sms_error(char *pErrorMessage) +void sms_error(char *pErrorMessage) { strncpy(error_message, pErrorMessage, 256); error_status = -1; @@ -1048,16 +1053,16 @@ void sms_error(char *pErrorMessage) * * \return -1 if there is an error, 0 if ok */ -int sms_errorCheck() +int sms_errorCheck() { return error_status; } -/*! \brief get a string containing information about the last error +/*! \brief get a string containing information about the last error * * \return pointer to a char string, or NULL if no error */ -char* sms_errorString() +char* sms_errorString() { if (error_status) { @@ -1074,7 +1079,7 @@ char* sms_errorString() sfloat sms_random() { #ifdef MERSENNE_TWISTER - return genrand_real1(); + return genrand_real1(); #else return (sfloat)(random() * 2 * INV_HALF_MAX); #endif @@ -1110,7 +1115,7 @@ int sms_power2(int n) if(1<<p == N) /* n was a power of 2 */ { - return N; + return N; } else /* make the new value larger than n */ { |