summaryrefslogtreecommitdiff
path: root/sms
diff options
context:
space:
mode:
Diffstat (limited to 'sms')
-rw-r--r--sms/analysis.c17
-rw-r--r--sms/fixTracks.c45
-rw-r--r--sms/sineSynth.c12
-rw-r--r--sms/sms.c24
-rw-r--r--sms/synthesis.c4
5 files changed, 41 insertions, 61 deletions
diff --git a/sms/analysis.c b/sms/analysis.c
index a435a5a..90bec7f 100644
--- a/sms/analysis.c
+++ b/sms/analysis.c
@@ -31,23 +31,6 @@
/*! \brief maximum size for magnitude spectrum */
#define SMS_MAX_SPEC 8192
-void printAnalysisParams(SMS_AnalParams* params)
-{
- printf("fLowestFreq: %f\n"
- "fHighestFreq: %f\n"
- "fMinPeakMag: %f\n"
- "iSamplingRate: %d\n"
- "maxPeaks: %d\n"
- "fHighestFundamental: %f\n"
- "iRefHarmonic: %d\n"
- "fMinRefHarmMag: %f\n"
- "fRefHarmMagDiffFromMax: %f\n"
- "iSoundType: %d\n",
- params->fLowestFreq, params->fHighestFreq, params->fMinPeakMag, params->iSamplingRate,
- params->maxPeaks, params->fHighestFundamental, params->iRefHarmonic,
- params->fMinRefHarmMag, params->fRefHarmMagDiffFromMax, params->iSoundType);
-}
-
/*! \brief compute spectrum, find peaks, and fundamental of one frame
*
* This is the main core of analysis calls
diff --git a/sms/fixTracks.c b/sms/fixTracks.c
index 81e24ee..109d854 100644
--- a/sms/fixTracks.c
+++ b/sms/fixTracks.c
@@ -33,8 +33,8 @@
* \param pIState pointer to the state of tracks
* \param pAnalParams pointer to analysis parameters
*/
-static void FillGap (int iCurrentFrame, int iTrack, int *pIState,
- SMS_AnalParams *pAnalParams)
+static void FillGap(int iCurrentFrame, int iTrack, int *pIState,
+ SMS_AnalParams *pAnalParams)
{
int iFrame, iLastFrame = - (pIState[iTrack] - 1);
sfloat fConstant = TWO_PI / pAnalParams->iSamplingRate;
@@ -45,8 +45,8 @@ static void FillGap (int iCurrentFrame, int iTrack, int *pIState,
return;
/* if firstMag is 0 it means that there is no Gap, just the begining of a track */
- if (pAnalParams->ppFrames[iCurrentFrame -
- iLastFrame]->deterministic.pFSinAmp[iTrack] == 0)
+ if(pAnalParams->ppFrames[iCurrentFrame -
+ iLastFrame]->deterministic.pFSinAmp[iTrack] == 0)
{
pIState[iTrack] = 1;
return;
@@ -63,10 +63,10 @@ static void FillGap (int iCurrentFrame, int iTrack, int *pIState,
/* if inharmonic format and the two extremes are very different */
/* do not interpolate, it means that they are different tracks */
- if ((pAnalParams->iFormat == SMS_FORMAT_IH ||
- pAnalParams->iFormat == SMS_FORMAT_IHP) &&
- (MIN (fFirstFreq, fLastFreq) * .5 * pAnalParams->fFreqDeviation <
- fabs ((double) fLastFreq - fFirstFreq)))
+ if((pAnalParams->iFormat == SMS_FORMAT_IH ||
+ pAnalParams->iFormat == SMS_FORMAT_IHP) &&
+ (MIN (fFirstFreq, fLastFreq) * .5 * pAnalParams->fFreqDeviation <
+ fabs(fLastFreq - fFirstFreq)))
{
pIState[iTrack] = 1;
return;
@@ -76,8 +76,7 @@ static void FillGap (int iCurrentFrame, int iTrack, int *pIState,
fFreq = fFirstFreq;
/* fill the gap by interpolating values */
/* if the gap is too long it should consider the lower partials */
- for (iFrame = iCurrentFrame - iLastFrame + 1; iFrame < iCurrentFrame;
- iFrame++)
+ for(iFrame = iCurrentFrame - iLastFrame + 1; iFrame < iCurrentFrame; iFrame++)
{
/* interpolate magnitude */
fMag += fIncrMag;
@@ -119,16 +118,16 @@ static void FillGap (int iCurrentFrame, int iTrack, int *pIState,
* \param pIState pointer to the state of tracks
* \param pAnalParams pointer to analysis parameters
*/
-static void DeleteShortTrack (int iCurrentFrame, int iTrack, int *pIState,
+static void DeleteShortTrack(int iCurrentFrame, int iTrack, int *pIState,
SMS_AnalParams *pAnalParams)
{
int iFrame, frame;
- for (iFrame = 1; iFrame <= pIState[iTrack]; iFrame++)
+ for(iFrame = 1; iFrame <= pIState[iTrack]; iFrame++)
{
frame = iCurrentFrame - iFrame;
- if (frame <= 0)
+ if(frame <= 0)
return;
pAnalParams->ppFrames[frame]->deterministic.pFSinAmp[iTrack] = 0;
@@ -136,11 +135,11 @@ static void DeleteShortTrack (int iCurrentFrame, int iTrack, int *pIState,
pAnalParams->ppFrames[frame]->deterministic.pFSinPha[iTrack] = 0;
}
- if (pAnalParams->iDebugMode == SMS_DBG_CLEAN_TRAJ ||
- pAnalParams->iDebugMode == SMS_DBG_ALL)
- fprintf (stdout, "deleteShortTrack: track %d, frames %d to %d deleted\n",
- iTrack, pAnalParams->ppFrames[iCurrentFrame - pIState[iTrack]]->iFrameNum,
- pAnalParams->ppFrames[iCurrentFrame-1]->iFrameNum);
+ if(pAnalParams->iDebugMode == SMS_DBG_CLEAN_TRAJ ||
+ pAnalParams->iDebugMode == SMS_DBG_ALL)
+ fprintf(stdout, "deleteShortTrack: track %d, frames %d to %d deleted\n",
+ iTrack, pAnalParams->ppFrames[iCurrentFrame - pIState[iTrack]]->iFrameNum,
+ pAnalParams->ppFrames[iCurrentFrame-1]->iFrameNum);
/* reset state */
pIState[iTrack] = -pAnalParams->iMaxSleepingTime;
@@ -227,8 +226,8 @@ void sms_cleanTracks(int iCurrentFrame, SMS_AnalParams *pAnalParams)
* \param pAnalParams pointer to analysis parameters
* \param nTrack number of tracks
*/
-void sms_scaleDet(sfloat *pFSynthBuffer, sfloat *pFOriginalBuffer,
- sfloat *pFSinAmp, SMS_AnalParams *pAnalParams, int nTrack)
+void sms_scaleDet(sfloat *pFSynthBuffer, sfloat *pFOriginalBuffer,
+ sfloat *pFSinAmp, SMS_AnalParams *pAnalParams, int nTrack)
{
sfloat fOriginalMag = 0, fSynthesisMag = 0;
sfloat fCosScaleFactor;
@@ -237,8 +236,8 @@ void sms_scaleDet(sfloat *pFSynthBuffer, sfloat *pFOriginalBuffer,
/* get sound energy */
for(i = 0; i < pAnalParams->sizeHop; i++)
{
- fOriginalMag += fabs((double) pFOriginalBuffer[i]);
- fSynthesisMag += fabs((double) pFSynthBuffer[i]);
+ fOriginalMag += fabs(pFOriginalBuffer[i]);
+ fSynthesisMag += fabs(pFSynthBuffer[i]);
}
/* if total energy of deterministic sound is larger than original,
@@ -254,7 +253,7 @@ void sms_scaleDet(sfloat *pFSynthBuffer, sfloat *pFOriginalBuffer,
for(iTrack = 0; iTrack < nTrack; iTrack++)
if(pFSinAmp[iTrack] > 0)
- pFSinAmp[iTrack] = sms_magToDB (sms_dBToMag (pFSinAmp[iTrack]) * fCosScaleFactor);
+ pFSinAmp[iTrack] = sms_magToDB(sms_dBToMag(pFSinAmp[iTrack]) * fCosScaleFactor);
}
}
diff --git a/sms/sineSynth.c b/sms/sineSynth.c
index f2110af..c91bf65 100644
--- a/sms/sineSynth.c
+++ b/sms/sineSynth.c
@@ -163,25 +163,23 @@ void sms_sineSynthFrame(SMS_Data *pSmsData, sfloat *pFBuffer,
int iHalfSamplingRate = iSamplingRate >> 1;
/* go through all the tracks */
- for (i = 0; i < nTracks; i++)
+ for(i = 0; i < nTracks; i++)
{
- /* get magnitude */
fMag = pSmsData->pFSinAmp[i];
-
fFreq = pSmsData->pFSinFreq[i];
- /* gaurd so transposed frequencies don't alias */
- if (fFreq > iHalfSamplingRate || fFreq < 0)
+ /* make that sure transposed frequencies don't alias */
+ if(fFreq > iHalfSamplingRate || fFreq < 0)
fMag = 0;
/* generate sines if there are magnitude values */
- if ((fMag > 0) || (pLastFrame->pFSinAmp[i] > 0))
+ if((fMag > 0) || (pLastFrame->pFSinAmp[i] > 0))
{
/* frequency from Hz to radians */
fFreq = (fFreq == 0) ? 0 : TWO_PI * fFreq / iSamplingRate;
/* \todo make seperate function for SineSynth /wo phase */
- if (pSmsData->pFSinPha == NULL)
+ if(pSmsData->pFSinPha == NULL)
{
SineSynth(fFreq, fMag, pLastFrame, pFBuffer, sizeBuffer, i);
}
diff --git a/sms/sms.c b/sms/sms.c
index 0b0950e..0942783 100644
--- a/sms/sms.c
+++ b/sms/sms.c
@@ -469,34 +469,36 @@ void sms_initSynthParams(SMS_SynthParams *synthParams)
*/
int sms_initSynth(SMS_SynthParams *pSynthParams)
{
- int sizeHop, sizeFft, err;
+ int sizeHop, sizeFft;
/* make sure sizeHop is something to the power of 2 */
sizeHop = sms_power2(pSynthParams->sizeHop);
if(sizeHop != pSynthParams->sizeHop)
{
- sms_error("sizeHop was not a power of two.");
- err = -1;
+ printf("Warning: Synthesis hop size (%d) was not a power of two.\n",
+ pSynthParams->sizeHop);
+ printf(" Changed to %d.\n", sizeHop);
pSynthParams->sizeHop = sizeHop;
}
sizeFft = sizeHop * 2;
- pSynthParams->pFStocWindow =(sfloat *) calloc(sizeFft, sizeof(sfloat));
+ /* TODO: check memory allocation */
+ pSynthParams->pFStocWindow = (sfloat *)calloc(sizeFft, sizeof(sfloat));
sms_getWindow(sizeFft, pSynthParams->pFStocWindow, SMS_WIN_HANNING);
- pSynthParams->pFDetWindow = (sfloat *) calloc(sizeFft, sizeof(sfloat));
+ pSynthParams->pFDetWindow = (sfloat *)calloc(sizeFft, sizeof(sfloat));
sms_getWindow(sizeFft, pSynthParams->pFDetWindow, SMS_WIN_IFFT);
- /* allocate memory for analysis data - size of original hopsize */
- /* previous frame to interpolate from */
+ /* 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,
pSynthParams->nStochasticCoeff + 1, 1,
pSynthParams->iStochasticType, 0);
- pSynthParams->pSynthBuff = (sfloat *) calloc(sizeFft, sizeof(sfloat));
- pSynthParams->pMagBuff = (sfloat *) calloc(sizeHop, sizeof(sfloat));
- pSynthParams->pPhaseBuff = (sfloat *) calloc(sizeHop, sizeof(sfloat));
- pSynthParams->pSpectra = (sfloat *) calloc(sizeFft, sizeof(sfloat));
+ pSynthParams->pSynthBuff = (sfloat *)calloc(sizeFft, sizeof(sfloat));
+ pSynthParams->pMagBuff = (sfloat *)calloc(sizeHop, sizeof(sfloat));
+ pSynthParams->pPhaseBuff = (sfloat *)calloc(sizeHop, sizeof(sfloat));
+ pSynthParams->pSpectra = (sfloat *)calloc(sizeFft, sizeof(sfloat));
/* approximation envelope */
pSynthParams->approxEnvelope = (sfloat *)calloc(pSynthParams->nStochasticCoeff, sizeof(sfloat));
diff --git a/sms/synthesis.c b/sms/synthesis.c
index 3a8a3bb..c7439f1 100644
--- a/sms/synthesis.c
+++ b/sms/synthesis.c
@@ -182,7 +182,7 @@ void sms_synthesize(SMS_Data *pSmsData, sfloat *pFSynthesis, SMS_SynthParams *p
else if(pSynthParams->iSynthesisType == SMS_STYPE_DET)
{
if(pSynthParams->iDetSynthType == SMS_DET_IFFT)
- SineSynthIFFT (pSmsData, pSynthParams);
+ SineSynthIFFT(pSmsData, pSynthParams);
else /*pSynthParams->iDetSynthType == SMS_DET_SIN*/
{
sms_sineSynthFrame(pSmsData, pSynthParams->pSynthBuff, pSynthParams->sizeHop,
@@ -196,5 +196,3 @@ void sms_synthesize(SMS_Data *pSmsData, sfloat *pFSynthesis, SMS_SynthParams *p
for(i = 0; i < sizeHop; i++)
pFSynthesis[i] = sms_deEmphasis(pSynthParams->pSynthBuff[i], pSynthParams);
}
-
-