summaryrefslogtreecommitdiff
path: root/sms/residual.c
diff options
context:
space:
mode:
authorJohn Glover <john@john-glovers-macbook.local>2010-12-17 18:12:52 +0000
committerJohn Glover <john@john-glovers-macbook.local>2010-12-17 18:12:52 +0000
commit3f5c5d34d99b121bb621230a918b621a9524a015 (patch)
tree7ffd1b25480f6c8ca359ca180e0af58858f3568b /sms/residual.c
parent20473bc111d2ec16dbe1403b0d8e4d963e15c0c3 (diff)
downloadsimpl-3f5c5d34d99b121bb621230a918b621a9524a015.tar.gz
simpl-3f5c5d34d99b121bb621230a918b621a9524a015.tar.bz2
simpl-3f5c5d34d99b121bb621230a918b621a9524a015.zip
Removed static variables from sms_residual, changed the method signature to accept an SMS_ResidualParams structure.
Diffstat (limited to 'sms/residual.c')
-rw-r--r--sms/residual.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/sms/residual.c b/sms/residual.c
index ae9bf9a..1c217ce 100644
--- a/sms/residual.c
+++ b/sms/residual.c
@@ -33,39 +33,42 @@
* \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, sfloat *pResidual, sfloat *pWindow)
+int sms_residual(int sizeWindow, sfloat *pSynthesis, sfloat *pOriginal,
+ SMS_ResidualParams* residualParams)
{
- static sfloat fResidualMag = 0.;
- static sfloat fOriginalMag = 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];
+ for(i = 0; i < sizeWindow; i++)
+ residualParams->residual[i] = pOriginal[i] - pSynthesis[i];
/* get energy of residual */
- for (i=0; i<sizeWindow; i++)
- fCurrentResidualMag += (pResidual[i] * pResidual[i]);
+ for(i = 0; i < sizeWindow; i++)
+ fCurrentResidualMag += (residualParams->residual[i] * residualParams->residual[i]);
/* if residual is big enough compute coefficients */
- if (fCurrentResidualMag)
+ if(fCurrentResidualMag)
{
/* get energy of original */
- for (i=0; i<sizeWindow; i++)
+ for(i = 0; i < sizeWindow; i++)
fCurrentOriginalMag += (pOriginal[i] * pOriginal[i]);
- fOriginalMag = .5 * (fCurrentOriginalMag/sizeWindow + fOriginalMag);
- fResidualMag = .5 * (fCurrentResidualMag/sizeWindow + fResidualMag);
+ residualParams->originalMag =
+ .5 * (fCurrentOriginalMag/sizeWindow + residualParams->originalMag);
+ residualParams->residualMag =
+ .5 * (fCurrentResidualMag/sizeWindow + residualParams->residualMag);
/* scale residual if need to be */
- if (fResidualMag > fOriginalMag)
+ if(residualParams->residualMag > residualParams->originalMag)
{
- fScale = fOriginalMag / fResidualMag;
- for (i=0; i<sizeWindow; i++)
- pResidual[i] *= fScale;
+ fScale = residualParams->originalMag / residualParams->residualMag;
+ for(i = 0; i < sizeWindow; i++)
+ residualParams->residual[i] *= fScale;
}
return fCurrentResidualMag / fCurrentOriginalMag;