summaryrefslogtreecommitdiff
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
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.
-rw-r--r--sms/analysis.c8
-rw-r--r--sms/residual.c33
-rw-r--r--sms/sms.c7
-rw-r--r--sms/sms.h5
4 files changed, 22 insertions, 31 deletions
diff --git a/sms/analysis.c b/sms/analysis.c
index 9e22ca3..a6b344d 100644
--- a/sms/analysis.c
+++ b/sms/analysis.c
@@ -339,11 +339,6 @@ int sms_findResidual(int sizeSynthesis, sfloat* pSynthesis,
sms_error("Residual signal length is smaller than the original signal length");
return -1;
}
- /*if(sizeSynthesis > sizeOriginal)*/
- /*{*/
- /* printf("Warning: synthesised signal is longer than the orignal signal. ");*/
- /* printf("Orignal will be zero padded.\n");*/
- /*}*/
/*sms_residual(sizeResidual, pSynthesis, pOriginal, pResidual);*/
return 0;
@@ -558,8 +553,7 @@ int sms_analyze(int sizeWaveform, sfloat *pWaveform, SMS_Data *pSmsData, SMS_Ana
pAnalParams->fResidualAccumPerc += sms_residual(sizeData,
pAnalParams->synthBuffer.pFBuffer,
pOriginal,
- pAnalParams->residualParams.residual,
- pAnalParams->residualParams.residualWindow);
+ &pAnalParams->residualParams);
if(pAnalParams->iStochasticType == SMS_STOC_APPROX)
{
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;
diff --git a/sms/sms.c b/sms/sms.c
index 825aca1..144f3a6 100644
--- a/sms/sms.c
+++ b/sms/sms.c
@@ -163,9 +163,6 @@ void sms_initAnalParams(SMS_AnalParams *pAnalParams)
pAnalParams->ppFrames = NULL;
/* residual */
sms_initResidualParams(&pAnalParams->residualParams);
- /*pAnalParams->sizeResidual = pAnalParams->sizeHop * 2;*/
- /*pAnalParams->residual = NULL;*/
- /*pAnalParams->residualWindow = NULL;*/
/* peak continuation */
pAnalParams->guideStates = NULL;
pAnalParams->guides = NULL;
@@ -489,7 +486,7 @@ int sms_initResidual(SMS_ResidualParams *residualParams)
return -1;
}
- /* */
+ /* residual signal */
residualParams->residual = (sfloat *)calloc(residualParams->residualSize, sizeof(sfloat));
if(residualParams->residual == NULL)
{
@@ -497,7 +494,7 @@ int sms_initResidual(SMS_ResidualParams *residualParams)
return -1;
}
- /* */
+ /* residual window */
residualParams->residualWindow = (sfloat *)calloc(residualParams->residualSize, sizeof(sfloat));
if(residualParams->residualWindow == NULL)
{
diff --git a/sms/sms.h b/sms/sms.h
index e3ac14b..4726760 100644
--- a/sms/sms.h
+++ b/sms/sms.h
@@ -269,9 +269,6 @@ typedef struct
sfloat spectrumWindow[SMS_MAX_SPEC];
sfloat fftBuffer[SMS_MAX_SPEC * 2];
SMS_ResidualParams residualParams;
- //int sizeResidual;
- //sfloat *residual;
- //sfloat *residualWindow;
int *guideStates;
SMS_Guide* guides;
sfloat inputBuffer[SMS_MAX_FRAME_SIZE];
@@ -675,7 +672,7 @@ void sms_initResidualParams(SMS_ResidualParams *residualParams);
int sms_initResidual(SMS_ResidualParams *residualParams);
void sms_freeResidual(SMS_ResidualParams *residualParams);
int sms_residual(int sizeWindow, sfloat *pSynthesis, sfloat *pOriginal,
- sfloat *pResidual, sfloat *pWindow);
+ SMS_ResidualParams* residualParams);
void sms_filterHighPass(int sizeResidual, sfloat *pResidual, int iSamplingRate);
int sms_stocAnalysis(int sizeWindow, sfloat *pResidual, sfloat *pWindow,
SMS_Data *pSmsFrame, SMS_AnalParams *pAnalParams);