summaryrefslogtreecommitdiff
path: root/sms/fileIO.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/fileIO.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/fileIO.c')
-rw-r--r--sms/fileIO.c418
1 files changed, 172 insertions, 246 deletions
diff --git a/sms/fileIO.c b/sms/fileIO.c
index 8fbfa5b..e870c5a 100644
--- a/sms/fileIO.c
+++ b/sms/fileIO.c
@@ -37,7 +37,7 @@ static char pChTextString[1000]; /*!< string to store analysis parameters in sms
*
* \param pSmsHeader header for SMS file
*/
-void sms_initHeader (SMS_Header *pSmsHeader)
+void sms_initHeader(SMS_Header *pSmsHeader)
{
pSmsHeader->iSmsMagic = SMS_MAGIC;
pSmsHeader->iHeadBSize = sizeof(SMS_Header);
@@ -51,8 +51,6 @@ void sms_initHeader (SMS_Header *pSmsHeader)
pSmsHeader->nEnvCoeff = 0;
pSmsHeader->iMaxFreq = 0;
pSmsHeader->fResidualPerc = 0;
- pSmsHeader->nTextCharacters = 0;
- pSmsHeader->pChTextCharacters = NULL;
}
/*! \brief fill an SMS header with necessary information for storage
@@ -67,10 +65,9 @@ void sms_initHeader (SMS_Header *pSmsHeader)
* \param pAnalParams structure of analysis parameters
* \param pProgramString pointer to a string containing the name of the program that made the analysis data
*/
-void sms_fillHeader (SMS_Header *pSmsHeader, SMS_AnalParams *pAnalParams,
- char *pProgramString)
+void sms_fillHeader(SMS_Header *pSmsHeader, SMS_AnalParams *pAnalParams, char *pProgramString)
{
- sms_initHeader (pSmsHeader);
+ sms_initHeader(pSmsHeader);
pSmsHeader->nFrames = pAnalParams->nFrames;
pSmsHeader->iFormat = pAnalParams->iFormat;
pSmsHeader->iFrameRate = pAnalParams->iFrameRate;
@@ -83,35 +80,8 @@ void sms_fillHeader (SMS_Header *pSmsHeader, SMS_AnalParams *pAnalParams,
pSmsHeader->nStochasticCoeff = pAnalParams->nStochasticCoeff;
pSmsHeader->iEnvType = pAnalParams->specEnvParams.iType;
pSmsHeader->nEnvCoeff = pAnalParams->specEnvParams.nCoeff;
- pSmsHeader->iMaxFreq = (int) pAnalParams->fHighestFreq;
+ pSmsHeader->iMaxFreq = (int)pAnalParams->fHighestFreq;
pSmsHeader->iFrameBSize = sms_frameSizeB(pSmsHeader);
- sprintf (pChTextString,
- "created by %s with parameters: format %d, soundType %d, "
- "analysisDirection %d, windowSize %.2f,"
- " windowType %d, frameRate %d, highestFreq %.2f, minPeakMag %.2f,"
- " refHarmonic %d, minRefHarmMag %.2f, refHarmMagDiffFromMax %.2f,"
- " defaultFund %.2f, lowestFund %.2f, highestFund %.2f, nGuides %d,"
- " nTracks %d, freqDeviation %.2f, peakContToGuide %.2f,"
- " fundContToGuide %.2f, cleanTracks %d, iMinTrackLength %d,"
- "iMaxSleepingTime %d, stochasticType %d, nStocCoeff %d\n"
- "iEnvType: %d, nEnvCoeff: %d",
- pProgramString,
- pAnalParams->iFormat, pAnalParams->iSoundType,
- pAnalParams->iAnalysisDirection, pAnalParams->fSizeWindow,
- pAnalParams->iWindowType, pAnalParams->iFrameRate,
- pAnalParams->fHighestFreq, pAnalParams->fMinPeakMag,
- pAnalParams->iRefHarmonic, pAnalParams->fMinRefHarmMag,
- pAnalParams->fRefHarmMagDiffFromMax,
- pAnalParams->fDefaultFundamental, pAnalParams->fLowestFundamental,
- pAnalParams->fHighestFundamental, pAnalParams->nGuides,
- pAnalParams->nTracks, pAnalParams->fFreqDeviation,
- pAnalParams->fPeakContToGuide, pAnalParams->fFundContToGuide,
- pAnalParams->iCleanTracks, pAnalParams->iMinTrackLength,
- pAnalParams->iMaxSleepingTime, pAnalParams->iStochasticType,
- pAnalParams->nStochasticCoeff, pSmsHeader->iEnvType, pSmsHeader->nEnvCoeff);
-
- pSmsHeader->nTextCharacters = strlen (pChTextString) + 1;
- pSmsHeader->pChTextCharacters = (char *) pChTextString;
}
/*! \brief write SMS header to file
@@ -121,50 +91,31 @@ void sms_fillHeader (SMS_Header *pSmsHeader, SMS_AnalParams *pAnalParams,
* \param ppSmsFile (double pointer to) file to be created
* \return error code \see SMS_WRERR in SMS_ERRORS
*/
-int sms_writeHeader (char *pChFileName, SMS_Header *pSmsHeader,
- FILE **ppSmsFile)
+int sms_writeHeader(char *pChFileName, SMS_Header *pSmsHeader, FILE **ppSmsFile)
{
int iVariableSize = 0;
- if (pSmsHeader->iSmsMagic != SMS_MAGIC)
+ if(pSmsHeader->iSmsMagic != SMS_MAGIC)
{
sms_error("not an SMS file");
- return(-1);
+ return -1;
}
- if ((*ppSmsFile = fopen (pChFileName, "w+")) == NULL)
+ if((*ppSmsFile = fopen (pChFileName, "w+")) == NULL)
{
sms_error("cannot open file for writing");
- return(-1);
+ return -1;
}
- /* check variable size of header */
- /* iVariableSize = sizeof (int) * pSmsHeader->nLoopRecords + */
- /* sizeof (sfloat) * pSmsHeader->nSpecEnvelopePoints + */
- /* sizeof(char) * pSmsHeader->nTextCharacters; */
- iVariableSize = sizeof(char) * pSmsHeader->nTextCharacters;
- pSmsHeader->iHeadBSize = sizeof(SMS_Header) + iVariableSize;
+ pSmsHeader->iHeadBSize = sizeof(SMS_Header);
/* write header */
- if (fwrite((void *)pSmsHeader, (size_t)1, (size_t)sizeof(SMS_Header),
- *ppSmsFile) < (size_t)sizeof(SMS_Header))
+ if(fwrite((void *)pSmsHeader, (size_t)1, (size_t)sizeof(SMS_Header),
+ *ppSmsFile) < (size_t)sizeof(SMS_Header))
{
sms_error("cannot write output file");
return(-1);
}
- /* write variable part of header */
- if (pSmsHeader->nTextCharacters > 0)
- {
- char *pChStart = (char *) pSmsHeader->pChTextCharacters;
- int iSize = sizeof(char) * pSmsHeader->nTextCharacters;
-
- if (fwrite ((void *)pChStart, (size_t)1, (size_t)iSize, *ppSmsFile) <
- (size_t)iSize)
- {
- sms_error("cannot write output file (nTextCharacters)");
- return(-1);
- }
- }
- return (0);
+ return 0;
}
/*! \brief rewrite SMS header and close file
@@ -173,40 +124,23 @@ int sms_writeHeader (char *pChFileName, SMS_Header *pSmsHeader,
* \param pSmsHeader pointer to header for SMS file
* \return error code \see SMS_WRERR in SMS_ERRORS
*/
-int sms_writeFile (FILE *pSmsFile, SMS_Header *pSmsHeader)
+int sms_writeFile(FILE *pSmsFile, SMS_Header *pSmsHeader)
{
int iVariableSize;
-
rewind(pSmsFile);
- /* check variable size of header */
- iVariableSize = sizeof(char) * pSmsHeader->nTextCharacters;
-
- pSmsHeader->iHeadBSize = sizeof(SMS_Header) + iVariableSize;
+ pSmsHeader->iHeadBSize = sizeof(SMS_Header);
/* write header */
- if (fwrite((void *)pSmsHeader, (size_t)1, (size_t)sizeof(SMS_Header),
+ if(fwrite((void *)pSmsHeader, (size_t)1, (size_t)sizeof(SMS_Header),
pSmsFile) < (size_t)sizeof(SMS_Header))
{
sms_error("cannot write output file (header)");
- return(-1);
+ return -1;
}
- if (pSmsHeader->nTextCharacters > 0)
- {
- char *pChStart = (char *) pSmsHeader->pChTextCharacters;
- int iSize = sizeof(char) * pSmsHeader->nTextCharacters;
-
- if (fwrite ((void *)pChStart, (size_t)1, (size_t)iSize, pSmsFile) <
- (size_t)iSize)
- {
- sms_error("cannot write output file (nTextCharacters)");
- return(-1);
- }
- }
-
fclose(pSmsFile);
- return (0);
+ return 0;
}
/*! \brief write SMS frame
@@ -216,32 +150,31 @@ int sms_writeFile (FILE *pSmsFile, SMS_Header *pSmsHeader)
* \param pSmsFrame pointer to SMS data frame
* \return 0 on success, -1 on failure
*/
-int sms_writeFrame (FILE *pSmsFile, SMS_Header *pSmsHeader,
- SMS_Data *pSmsFrame)
+int sms_writeFrame(FILE *pSmsFile, SMS_Header *pSmsHeader, SMS_Data *pSmsFrame)
{
- if (fwrite ((void *)pSmsFrame->pSmsData, 1, pSmsHeader->iFrameBSize,
- pSmsFile) < (unsigned int) pSmsHeader->iFrameBSize)
+ if (fwrite((void *)pSmsFrame->pSmsData, 1, pSmsHeader->iFrameBSize,
+ pSmsFile) < (unsigned int) pSmsHeader->iFrameBSize)
{
sms_error("cannot write frame to output file");
- return(-1);
+ return -1;
}
- else return (0);
+ return 0;
}
-
/*! \brief get the size in bytes of the frame in a SMS file
*
* \param pSmsHeader pointer to SMS header
* \return the size in bytes of the frame
*/
-int sms_frameSizeB (SMS_Header *pSmsHeader)
+int sms_frameSizeB(SMS_Header *pSmsHeader)
{
int iSize, nDet;
- if (pSmsHeader->iFormat == SMS_FORMAT_H ||
- pSmsHeader->iFormat == SMS_FORMAT_IH)
+ if(pSmsHeader->iFormat == SMS_FORMAT_H ||
+ pSmsHeader->iFormat == SMS_FORMAT_IH)
nDet = 2;/* freq, mag */
- else nDet = 3; /* freq, mag, phase */
+ else
+ nDet = 3; /* freq, mag, phase */
iSize = sizeof (sfloat) * (nDet * pSmsHeader->nTracks);
@@ -255,10 +188,9 @@ int sms_frameSizeB (SMS_Header *pSmsHeader)
iSize += sizeof(sfloat) * (pSmsHeader->nStochasticCoeff * 2 + 1);
}
iSize += sizeof(sfloat) * pSmsHeader->nEnvCoeff;
- return(iSize);
+ return iSize;
}
-
/*! \brief function to read SMS header
*
* \param pChFileName file name for SMS file
@@ -266,108 +198,89 @@ int sms_frameSizeB (SMS_Header *pSmsHeader)
* \param ppSmsFile (double pointer to) inputfile
* \return error code \see SMS_ERRORS
*/
-int sms_getHeader (char *pChFileName, SMS_Header **ppSmsHeader,
- FILE **ppSmsFile)
+int sms_getHeader(char *pChFileName, SMS_Header **ppSmsHeader, FILE **ppSmsFile)
{
int iHeadBSize, iFrameBSize, nFrames;
int iMagicNumber;
/* open file for reading */
- if ((*ppSmsFile = fopen (pChFileName, "r")) == NULL)
+ if((*ppSmsFile = fopen (pChFileName, "r")) == NULL)
{
sms_error("could not open SMS header");
- return (-1);
+ return -1;
}
/* read magic number */
- if (fread ((void *) &iMagicNumber, (size_t) sizeof(int), (size_t)1,
- *ppSmsFile) < (size_t)1)
+ if(fread((void *) &iMagicNumber, (size_t) sizeof(int), (size_t)1,
+ *ppSmsFile) < (size_t)1)
{
sms_error("could not read SMS header");
- return (-1);
+ return -1;
}
- if (iMagicNumber != SMS_MAGIC)
+ if(iMagicNumber != SMS_MAGIC)
{
sms_error("not an SMS file");
- return (-1);
+ return -1;
}
/* read size of of header */
- if (fread ((void *) &iHeadBSize, (size_t) sizeof(int), (size_t)1,
- *ppSmsFile) < (size_t)1)
+ if(fread((void *) &iHeadBSize, (size_t) sizeof(int), (size_t)1,
+ *ppSmsFile) < (size_t)1)
{
sms_error("could not read SMS header (iHeadBSize)");
- return (-1);
+ return -1;
}
- if (iHeadBSize <= 0)
+ if(iHeadBSize <= 0)
{
sms_error("bad SMS header size");
- return (-1);
+ return -1;
}
/* read number of data Frames */
- if (fread ((void *) &nFrames, (size_t) sizeof(int), (size_t)1,
- *ppSmsFile) < (size_t)1)
+ if(fread((void *) &nFrames, (size_t) sizeof(int), (size_t)1,
+ *ppSmsFile) < (size_t)1)
{
sms_error("could not read SMS number of frames");
- return (-1);
+ return -1;
}
- if (nFrames <= 0)
+ if(nFrames <= 0)
{
sms_error("number of frames <= 0");
- return (-1);
+ return -1;
}
/* read size of data Frames */
- if (fread ((void *) &iFrameBSize, (size_t) sizeof(int), (size_t)1,
- *ppSmsFile) < (size_t)1)
+ if(fread((void *) &iFrameBSize, (size_t) sizeof(int), (size_t)1,
+ *ppSmsFile) < (size_t)1)
{
sms_error("could not read size of SMS data");
- return (-1);
+ return -1;
}
- if (iFrameBSize <= 0)
+ if(iFrameBSize <= 0)
{
sms_error("size bytes of frames <= 0");
- return (-1);
+ return -1;
}
/* allocate memory for header */
- if (((*ppSmsHeader) = (SMS_Header *)malloc (iHeadBSize)) == NULL)
+ if(((*ppSmsHeader) = (SMS_Header *)malloc (iHeadBSize)) == NULL)
{
sms_error("cannot allocate memory for header");
- return (-1);
+ return -1;
}
/* read header */
- rewind (*ppSmsFile);
- if (fread ((void *) (*ppSmsHeader), 1, iHeadBSize, *ppSmsFile) < (unsigned int) iHeadBSize)
+ rewind(*ppSmsFile);
+ if(fread ((void *) (*ppSmsHeader), 1, iHeadBSize, *ppSmsFile) < (unsigned int) iHeadBSize)
{
sms_error("cannot read header of SMS file");
- return (-1);
+ return -1;
}
- /* set pointers to variable part of header */
- /* if ((*ppSmsHeader)->nLoopRecords > 0) */
- /* (*ppSmsHeader)->pILoopRecords = (int *) ((char *)(*ppSmsHeader) + */
- /* sizeof(SMS_Header)); */
-
- /* if ((*ppSmsHeader)->nSpecEnvelopePoints > 0) */
- /* (*ppSmsHeader)->pFSpectralEnvelope = */
- /* (sfloat *) ((char *)(*ppSmsHeader) + sizeof(SMS_Header) + */
- /* sizeof(int) * (*ppSmsHeader)->nLoopRecords); */
-
- /* if ((*ppSmsHeader)->nTextCharacters > 0) */
- /* (*ppSmsHeader)->pChTextCharacters = */
- /* (char *) ((char *)(*ppSmsHeader) + sizeof(SMS_Header) + */
- /* sizeof(int) * (*ppSmsHeader)->nLoopRecords + */
- /* sizeof(sfloat) * (*ppSmsHeader)->nSpecEnvelopePoints); */
- if ((*ppSmsHeader)->nTextCharacters > 0)
- (*ppSmsHeader)->pChTextCharacters = (char *)(*ppSmsHeader) + sizeof(SMS_Header);
-
- return (0);
+ return 0;
}
/*! \brief read an SMS data frame
@@ -378,24 +291,23 @@ int sms_getHeader (char *pChFileName, SMS_Header **ppSmsHeader,
* \param pSmsFrame pointer to SMS frame
* \return 0 on sucess, -1 on error
*/
-int sms_getFrame (FILE *pSmsFile, SMS_Header *pSmsHeader, int iFrame,
- SMS_Data *pSmsFrame)
+int sms_getFrame(FILE *pSmsFile, SMS_Header *pSmsHeader, int iFrame, SMS_Data *pSmsFrame)
{
- if (fseek (pSmsFile, pSmsHeader->iHeadBSize + iFrame *
- pSmsHeader->iFrameBSize, SEEK_SET) < 0)
+ if(fseek(pSmsFile, pSmsHeader->iHeadBSize + iFrame *
+ pSmsHeader->iFrameBSize, SEEK_SET) < 0)
{
- sms_error ("cannot seek to the SMS frame");
- return (-1);
+ sms_error("cannot seek to the SMS frame");
+ return -1;
}
- if ((pSmsHeader->iFrameBSize =
- fread ((void *)pSmsFrame->pSmsData, (size_t)1,
- (size_t)pSmsHeader->iFrameBSize, pSmsFile))
- != pSmsHeader->iFrameBSize)
+ if((pSmsHeader->iFrameBSize =
+ fread((void *)pSmsFrame->pSmsData, (size_t)1,
+ (size_t)pSmsHeader->iFrameBSize, pSmsFile))
+ != pSmsHeader->iFrameBSize)
{
- sms_error ("cannot read SMS frame");
- return (-1);
+ sms_error("cannot read SMS frame");
+ return -1;
}
- return (0);
+ return 0;
}
/*! \brief allocate memory for a frame of SMS data
@@ -409,25 +321,34 @@ int sms_getFrame (FILE *pSmsFile, SMS_Header *pSmsHeader, int iFrame,
* \param nEnvCoeff number of envelope coefficients in frame
* \return 0 on success, -1 on error
*/
-int sms_allocFrame (SMS_Data *pSmsFrame, int nTracks, int nStochCoeff, int iPhase,
- int stochType, int nEnvCoeff)
+int sms_allocFrame(SMS_Data *pSmsFrame, int nTracks, int nStochCoeff, int iPhase,
+ int stochType, int nEnvCoeff)
{
sfloat *dataPos; /* a marker to locate specific data witin smsData */
+
/* calculate size of frame */
- int sizeData = 2 * nTracks * sizeof(sfloat);
- sizeData += 1 * sizeof(sfloat); //adding one for nSamples
- if (iPhase > 0) sizeData += nTracks * sizeof(sfloat);
- if (stochType == SMS_STOC_APPROX)
+ int sizeData = sizeof(sfloat); /* nSamples */
+ /* frequencies and magnitudes */
+ sizeData += 2 * nTracks * sizeof(sfloat);
+ /* phases */
+ if(iPhase > 0)
+ sizeData += nTracks * sizeof(sfloat);
+ /* stochastic coefficients */
+ if(stochType == SMS_STOC_APPROX)
sizeData += (nStochCoeff + 1) * sizeof(sfloat);
- else if (stochType == SMS_STOC_IFFT)
- sizeData += (2*nStochCoeff + 1) * sizeof(sfloat);
+ else if(stochType == SMS_STOC_IFFT)
+ sizeData += ((2*nStochCoeff) + 1) * sizeof(sfloat);
+ /* spectral envelope */
sizeData += nEnvCoeff * sizeof(sfloat); /* add in number of envelope coefficients (cep or fbins) if any */
+
/* allocate memory for data */
- if ((pSmsFrame->pSmsData = (sfloat *) malloc (sizeData)) == NULL)
+ pSmsFrame->pSmsData = (sfloat *)malloc(sizeData);
+ if(pSmsFrame->pSmsData == NULL)
{
sms_error("cannot allocate memory for SMS frame data");
- return (-1);
+ return -1;
}
+ memset(pSmsFrame->pSmsData, 0, sizeData);
/* set the variables in the structure */
/* \todo why not set these in init functions, then allocate with them?? */
@@ -435,40 +356,38 @@ int sms_allocFrame (SMS_Data *pSmsFrame, int nTracks, int nStochCoeff, int iPhas
pSmsFrame->nTracks = nTracks;
pSmsFrame->nCoeff = nStochCoeff;
pSmsFrame->nEnvCoeff = nEnvCoeff;
+
/* set pointers to data types within smsData array */
pSmsFrame->pFSinFreq = pSmsFrame->pSmsData;
- dataPos = (sfloat *)(pSmsFrame->pFSinFreq + nTracks);
- memset(pSmsFrame->pFSinFreq, 0, sizeof(sfloat) * nTracks);
+ dataPos = (sfloat *)(pSmsFrame->pFSinFreq + nTracks);
pSmsFrame->pFSinAmp = dataPos;
dataPos = (sfloat *)(pSmsFrame->pFSinAmp + nTracks);
- memset(pSmsFrame->pFSinAmp, 0, sizeof(sfloat) * nTracks);
- if (iPhase > 0)
+ if(iPhase > 0)
{
pSmsFrame->pFSinPha = dataPos;
- dataPos = (sfloat *) (pSmsFrame->pFSinPha + nTracks);
- memset(pSmsFrame->pFSinPha, 0, sizeof(sfloat) * nTracks);
+ dataPos = (sfloat *)(pSmsFrame->pFSinPha + nTracks);
}
- else pSmsFrame->pFSinPha = NULL;
+ else
+ pSmsFrame->pFSinPha = NULL;
- if (stochType == SMS_STOC_APPROX)
+ if(stochType == SMS_STOC_APPROX)
{
pSmsFrame->pFStocCoeff = dataPos;
- dataPos = (sfloat *) (pSmsFrame->pFStocCoeff + nStochCoeff);
- memset(pSmsFrame->pFStocCoeff, 0, sizeof(sfloat) * nStochCoeff);
+ dataPos = (sfloat *)(pSmsFrame->pFStocCoeff + nStochCoeff);
pSmsFrame->pFStocGain = dataPos;
- dataPos = (sfloat *) (pSmsFrame->pFStocGain + 1);
+ dataPos = (sfloat *)(pSmsFrame->pFStocGain + 1);
}
- else if (stochType == SMS_STOC_IFFT)
+ else if(stochType == SMS_STOC_IFFT)
{
pSmsFrame->pFStocCoeff = dataPos;
- dataPos = (sfloat *) (pSmsFrame->pFStocCoeff + nStochCoeff);
+ dataPos = (sfloat *)(pSmsFrame->pFStocCoeff + nStochCoeff);
pSmsFrame->pResPhase = dataPos;
- dataPos = (sfloat *) (pSmsFrame->pResPhase + nStochCoeff);
+ dataPos = (sfloat *)(pSmsFrame->pResPhase + nStochCoeff);
pSmsFrame->pFStocGain = dataPos;
- dataPos = (sfloat *) (pSmsFrame->pFStocGain + 1);
+ dataPos = (sfloat *)(pSmsFrame->pFStocGain + 1);
}
else
{
@@ -476,11 +395,13 @@ int sms_allocFrame (SMS_Data *pSmsFrame, int nTracks, int nStochCoeff, int iPhas
pSmsFrame->pResPhase = NULL;
pSmsFrame->pFStocGain = NULL;
}
- if (nEnvCoeff > 0)
+
+ if(nEnvCoeff > 0)
pSmsFrame->pSpecEnv = dataPos;
else
pSmsFrame->pSpecEnv = NULL;
- return (0);
+
+ return 0;
}
/*! \brief function to allocate an SMS data frame using an SMS_Header
@@ -492,40 +413,45 @@ int sms_allocFrame (SMS_Data *pSmsFrame, int nTracks, int nStochCoeff, int iPhas
* \param pSmsFrame pointer to SMS frame
* \return 0 on success, -1 on error
*/
-int sms_allocFrameH (SMS_Header *pSmsHeader, SMS_Data *pSmsFrame)
+int sms_allocFrameH(SMS_Header *pSmsHeader, SMS_Data *pSmsFrame)
{
int iPhase = (pSmsHeader->iFormat == SMS_FORMAT_HP ||
- pSmsHeader->iFormat == SMS_FORMAT_IHP) ? 1 : 0;
- return (sms_allocFrame (pSmsFrame, pSmsHeader->nTracks,
- pSmsHeader->nStochasticCoeff, iPhase,
- pSmsHeader->iStochasticType, pSmsHeader->nEnvCoeff));
+ pSmsHeader->iFormat == SMS_FORMAT_IHP) ? 1 : 0;
+ return sms_allocFrame(pSmsFrame, pSmsHeader->nTracks,
+ pSmsHeader->nStochasticCoeff, iPhase,
+ pSmsHeader->iStochasticType,
+ pSmsHeader->nEnvCoeff);
}
-
/*! \brief free the SMS data structure
*
* \param pSmsFrame pointer to frame of SMS data
*/
-void sms_freeFrame (SMS_Data *pSmsFrame)
+void sms_freeFrame(SMS_Data *pSmsFrame)
{
- free(pSmsFrame->pSmsData);
- pSmsFrame->nTracks = 0;
- pSmsFrame->nCoeff = 0;
- pSmsFrame->sizeData = 0;
- pSmsFrame->pFSinFreq = NULL;
- pSmsFrame->pFSinAmp = NULL;
- pSmsFrame->pFStocCoeff = NULL;
- pSmsFrame->pResPhase = NULL;
- pSmsFrame->pFStocGain = NULL;
+ if(!pSmsFrame)
+ return;
+
+ if(pSmsFrame->pSmsData)
+ free(pSmsFrame->pSmsData);
+
+ pSmsFrame->nTracks = 0;
+ pSmsFrame->nCoeff = 0;
+ pSmsFrame->sizeData = 0;
+ pSmsFrame->pFSinFreq = NULL;
+ pSmsFrame->pFSinAmp = NULL;
+ pSmsFrame->pFStocCoeff = NULL;
+ pSmsFrame->pResPhase = NULL;
+ pSmsFrame->pFStocGain = NULL;
}
/*! \brief clear the SMS data structure
*
* \param pSmsFrame pointer to frame of SMS data
*/
-void sms_clearFrame (SMS_Data *pSmsFrame)
+void sms_clearFrame(SMS_Data *pSmsFrame)
{
- memset ((char *) pSmsFrame->pSmsData, 0, pSmsFrame->sizeData);
+ memset(pSmsFrame->pSmsData, 0, pSmsFrame->sizeData);
}
/*! \brief copy a frame of SMS_Data
@@ -534,49 +460,49 @@ void sms_clearFrame (SMS_Data *pSmsFrame)
* \param pOriginalSmsData original frame
*
*/
-void sms_copyFrame (SMS_Data *pCopySmsData, SMS_Data *pOriginalSmsData)
+void sms_copyFrame(SMS_Data *pCopySmsData, SMS_Data *pOriginalSmsData)
{
/* if the two frames are the same size just copy data */
- if (pCopySmsData->sizeData == pOriginalSmsData->sizeData &&
- pCopySmsData->nTracks == pOriginalSmsData->nTracks)
+ if(pCopySmsData->sizeData == pOriginalSmsData->sizeData &&
+ pCopySmsData->nTracks == pOriginalSmsData->nTracks)
{
- memcpy ((char *)pCopySmsData->pSmsData,
- (char *)pOriginalSmsData->pSmsData,
- pCopySmsData->sizeData);
+ memcpy((char *)pCopySmsData->pSmsData,
+ (char *)pOriginalSmsData->pSmsData,
+ pCopySmsData->sizeData);
}
/* if frames is different size copy the smallest */
else
{
- int nTracks = MIN (pCopySmsData->nTracks, pOriginalSmsData->nTracks);
- int nCoeff = MIN (pCopySmsData->nCoeff, pOriginalSmsData->nCoeff);
+ int nTracks = MIN(pCopySmsData->nTracks, pOriginalSmsData->nTracks);
+ int nCoeff = MIN(pCopySmsData->nCoeff, pOriginalSmsData->nCoeff);
pCopySmsData->nTracks = nTracks;
pCopySmsData->nCoeff = nCoeff;
- memcpy ((char *)pCopySmsData->pFSinFreq,
- (char *)pOriginalSmsData->pFSinFreq,
- sizeof(sfloat) * nTracks);
- memcpy ((char *)pCopySmsData->pFSinAmp,
- (char *)pOriginalSmsData->pFSinAmp,
- sizeof(sfloat) * nTracks);
- if (pOriginalSmsData->pFSinPha != NULL &&
- pCopySmsData->pFSinPha != NULL)
- memcpy ((char *)pCopySmsData->pFSinPha,
- (char *)pOriginalSmsData->pFSinPha,
- sizeof(sfloat) * nTracks);
- if (pOriginalSmsData->pFStocCoeff != NULL &&
- pCopySmsData->pFStocCoeff != NULL)
+ memcpy((char *)pCopySmsData->pFSinFreq,
+ (char *)pOriginalSmsData->pFSinFreq,
+ sizeof(sfloat) * nTracks);
+ memcpy((char *)pCopySmsData->pFSinAmp,
+ (char *)pOriginalSmsData->pFSinAmp,
+ sizeof(sfloat) * nTracks);
+ if(pOriginalSmsData->pFSinPha != NULL &&
+ pCopySmsData->pFSinPha != NULL)
+ memcpy((char *)pCopySmsData->pFSinPha,
+ (char *)pOriginalSmsData->pFSinPha,
+ sizeof(sfloat) * nTracks);
+ if(pOriginalSmsData->pFStocCoeff != NULL &&
+ pCopySmsData->pFStocCoeff != NULL)
{
- if (pOriginalSmsData->pResPhase != NULL &&
- pCopySmsData->pResPhase != NULL)
- memcpy ((char *)pCopySmsData->pResPhase,
- (char *)pOriginalSmsData->pResPhase,
- sizeof(sfloat) * nCoeff);
+ if(pOriginalSmsData->pResPhase != NULL &&
+ pCopySmsData->pResPhase != NULL)
+ memcpy((char *)pCopySmsData->pResPhase,
+ (char *)pOriginalSmsData->pResPhase,
+ sizeof(sfloat) * nCoeff);
}
- if (pOriginalSmsData->pFStocGain != NULL &&
- pCopySmsData->pFStocGain != NULL)
- memcpy ((char *)pCopySmsData->pFStocGain,
- (char *)pOriginalSmsData->pFStocGain,
- sizeof(sfloat));
+ if(pOriginalSmsData->pFStocGain != NULL &&
+ pCopySmsData->pFStocGain != NULL)
+ memcpy((char *)pCopySmsData->pFStocGain,
+ (char *)pOriginalSmsData->pFStocGain,
+ sizeof(sfloat));
}
}
@@ -589,21 +515,22 @@ void sms_copyFrame (SMS_Data *pCopySmsData, SMS_Data *pOriginalSmsData)
* \param pSmsFrameOut sms output frame
* \param fInterpFactor interpolation factor
*/
-void sms_interpolateFrames (SMS_Data *pSmsFrame1, SMS_Data *pSmsFrame2,
- SMS_Data *pSmsFrameOut, sfloat fInterpFactor)
+void sms_interpolateFrames(SMS_Data *pSmsFrame1, SMS_Data *pSmsFrame2,
+ SMS_Data *pSmsFrameOut, sfloat fInterpFactor)
{
int i;
sfloat fFreq1, fFreq2;
/* interpolate the deterministic part */
- for (i = 0; i < pSmsFrame1->nTracks; i++)
+ for(i = 0; i < pSmsFrame1->nTracks; i++)
{
fFreq1 = pSmsFrame1->pFSinFreq[i];
fFreq2 = pSmsFrame2->pFSinFreq[i];
- if (fFreq1 == 0) fFreq1 = fFreq2;
- if (fFreq2 == 0) fFreq2 = fFreq1;
- pSmsFrameOut->pFSinFreq[i] =
- fFreq1 + fInterpFactor * (fFreq2 - fFreq1);
+ if(fFreq1 == 0)
+ fFreq1 = fFreq2;
+ if(fFreq2 == 0)
+ fFreq2 = fFreq1;
+ pSmsFrameOut->pFSinFreq[i] = fFreq1 + fInterpFactor * (fFreq2 - fFreq1);
pSmsFrameOut->pFSinAmp[i] =
pSmsFrame1->pFSinAmp[i] + fInterpFactor *
(pSmsFrame2->pFSinAmp[i] - pSmsFrame1->pFSinAmp[i]);
@@ -611,23 +538,22 @@ void sms_interpolateFrames (SMS_Data *pSmsFrame1, SMS_Data *pSmsFrame2,
/* interpolate the stochastic part. The pointer is non-null when the frame contains
stochastic coefficients */
- if (pSmsFrameOut->pFStocGain)
+ if(pSmsFrameOut->pFStocGain)
{
*(pSmsFrameOut->pFStocGain) =
*(pSmsFrame1->pFStocGain) + fInterpFactor *
(*(pSmsFrame2->pFStocGain) - *(pSmsFrame1->pFStocGain));
}
/*! \todo how to interpolate residual phase spectrum */
- for (i = 0; i < pSmsFrame1->nCoeff; i++)
+ for(i = 0; i < pSmsFrame1->nCoeff; i++)
pSmsFrameOut->pFStocCoeff[i] =
pSmsFrame1->pFStocCoeff[i] + fInterpFactor *
(pSmsFrame2->pFStocCoeff[i] - pSmsFrame1->pFStocCoeff[i]);
/* DO NEXT: interpolate spec env here if fbins */
- for (i = 0; i < pSmsFrame1->nEnvCoeff; i++)
+ for(i = 0; i < pSmsFrame1->nEnvCoeff; i++)
pSmsFrameOut->pSpecEnv[i] =
pSmsFrame1->pSpecEnv[i] + fInterpFactor *
(pSmsFrame2->pSpecEnv[i] - pSmsFrame1->pSpecEnv[i]);
-
-
}
+