summaryrefslogtreecommitdiff
path: root/sms/residual.c
diff options
context:
space:
mode:
authorJohn Glover <glover.john@gmail.com>2010-11-24 23:26:43 +0000
committerJohn Glover <glover.john@gmail.com>2010-11-24 23:26:43 +0000
commit5e25edb1b78f28bee09bd7513a80fb500bbd59c4 (patch)
tree9290c3757abdecf2525c68cd5e5082fa9604ca61 /sms/residual.c
parent580dd2e019e9666dc5f4771dedeb0720aa8d1d07 (diff)
downloadsimpl-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/residual.c')
-rw-r--r--sms/residual.c126
1 files changed, 31 insertions, 95 deletions
diff --git a/sms/residual.c b/sms/residual.c
index a9237dc..b69a28f 100644
--- a/sms/residual.c
+++ b/sms/residual.c
@@ -32,109 +32,45 @@
* \param pResidual pointer to output residual waveform
* \param pWindow pointer to windowing array
* \return residual percentage (0 if residual was not large enough)
- \todo why is residual energy percentage computed this way? should be optional and in a seperate function
+ \todo why is residual energy percentage computed this way? should be optional and in a seperate function
*/
-int sms_residual (int sizeWindow, sfloat *pSynthesis, sfloat *pOriginal, sfloat *pResidual)
+int sms_residual(int sizeWindow, sfloat *pSynthesis, sfloat *pOriginal, sfloat *pResidual, sfloat *pWindow)
{
- static sfloat fResidualMag = 0.;
+ static sfloat fResidualMag = 0.;
static sfloat fOriginalMag = 0.;
- sfloat fScale = 1.;
- sfloat fCurrentResidualMag = 0.;
- sfloat fCurrentOriginalMag = 0.;
- int i;
-
- /* get residual */
- for (i=0; i<sizeWindow; i++)
- {
- pResidual[i] = pOriginal[i] - pSynthesis[i];
- }
+ sfloat fScale = 1.;
+ sfloat fCurrentResidualMag = 0.;
+ sfloat fCurrentOriginalMag = 0.;
+ int i;
- /* get energy of residual */
- for (i=0; i<sizeWindow; i++)
- {
- fCurrentResidualMag += (pResidual[i] * pResidual[i]);
- }
+ /* get residual */
+ for (i=0; i<sizeWindow; i++)
+ pResidual[i] = pOriginal[i] - pSynthesis[i];
- /* if residual is big enough compute coefficients */
- if (fCurrentResidualMag) //always compute
- {
- /* get energy of original */
- for (i=0; i<sizeWindow; i++)
- {
- fCurrentOriginalMag += (pOriginal[i] * pOriginal[i]);
- }
- fOriginalMag = .5 * (fCurrentOriginalMag/sizeWindow + fOriginalMag);
- fResidualMag = .5 * (fCurrentResidualMag/sizeWindow + fResidualMag);
+ /* get energy of residual */
+ for (i=0; i<sizeWindow; i++)
+ fCurrentResidualMag += (pResidual[i] * pResidual[i]);
- /* scale residual if need to be */
- if (fResidualMag > fOriginalMag)
- {
- fScale = fOriginalMag / fResidualMag;
- for (i=0; i<sizeWindow; i++)
- {
- pResidual[i] *= fScale;
- }
- }
+ /* if residual is big enough compute coefficients */
+ if (fCurrentResidualMag)
+ {
+ /* get energy of original */
+ for (i=0; i<sizeWindow; i++)
+ fCurrentOriginalMag += (pOriginal[i] * pOriginal[i]);
- return fCurrentResidualMag / fCurrentOriginalMag;
- }
- return 0;
-}
-
-/*! \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
- \todo why is residual energy percentage computed this way? should be optional and in a seperate function
- */
-int sms_residualOLD ( int sizeWindow, sfloat *pSynthesis, sfloat *pOriginal, sfloat *pResidual, sfloat *pWindow)
-{
- static sfloat fResidualMag = 0, fOriginalMag = 0, *pFWindow = NULL;
- sfloat fScale = 1, fCurrentResidualMag = 0, fCurrentOriginalMag = 0;
- int i;
-
- /* get residual */
- for (i=0; i<sizeWindow; i++)
- pResidual[i] = pOriginal[i] - pSynthesis[i];
+ fOriginalMag = .5 * (fCurrentOriginalMag/sizeWindow + fOriginalMag);
+ fResidualMag = .5 * (fCurrentResidualMag/sizeWindow + fResidualMag);
- /* get energy of residual */
- for (i=0; i<sizeWindow; i++)
- fCurrentResidualMag += fabsf( pResidual[i] * pWindow[i]);
+ /* scale residual if need to be */
+ if (fResidualMag > fOriginalMag)
+ {
+ fScale = fOriginalMag / fResidualMag;
+ for (i=0; i<sizeWindow; i++)
+ pResidual[i] *= fScale;
+ }
- /* if residual is big enough compute coefficients */
-// if (fCurrentResidualMag/sizeWindow > .01)
- if (fCurrentResidualMag) //always compute
- {
-/* printf(" fCurrentResidualMag: %f, sizeWindow: %d, ratio: %f\n", */
-/* fCurrentResidualMag, sizeWindow, fCurrentResidualMag/sizeWindow ); */
-
- /* get energy of original */
- for (i=0; i<sizeWindow; i++)
- fCurrentOriginalMag += fabs( pOriginal[i] * pWindow[i]);
-
- fOriginalMag =
- .5 * (fCurrentOriginalMag/sizeWindow + fOriginalMag);
- fResidualMag =
- .5 * (fCurrentResidualMag/sizeWindow + fResidualMag);
-
- /* scale residual if need to be */
- if (fResidualMag > fOriginalMag)
- {
- fScale = fOriginalMag / fResidualMag;
- for (i=0; i<sizeWindow; i++)
- pResidual[i] *= fScale;
- }
-
- printf("risidual mag: %f, original mag: %f \n", fCurrentResidualMag , fCurrentOriginalMag);
- return (fCurrentResidualMag / fCurrentOriginalMag);
- }
- else printf("whaaaat not big enough: fCurrentResidualMag: %f, sizeWindow: %d, ratio: %f\n",
- fCurrentResidualMag, sizeWindow, fCurrentResidualMag/sizeWindow );
-
- return (0);
+ return fCurrentResidualMag / fCurrentOriginalMag;
+ }
+ return 0;
}