diff options
author | John Glover <glover.john@gmail.com> | 2011-06-24 18:17:23 +0100 |
---|---|---|
committer | John Glover <glover.john@gmail.com> | 2011-06-24 18:17:23 +0100 |
commit | 416bd737074a287ea47106c73ea6bcfde40a75a8 (patch) | |
tree | 74562303d4f4f2f2e010f7e13cba41dc4852b50c /src/sms/residual.c | |
parent | d26519464dcbf8c3682348167c29454961facefe (diff) | |
download | simpl-416bd737074a287ea47106c73ea6bcfde40a75a8.tar.gz simpl-416bd737074a287ea47106c73ea6bcfde40a75a8.tar.bz2 simpl-416bd737074a287ea47106c73ea6bcfde40a75a8.zip |
Change to using distutils.
Currently only builds the simplsndobj module
Diffstat (limited to 'src/sms/residual.c')
-rw-r--r-- | src/sms/residual.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/sms/residual.c b/src/sms/residual.c new file mode 100644 index 0000000..0c720f0 --- /dev/null +++ b/src/sms/residual.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2008 MUSIC TECHNOLOGY GROUP (MTG) + * 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 + * 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 residual.c + * \brief main sms_residual() function + */ + +#include "sms.h" + +/*! \brief get the residual waveform + * + * \param sizeWindow size of buffers + * \param pSynthesis pointer to deterministic component + * \param pOriginal pointer to original waveform + * \param pResidual pointer to output residual waveform + * \param pWindow pointer to windowing array + * \return residual percentage (0 if residual was not large enough) + */ +int sms_residual(int sizeWindow, sfloat *pSynthesis, sfloat *pOriginal, + SMS_ResidualParams* residualParams) +{ + sfloat fScale = 1.; + sfloat fCurrentResidualMag = 0.; + sfloat fCurrentOriginalMag = 0.; + int i; + + /* get residual */ + for(i = 0; i < sizeWindow; i++) + residualParams->residual[i] = pOriginal[i] - pSynthesis[i]; + + /* get energy of residual */ + for(i = 0; i < sizeWindow; i++) + fCurrentResidualMag += (residualParams->residual[i] * residualParams->residual[i]); + + /* if residual is big enough compute coefficients */ + if(fCurrentResidualMag) + { + /* get energy of original */ + for(i = 0; i < sizeWindow; i++) + fCurrentOriginalMag += (pOriginal[i] * pOriginal[i]); + + residualParams->originalMag = + .5 * (fCurrentOriginalMag/sizeWindow + residualParams->originalMag); + residualParams->residualMag = + .5 * (fCurrentResidualMag/sizeWindow + residualParams->residualMag); + + /* scale residual if need to be */ + if(residualParams->residualMag > residualParams->originalMag) + { + fScale = residualParams->originalMag / residualParams->residualMag; + for(i = 0; i < sizeWindow; i++) + residualParams->residual[i] *= fScale; + } + + return fCurrentResidualMag / fCurrentOriginalMag; + } + return 0; +} + |