/Users/richardeakin/projects/libsms/trunk/src/sms.h File Reference

header file to be included in all SMS application More...

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <memory.h>
#include <strings.h>
#include <sndfile.h>
Include dependency graph for sms.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SMS_Header
 structure for the header of an SMS file More...
struct  SMS_SndHeader
 structure including sound header information More...
struct  SMS_Data
 structure with SMS data More...
struct  SMS_SndBuffer
 buffer for sound data More...
struct  SMS_Peak
 structure for sinusodial peak More...
struct  SMS_AnalFrame
 structure to hold an analysis frame More...
struct  SMS_PeakParams
 structure with useful information for peak detection and continuation More...
struct  SMS_SEnvParams
 structure information and data for spectral enveloping More...
struct  SMS_AnalParams
 structure with useful information for analysis functions More...
struct  SMS_ModifyParams
 structure with parameters and data that will be used to modify an SMS_Data frame More...
struct  SMS_SynthParams
 structure with information for synthesis functions More...
struct  SMS_HarmCandidate
 structure to hold information about a harmonic candidate More...
struct  SMS_ContCandidate
 structure to hold information about a continuation candidate More...
struct  SMS_Guide
 information attached to a guide More...

Defines

#define SMS_VERSION   1.1
 version control number
#define SMS_MAX_NPEAKS   400
 maximum number of peaks
#define sfloat   float
#define SMS_MAX_WINDOW   8190
 maximum size for analysis window
#define SMS_MIN_GOOD_FRAMES   3
#define SMS_MAX_DEVIATION   .01
#define SMS_ANAL_DELAY   100
#define SMS_DELAY_FRAMES   (SMS_MIN_GOOD_FRAMES + SMS_ANAL_DELAY)
#define SMS_MIN_SIZE_FRAME   128
#define PI   3.141592653589793238462643
#define TWO_PI   6.28318530717958647692
#define INV_TWO_PI   (1 / TWO_PI)
#define PI_2   1.57079632679489661923
#define LOG2   0.69314718055994529
#define LOG10   2.3025850929940459
#define EXP   2.7182818284590451
#define MAX(a, b)   ((a) > (b) ? (a) : (b))
 returns the maximum of a and b
#define MIN(a, b)   ((a) < (b) ? (a) : (b))
 returns the minimum of a and b

Enumerations

enum  SMS_Format { SMS_FORMAT_H, SMS_FORMAT_IH, SMS_FORMAT_HP, SMS_FORMAT_IHP }
 

analysis format

More...
enum  SMS_SynthType { SMS_STYPE_ALL, SMS_STYPE_DET, SMS_STYPE_STOC }
 

synthesis types

More...
enum  SMS_DetSynthType { SMS_DET_IFFT, SMS_DET_SIN }
 

synthesis method for deterministic component

More...
enum  SMS_StocSynthType { SMS_STOC_NONE, SMS_STOC_APPROX, SMS_STOC_IFFT }
 

synthesis method for stochastic component

More...
enum  SMS_SpecEnvType { SMS_ENV_NONE, SMS_ENV_CEP, SMS_ENV_FBINS }
 

synthesis method for deterministic component

More...
enum  SMS_ERRORS {
  SMS_OK, SMS_NOPEN, SMS_NSMS, SMS_MALLOC,
  SMS_RDERR, SMS_WRERR, SMS_SNDERR
}
 

Error codes returned by SMS file functions.

More...
enum  SMS_DBG {
  SMS_DBG_NONE, SMS_DBG_DET, SMS_DBG_PEAK_DET, SMS_DBG_HARM_DET,
  SMS_DBG_PEAK_CONT, SMS_DBG_CLEAN_TRAJ, SMS_DBG_SINE_SYNTH, SMS_DBG_STOC_ANAL,
  SMS_DBG_STOC_SYNTH, SMS_DBG_SMS_ANAL, SMS_DBG_ALL, SMS_DBG_RESIDUAL,
  SMS_DBG_SYNC
}
 

debug modes

More...
enum  SMS_SOUND_TYPE { SMS_SOUND_TYPE_MELODY, SMS_SOUND_TYPE_NOTE }
enum  SMS_DIRECTION { SMS_DIR_FWD, SMS_DIR_REV }
enum  SMS_WINDOWS {
  SMS_WIN_HAMMING, SMS_WIN_BH_62, SMS_WIN_BH_70, SMS_WIN_BH_74,
  SMS_WIN_BH_92, SMS_WIN_HANNING, SMS_WIN_IFFT
}
enum  SMS_FRAME_STATUS {
  SMS_FRAME_EMPTY, SMS_FRAME_READY, SMS_FRAME_PEAKS_FOUND, SMS_FRAME_FUND_FOUND,
  SMS_FRAME_TRAJ_FOUND, SMS_FRAME_CLEANED, SMS_FRAME_RECOMPUTED, SMS_FRAME_DETER_SYNTH,
  SMS_FRAME_STOC_COMPUTED, SMS_FRAME_DONE, SMS_FRAME_END
}
 

frame status

More...

Functions

sfloat sms_magToDB (sfloat x)
 convert from magnitude to decibel
sfloat sms_dBToMag (sfloat x)
 convert from decibel to magnitude
void sms_arrayMagToDB (int sizeArray, sfloat *pArray)
 convert an array from magnitude to decibel
void sms_arrayDBToMag (int sizeArray, sfloat *pArray)
 convert and array from decibel (0-100) to magnitude (0-1)
void sms_setMagThresh (sfloat x)
 set the linear magnitude threshold
sfloat sms_rms (int sizeArray, sfloat *pArray)
 Root Mean Squared of an array.
sfloat sms_sine (sfloat fTheta)
 table-lookup sine method
sfloat sms_sinc (sfloat fTheta)
 global sinc table-lookup method
sfloat sms_random (void)
 random number genorator
int sms_power2 (int n)
 make sure a number is a power of 2
sfloat sms_scalarTempered (float x)
void sms_arrayScalarTempered (int sizeArray, sfloat *pArray)
 scale an array of linear frequencies to the well-tempered scale
int sms_analyze (int sizeWaveform, sfloat *pWaveform, SMS_Data *pSmsFrame, SMS_AnalParams *pAnalParams)
 main function to perform the SMS analysis on a single frame
void sms_analyzeFrame (int iCurrentFrame, SMS_AnalParams *pAnalParams, sfloat fRefFundamental)
 compute spectrum, find peaks, and fundamental of one frame
int sms_init (void)
 initialize global data
void sms_free (void)
 free global data
int sms_initAnalysis (SMS_AnalParams *pAnalParams, SMS_SndHeader *pSoundHeader)
 initialize analysis data structure's arrays
void sms_initAnalParams (SMS_AnalParams *pAnalParams)
 give default values to an SMS_AnalParams struct
void sms_initSynthParams (SMS_SynthParams *synthParams)
 give default values to an SMS_SynthParams struct
int sms_initSynth (SMS_Header *pSmsHeader, SMS_SynthParams *pSynthParams)
 initialize synthesis data structure's arrays
int sms_changeSynthHop (SMS_SynthParams *pSynthParams, int sizeHop)
void sms_freeAnalysis (SMS_AnalParams *pAnalParams)
 free analysis data
void sms_freeSynth (SMS_SynthParams *pSynthParams)
 free analysis data
void sms_fillSoundBuffer (int sizeWaveform, sfloat *pWaveform, SMS_AnalParams *pAnalParams)
 fill the sound buffer
void sms_windowCentered (int sizeWindow, sfloat *pWaveform, float *pWindow, int sizeFft, float *pFftBuffer)
void sms_getWindow (int sizeWindow, sfloat *pWindow, int iWindowType)
 main function for getting various windows
void sms_scaleWindow (int sizeWindow, sfloat *pWindow)
int sms_spectrum (int sizeWindow, sfloat *pWaveform, float *pWindow, int sizeMag, sfloat *pMag, float *pPhase)
int sms_invSpectrum (int sizeWaveform, sfloat *pWaveform, float *pWindow, int sizeMag, sfloat *pMag, float *pPhase)
int sms_invQuickSpectrumW (sfloat *pFMagSpectrum, float *pFPhaseSpectrum, int sizeFft, sfloat *pFWaveform, int sizeWave, sfloat *pFWindow)
int sms_spectralApprox (sfloat *pSpec1, int sizeSpec1, int sizeSpec1Used, sfloat *pSpec2, int sizeSpec2, int nCoefficients)
 approximate a magnitude spectrum First downsampling using local maxima and then upsampling using linear interpolation. The output spectrum doesn't have to be the same size as the input one.
int sms_spectrumMag (int sizeWindow, sfloat *pWaveform, float *pWindow, int sizeMag, sfloat *pMag)
void sms_dCepstrum (int sizeCepstrum, sfloat *pCepstrum, int sizeFreq, float *pFreq, float *pMag, sfloat fLambda, int iSamplingRate)
void sms_dCepstrumEnvelope (int sizeCepstrum, sfloat *pCepstrum, int sizeEnv, float *pEnv)
void sms_spectralEnvelope (SMS_Data *pSmsData, SMS_SEnvParams *pSpecEnvParams)
 main function for computing spectral envelope from sinusoidal peaks
int sms_sizeNextWindow (int iCurrentFrame, SMS_AnalParams *pAnalParams)
 set window size for next frame
sfloat sms_fundDeviation (SMS_AnalParams *pAnalParams, int iCurrentFrame)
 get deviation from average fundamental \
int sms_detectPeaks (int sizeSpec, sfloat *pFMag, float *pPhase, SMS_Peak *pSpectralPeaks, SMS_PeakParams *pPeakParams)
void sms_harmDetection (SMS_AnalFrame *pFrame, sfloat fRefFundamental, SMS_PeakParams *pPeakParams)
 main harmonic detection function
int sms_peakContinuation (int iFrame, SMS_AnalParams *pAnalParams)
 function to advance the guides through the next frame
sfloat sms_preEmphasis (float fInput)
sfloat sms_deEmphasis (float fInput)
void sms_cleanTracks (int iCurrentFrame, SMS_AnalParams *pAnalParams)
 fill gaps and delete short tracks
void sms_scaleDet (sfloat *pSynthBuffer, float *pOriginalBuffer, sfloat *pSinAmp, SMS_AnalParams *pAnalParams, int nTracks)
int sms_prepSine (int nTableSize)
 prepares the sine table
int sms_prepSinc (int nTableSize)
 prepare the Sinc table
void sms_clearSine (void)
 clear sine table
void sms_clearSinc (void)
 clear sine table
void sms_synthesize (SMS_Data *pSmsFrame, sfloat *pSynthesis, SMS_SynthParams *pSynthParams)
 synthesizes one frame of SMS data
void sms_sineSynthFrame (SMS_Data *pSmsFrame, sfloat *pBuffer, int sizeBuffer, SMS_Data *pLastFrame, int iSamplingRate)
 generate all the sinusoids for a given frame
void sms_initHeader (SMS_Header *pSmsHeader)
 initialize the header structure of an SMS file
int sms_getHeader (char *pChFileName, SMS_Header **ppSmsHeader, FILE **ppInputFile)
 function to read SMS header
void sms_fillHeader (SMS_Header *pSmsHeader, SMS_AnalParams *pAnalParams, char *pProgramString)
 fill an SMS header with necessary information for storage
int sms_writeHeader (char *pFileName, SMS_Header *pSmsHeader, FILE **ppOutSmsFile)
 write SMS header to file
int sms_writeFile (FILE *pSmsFile, SMS_Header *pSmsHeader)
 rewrite SMS header and close file
int sms_initFrame (int iCurrentFrame, SMS_AnalParams *pAnalParams, int sizeWindow)
 initialize the current frame
int sms_allocFrame (SMS_Data *pSmsFrame, int nTracks, int nCoeff, int iPhase, int stochType, int nEnvCoeff)
 allocate memory for a frame of SMS data
int sms_allocFrameH (SMS_Header *pSmsHeader, SMS_Data *pSmsFrame)
 function to allocate an SMS data frame using an SMS_Header
int sms_getFrame (FILE *pInputFile, SMS_Header *pSmsHeader, int iFrame, SMS_Data *pSmsFrame)
 read an SMS data frame
int sms_writeFrame (FILE *pSmsFile, SMS_Header *pSmsHeader, SMS_Data *pSmsFrame)
 write SMS frame
void sms_freeFrame (SMS_Data *pSmsFrame)
 free the SMS data structure
void sms_clearFrame (SMS_Data *pSmsFrame)
 clear the SMS data structure
void sms_copyFrame (SMS_Data *pCopySmsFrame, SMS_Data *pOriginalSmsFrame)
 copy a frame of SMS_Data
int sms_frameSizeB (SMS_Header *pSmsHeader)
 get the size in bytes of the frame in a SMS file
int sms_residual (int sizeWindow, sfloat *pSynthesis, float *pOriginal, float *pResidual, float *pWindow)
void sms_filterHighPass (int sizeResidual, sfloat *pResidual, int iSamplingRate)
 function to filter a waveform with a high-pass filter
int sms_stocAnalysis (int sizeWindow, sfloat *pResidual, float *pWindow, SMS_Data *pSmsFrame)
void sms_interpolateFrames (SMS_Data *pSmsFrame1, SMS_Data *pSmsFrame2, SMS_Data *pSmsFrameOut, sfloat fInterpFactor)
 function to interpolate two SMS frames
int sms_openSF (char *pChInputSoundFile, SMS_SndHeader *pSoundHeader)
 open a sound file and check its header
void sms_closeSF ()
 close a sound file that was open for reading
int sms_getSound (SMS_SndHeader *pSoundHeader, long sizeSound, sfloat *pSound, long offset)
 get a chunk of sound from input file
int sms_createSF (char *pChOutputSoundFile, int iSamplingRate, int iType)
 function to create an output sound file
void sms_writeSound (sfloat *pBuffer, int sizeBuffer)
 write to the sound file data
void sms_writeSF (void)
 function to write the output sound file to disk
void sms_fft (int sizeFft, sfloat *pArray)
 Forward Fast Fourier Transform.
void sms_ifft (int sizeFft, sfloat *pArray)
 Inverse Forward Fast Fourier Transform.
void sms_RectToPolar (int sizeSpec, sfloat *pReal, float *pMag, float *pPhase)
void sms_PolarToRect (int sizeSpec, sfloat *pReal, float *pMag, float *pPhase)
void sms_spectrumRMS (int sizeMag, sfloat *pReal, float *pMag)
void sms_initModify (SMS_Header *header, SMS_ModifyParams *params)
 initialize a modifications structure based on an SMS_Header
void sms_initModifyParams (SMS_ModifyParams *params)
 initialize modification parameters
void sms_freeModify (SMS_ModifyParams *params)
 free memory allocated during initialization
void sms_modify (SMS_Data *frame, SMS_ModifyParams *params)
 modify a frame (SMS_Data object)
int sms_createResSF (int iSamplingRate)
 function to create the residual sound file
int sms_writeResSound (sfloat *pBuffer, int sizeBuffer)
 function to write to the residual sound file
void sms_writeResSF (void)
 write the residual sound file to disk
int sms_createDebugFile (SMS_AnalParams *pAnalParams)
 function to create the debug file
void sms_writeDebugData (sfloat *pBuffer1, float *pBuffer2, sfloat *pBuffer3, int sizeBuffer)
void sms_writeDebugFile (void)
 function to write the residual sound file to disk
void sms_error (char *pErrorMessage)
 get a string containing information about the error code
int sms_errorCheck (void)
 check if an error has been reported
char * sms_errorString (void)
 get a string containing information about the last error

Detailed Description

header file to be included in all SMS application


Define Documentation

#define sfloat   float
#define SMS_ANAL_DELAY   100

number of frames in the past to be looked in possible re-analyze

Todo:
this should be a parameter in AnalParams

Referenced by ReAnalyzeFrame().

#define SMS_DELAY_FRAMES   (SMS_MIN_GOOD_FRAMES + SMS_ANAL_DELAY)

total number of delay frames

Referenced by sms_analyze(), and sms_initAnalParams().

#define SMS_MAX_DEVIATION   .01

maximum deviation allowed

Referenced by ReAnalyzeFrame(), and sms_analyze().

#define SMS_MAX_NPEAKS   400

maximum number of peaks

Referenced by GetNextClosestPeak(), GetNextMax(), sms_initAnalysis(), and sms_initFrame().

#define SMS_MAX_WINDOW   8190

maximum size for analysis window

Referenced by sms_initAnalysis(), and sms_sizeNextWindow().

#define SMS_MIN_GOOD_FRAMES   3

minimum number of stable frames for backward search

Referenced by ReAnalyzeFrame(), and sms_fundDeviation().

#define SMS_MIN_SIZE_FRAME   128

Referenced by sms_initSynthParams().

#define SMS_VERSION   1.1

version control number


Enumeration Type Documentation

enum SMS_DBG

debug modes

Todo:
write details about debug files
Enumerator:
SMS_DBG_NONE 

0, no debugging

SMS_DBG_DET 

1, not yet implemented

Todo:
make this show main information to look at for discovering the correct deterministic parameters
SMS_DBG_PEAK_DET 

2, peak detection function

SMS_DBG_HARM_DET 

3, harmonic detection function

SMS_DBG_PEAK_CONT 

4, peak continuation function

SMS_DBG_CLEAN_TRAJ 

5, clean tracks function

SMS_DBG_SINE_SYNTH 

6, sine synthesis function

SMS_DBG_STOC_ANAL 

7, stochastic analysis function

SMS_DBG_STOC_SYNTH 

8, stochastic synthesis function

SMS_DBG_SMS_ANAL 

9, top level analysis function

SMS_DBG_ALL 

10, everything

SMS_DBG_RESIDUAL 

11, write residual to file

SMS_DBG_SYNC 

12, write original, synthesis and residual to a text file

synthesis method for deterministic component

There are two options for deterministic synthesis available to the SMS synthesizer. The Inverse Fast Fourier Transform method (IFFT) is more effecient for models with lots of partial tracks, but can possibly smear transients. The Sinusoidal Table Lookup (SIN) can theoritically support faster moving tracks at a higher fidelity, but can consume lots of cpu at varying rates.

Enumerator:
SMS_DET_IFFT 

Inverse Fast Fourier Transform (IFFT)

SMS_DET_SIN 

Sinusoidal Table Lookup (SIN)

Enumerator:
SMS_DIR_FWD 

analysis from left to right

SMS_DIR_REV 

analysis from right to left

enum SMS_ERRORS

Error codes returned by SMS file functions.

Enumerator:
SMS_OK 

0, no error

SMS_NOPEN 

1, couldn't open file

SMS_NSMS 

2, not a SMS file

SMS_MALLOC 

3, couldn't allocate memory

SMS_RDERR 

4, read error

SMS_WRERR 

5, write error

SMS_SNDERR 

7, sound IO error

enum SMS_Format

analysis format

Is the signal is known to be harmonic, using format harmonic (with out without phase) will give more accuracy to the peak continuation algorithm. If the signal is known to be inharmonic, then it is best to use one of the inharmonic settings to tell the peak continuation algorithm to just look at the peaks and connect them, instead of trying to look for peaks at specific frequencies (harmonic partials).

Enumerator:
SMS_FORMAT_H 

0, format harmonic

SMS_FORMAT_IH 

1, format inharmonic

SMS_FORMAT_HP 

2, format harmonic with phase

SMS_FORMAT_IHP 

3, format inharmonic with phase

frame status

Enumerator:
SMS_FRAME_EMPTY 
SMS_FRAME_READY 
SMS_FRAME_PEAKS_FOUND 
SMS_FRAME_FUND_FOUND 
SMS_FRAME_TRAJ_FOUND 
SMS_FRAME_CLEANED 
SMS_FRAME_RECOMPUTED 
SMS_FRAME_DETER_SYNTH 
SMS_FRAME_STOC_COMPUTED 
SMS_FRAME_DONE 
SMS_FRAME_END 
Enumerator:
SMS_SOUND_TYPE_MELODY 

0, sound composed of several notes

SMS_SOUND_TYPE_NOTE 

1, sound composed of a single note

synthesis method for deterministic component

There are two options for deterministic synthesis available to the SMS synthesizer. The Inverse Fast Fourier Transform method (IFFT) is more effecient for models with lots of partial tracks, but can possibly smear transients. The Sinusoidal Table Lookup (SIN) can theoritically support faster moving tracks at a higher fidelity, but can consume lots of cpu at varying rates.

Enumerator:
SMS_ENV_NONE 

none

SMS_ENV_CEP 

cepstral coefficients

SMS_ENV_FBINS 

frequency bins

synthesis method for stochastic component

Currently, Stochastic Approximation is the only reasonable choice for stochastic synthesis: this method approximates the spectrum of the stochastic component by a specified number of coefficients during analyses, and then approximates another set of coefficients during synthesis in order to fit the specified hopsize. The phases of the coefficients are randomly generated, according to the theory that a stochastic spectrum consists of random phases.

The Inverse FFT method is not implemented, but is based on the idea of storing the exact spectrum and phases of the residual component to file. Synthesis could then be an exact reconstruction of the original signal, provided interpolation is not necessary.

No stochastic component can also be specified in order to skip the this time consuming process altogether. This is especially useful when performing multiple analyses to fine tune parameters pertaining to the determistic component; once that is achieved, the stochastic component will be much better as well.

Enumerator:
SMS_STOC_NONE 

0, no stochastistic component

SMS_STOC_APPROX 

1, Inverse FFT, magnitude approximation and generated phases

SMS_STOC_IFFT 

2, inverse FFT, interpolated spectrum (not used)

synthesis types

These values are used to determine whether to synthesize both deterministic and stochastic components together, the deterministic component alone, or the stochastic component alone.

Enumerator:
SMS_STYPE_ALL 

both components combined

SMS_STYPE_DET 

deterministic component alone

SMS_STYPE_STOC 

stochastic component alone

Enumerator:
SMS_WIN_HAMMING 

0: hamming

SMS_WIN_BH_62 

1: blackman-harris, 62dB cutoff

SMS_WIN_BH_70 

2: blackman-harris, 70dB cutoff

SMS_WIN_BH_74 

3: blackman-harris, 74dB cutoff

SMS_WIN_BH_92 

4: blackman-harris, 92dB cutoff

SMS_WIN_HANNING 

5: hanning

SMS_WIN_IFFT 

6: window for deterministic synthesis based on the Inverse-FFT algorithm. This is a combination of an inverse Blackman-Harris 92dB and a triangular window.


Function Documentation

int sms_allocFrame ( SMS_Data pSmsFrame,
int  nTracks,
int  nStochCoeff,
int  iPhase,
int  stochType,
int  nEnvCoeff 
)

allocate memory for a frame of SMS data

Parameters:
pSmsFrame pointer to a frame of SMS data
nTracks number of sinusoidal tracks in frame
nStochCoeff number of stochastic coefficients in frame
iPhase whether phase information is in the frame
stochType stochastic resynthesis type
nStochCoeff number of envelope coefficients in frame
nEnvCoeff number of envelope coefficients in frame
Returns:
0 on success, -1 on error

References SMS_Data::nCoeff, SMS_Data::nEnvCoeff, SMS_Data::nTracks, SMS_Data::pFSinAmp, SMS_Data::pFSinFreq, SMS_Data::pFSinPha, SMS_Data::pFStocCoeff, SMS_Data::pFStocGain, SMS_Data::pResPhase, SMS_Data::pSmsData, SMS_Data::pSpecEnv, sfloat, SMS_Data::sizeData, sms_error(), SMS_STOC_APPROX, and SMS_STOC_IFFT.

Referenced by sms_allocFrameH(), sms_initAnalysis(), and sms_initSynth().

Here is the call graph for this function:

int sms_allocFrameH ( SMS_Header pSmsHeader,
SMS_Data pSmsFrame 
)

function to allocate an SMS data frame using an SMS_Header

this one is used when you have only read the header, such as after opening a file.

Parameters:
pSmsHeader pointer to SMS header
pSmsFrame pointer to SMS frame
Returns:
0 on success, -1 on error

References SMS_Header::iFormat, SMS_Header::iStochasticType, SMS_Header::nEnvCoeff, SMS_Header::nStochasticCoeff, SMS_Header::nTracks, sms_allocFrame(), SMS_FORMAT_HP, and SMS_FORMAT_IHP.

Here is the call graph for this function:

int sms_analyze ( int  sizeWaveform,
sfloat *  pWaveform,
SMS_Data pSmsData,
SMS_AnalParams pAnalParams 
)

main function to perform the SMS analysis on a single frame

The input is a section of the sound, the output is the SMS data

Parameters:
sizeWaveform size of input waveform data
pWaveform pointer to input waveform data
pSmsData pointer to output SMS data
pAnalParams pointer to analysis parameters
Returns:
Todo:
sort out return meanings

Todo:
when deviation is really off, this function returns -1, yet it isn't used.. is it being recomputed ??

References SMS_AnalFrame::deterministic, SMS_AnalParams::fDefaultFundamental, SMS_AnalFrame::fFundamental, SMS_AnalParams::fResidualAccumPerc, SMS_AnalParams::iCleanTracks, SMS_AnalParams::iDefaultSizeWindow, SMS_AnalParams::iFormat, SMS_AnalFrame::iFrameSample, SMS_SndBuffer::iMarker, SMS_AnalParams::iMaxDelayFrames, SMS_AnalParams::iSamplingRate, SMS_AnalParams::iSoundType, SMS_AnalFrame::iStatus, SMS_AnalParams::iStochasticType, SMS_SEnvParams::iType, MAX, MIN, SMS_AnalFrame::nPeaks, SMS_Data::nTracks, SMS_SndBuffer::pFBuffer, SMS_Data::pFSinAmp, SMS_Data::pFSinFreq, SMS_Data::pFSinPha, SMS_Data::pFStocCoeff, SMS_AnalParams::ppFrames, SMS_Data::pResPhase, SMS_AnalParams::prevFrame, ReAnalyzeFrame(), sfloat, SMS_SndBuffer::sizeBuffer, SMS_AnalParams::sizeHop, SMS_AnalParams::sizeNextRead, sms_analyzeFrame(), sms_arrayDBToMag(), sms_cleanTracks(), sms_clearFrame(), SMS_DELAY_FRAMES, SMS_ENV_NONE, sms_error(), sms_errorCheck(), sms_errorString(), sms_fillSoundBuffer(), sms_filterHighPass(), SMS_FORMAT_HP, SMS_FORMAT_IH, SMS_FORMAT_IHP, SMS_FRAME_DONE, SMS_FRAME_EMPTY, SMS_FRAME_END, SMS_FRAME_READY, sms_fundDeviation(), sms_getWindow(), sms_initFrame(), SMS_MAX_DEVIATION, sms_peakContinuation(), sms_power2(), sms_residual(), sms_scaleDet(), sms_scaleWindow(), sms_sineSynthFrame(), sms_sizeNextWindow(), SMS_SOUND_TYPE_NOTE, sms_spectralEnvelope(), sms_spectrum(), SMS_STOC_APPROX, SMS_STOC_IFFT, SMS_STOC_NONE, sms_stocAnalysis(), SMS_WIN_HAMMING, SMS_AnalParams::soundBuffer, SMS_AnalParams::specEnvParams, and SMS_AnalParams::synthBuffer.

Here is the call graph for this function:

void sms_analyzeFrame ( int  iCurrentFrame,
SMS_AnalParams pAnalParams,
sfloat  fRefFundamental 
)

compute spectrum, find peaks, and fundamental of one frame

This is the main core of analysis calls

Parameters:
iCurrentFrame frame number to be computed
pAnalParams structure of analysis parameters
fRefFundamental reference fundamental

References SMS_AnalParams::iFormat, SMS_AnalFrame::iFrameSample, SMS_AnalFrame::iFrameSize, SMS_SndBuffer::iMarker, SMS_AnalParams::iWindowType, SMS_AnalFrame::nPeaks, SMS_AnalParams::peakParams, SMS_SndBuffer::pFBuffer, SMS_AnalParams::ppFrames, SMS_AnalFrame::pSpectralPeaks, sfloat, sms_arrayMagToDB(), sms_detectPeaks(), SMS_FORMAT_H, SMS_FORMAT_HP, sms_getWindow(), sms_harmDetection(), SMS_MAX_SPEC, sms_power2(), sms_scaleWindow(), sms_spectrum(), and SMS_AnalParams::soundBuffer.

Referenced by ReAnalyzeFrame(), and sms_analyze().

Here is the call graph for this function:

int sms_changeSynthHop ( SMS_SynthParams pSynthParams,
int  sizeHop 
)
void sms_cleanTracks ( int  iCurrentFrame,
SMS_AnalParams pAnalParams 
)
void sms_clearFrame ( SMS_Data pSmsFrame  ) 

clear the SMS data structure

Parameters:
pSmsFrame pointer to frame of SMS data

References SMS_Data::pSmsData, and SMS_Data::sizeData.

Referenced by sms_analyze().

void sms_clearSinc ( void   ) 

clear sine table

References sms_tab_sinc.

Referenced by sms_free().

void sms_clearSine ( void   ) 

clear sine table

References sms_tab_sine.

Referenced by sms_free().

void sms_closeSF (  ) 

close a sound file that was open for reading

References pSNDStream.

void sms_copyFrame ( SMS_Data pCopySmsData,
SMS_Data pOriginalSmsData 
)
int sms_createDebugFile ( SMS_AnalParams pAnalParams  ) 

function to create the debug file

Parameters:
pAnalParams pointer to analysis params
Returns:
error value
See also:
SMS_ERRORS

References pChDebugFile, pDebug, SMS_OK, and SMS_WRERR.

int sms_createResSF ( int  iSamplingRate  ) 

function to create the residual sound file

Parameters:
iSamplingRate samplerate of sound file
Returns:
error code
See also:
SMS_SNDERR in SMS_ERRORS

References pChResidualFile, pResidualSNDStream, sfResidualHeader, and sms_error().

Here is the call graph for this function:

int sms_createSF ( char *  pChOutputSoundFile,
int  iSamplingRate,
int  iType 
)

function to create an output sound file

Parameters:
pChOutputSoundFile name of output file
iSamplingRate sampling rate of synthesis
iType output file format (0 is wav, 1 is aiff, or other is libsndfile specific)
Returns:
0 on success, -1 on failure

References pOutputSNDStream, sfOutputSoundHeader, and sms_error().

Here is the call graph for this function:

void sms_dCepstrum ( int  sizeCepstrum,
sfloat *  pCepstrum,
int  sizeFreq,
float *  pFreq,
float *  pMag,
sfloat  fLambda,
int  iSamplingRate 
)
void sms_dCepstrumEnvelope ( int  sizeCepstrum,
sfloat *  pCepstrum,
int  sizeEnv,
float *  pEnv 
)
sfloat sms_deEmphasis ( float  fInput  ) 
int sms_detectPeaks ( int  sizeSpec,
sfloat *  pFMag,
float *  pPhase,
SMS_Peak pSpectralPeaks,
SMS_PeakParams pPeakParams 
)
void sms_error ( char *  pErrorMessage  ) 
int sms_errorCheck ( void   ) 

check if an error has been reported

Returns:
-1 if there is an error, 0 if ok

References error_status.

Referenced by sms_analyze().

char* sms_errorString ( void   ) 

get a string containing information about the last error

Returns:
pointer to a char string, or NULL if no error

References error_message, and error_status.

Referenced by sms_analyze().

void sms_fft ( int  sizeFft,
sfloat *  pArray 
)

Forward Fast Fourier Transform.

function to call the OOURA routines to calculate the forward FFT. Operation is in place.

Todo:
if sizeFft != power of 2, there is a silent crash.. cuidado!
Parameters:
sizeFft size of the FFT in samples (must be a power of 2 >= 2)
pArray pointer to real array (n >= 2, n = power of 2)

References ip, rdft(), and w.

Referenced by sms_dCepstrumEnvelope(), sms_spectrum(), and sms_spectrumMag().

Here is the call graph for this function:

void sms_fillHeader ( SMS_Header pSmsHeader,
SMS_AnalParams pAnalParams,
char *  pProgramString 
)

fill an SMS header with necessary information for storage

copies parameters from SMS_AnalParams, along with other values so an SMS file can be stored and correctly synthesized at a later time. This is somewhat of a convenience function.

sms_initAnal() should be done first to properly set everything.

Parameters:
pSmsHeader header for SMS file (to be stored)
pAnalParams structure of analysis parameters
pProgramString pointer to a string containing the name of the program that made the analysis data

References SMS_AnalParams::fDefaultFundamental, SMS_AnalParams::fFreqDeviation, SMS_AnalParams::fFundContToGuide, SMS_AnalParams::fHighestFreq, SMS_AnalParams::fHighestFundamental, SMS_AnalParams::fLowestFundamental, SMS_AnalParams::fMinPeakMag, SMS_AnalParams::fMinRefHarmMag, SMS_AnalParams::fPeakContToGuide, SMS_AnalParams::fRefHarmMagDiffFromMax, SMS_AnalParams::fSizeWindow, SMS_AnalParams::iAnalysisDirection, SMS_AnalParams::iCleanTracks, SMS_Header::iEnvType, SMS_AnalParams::iFormat, SMS_Header::iFormat, SMS_Header::iFrameBSize, SMS_AnalParams::iFrameRate, SMS_Header::iFrameRate, SMS_Header::iMaxFreq, SMS_AnalParams::iMaxSleepingTime, SMS_AnalParams::iMinTrackLength, SMS_AnalParams::iRefHarmonic, SMS_AnalParams::iSamplingRate, SMS_Header::iSamplingRate, SMS_AnalParams::iSoundType, SMS_AnalParams::iStochasticType, SMS_Header::iStochasticType, SMS_SEnvParams::iType, SMS_AnalParams::iWindowType, SMS_SEnvParams::nCoeff, SMS_Header::nEnvCoeff, SMS_AnalParams::nFrames, SMS_Header::nFrames, SMS_AnalParams::nGuides, SMS_AnalParams::nStochasticCoeff, SMS_Header::nStochasticCoeff, SMS_Header::nTextCharacters, SMS_AnalParams::nTracks, SMS_Header::nTracks, SMS_Header::pChTextCharacters, pChTextString, sms_frameSizeB(), sms_initHeader(), SMS_STOC_NONE, and SMS_AnalParams::specEnvParams.

Here is the call graph for this function:

void sms_fillSoundBuffer ( int  sizeWaveform,
sfloat *  pWaveform,
SMS_AnalParams pAnalParams 
)

fill the sound buffer

Parameters:
sizeWaveform size of input data
pWaveform input data
pAnalParams pointer to structure of analysis parameters

References SMS_AnalParams::iAnalysisDirection, SMS_SndBuffer::iFirstGood, SMS_SndBuffer::iMarker, MAX, SMS_SndBuffer::pFBuffer, sfloat, SMS_SndBuffer::sizeBuffer, SMS_DIR_REV, sms_preEmphasis(), and SMS_AnalParams::soundBuffer.

Referenced by sms_analyze().

Here is the call graph for this function:

void sms_filterHighPass ( int  sizeResidual,
sfloat *  pResidual,
int  iSamplingRate 
)

function to filter a waveform with a high-pass filter

cutoff =1500 Hz

Todo:
this filter only works on sample rates up to 48k?
Parameters:
sizeResidual size of signal
pResidual pointer to residual signal
iSamplingRate sampling rate of signal

References sfloat, and ZeroPoleFilter().

Referenced by sms_analyze().

Here is the call graph for this function:

int sms_frameSizeB ( SMS_Header pSmsHeader  ) 

get the size in bytes of the frame in a SMS file

Parameters:
pSmsHeader pointer to SMS header
Returns:
the size in bytes of the frame

References SMS_Header::iFormat, SMS_Header::iStochasticType, SMS_Header::nEnvCoeff, SMS_Header::nStochasticCoeff, SMS_Header::nTracks, sfloat, SMS_FORMAT_H, SMS_FORMAT_IH, SMS_STOC_APPROX, and SMS_STOC_IFFT.

Referenced by sms_fillHeader().

void sms_free ( void   ) 

free global data

deallocates memory allocated to global arrays (windows and tables)

References initIsDone, sms_clearSinc(), and sms_clearSine().

Here is the call graph for this function:

void sms_freeAnalysis ( SMS_AnalParams pAnalParams  ) 

free analysis data

frees all the memory allocated to an SMS_AnalParams by sms_initAnalysis

Parameters:
pAnalParams pointer to analysis data structure

References SMS_AnalFrame::deterministic, SMS_AnalParams::iMaxDelayFrames, SMS_SndBuffer::pFBuffer, SMS_AnalParams::pFrames, SMS_AnalParams::ppFrames, SMS_AnalParams::prevFrame, sms_freeFrame(), SMS_AnalParams::soundBuffer, and SMS_AnalParams::synthBuffer.

Here is the call graph for this function:

void sms_freeFrame ( SMS_Data pSmsFrame  ) 

free the SMS data structure

Parameters:
pSmsFrame pointer to frame of SMS data

References SMS_Data::nCoeff, SMS_Data::nTracks, SMS_Data::pFSinAmp, SMS_Data::pFSinFreq, SMS_Data::pFStocCoeff, SMS_Data::pFStocGain, SMS_Data::pResPhase, SMS_Data::pSmsData, and SMS_Data::sizeData.

Referenced by sms_freeAnalysis(), and sms_freeSynth().

void sms_freeModify ( SMS_ModifyParams params  ) 

free memory allocated during initialization

Parameters:
params pointer to parameter structure
void sms_freeSynth ( SMS_SynthParams pSynthParams  ) 

free analysis data

frees all the memory allocated to an SMS_SynthParams by sms_initSynthesis

Todo:
is there a way to make sure the plan has been made already? as it is, it crashes if this is called without one
Parameters:
pSynthParams pointer to synthesis data structure

References SMS_SynthParams::pFDetWindow, SMS_SynthParams::pFStocWindow, SMS_SynthParams::pMagBuff, SMS_SynthParams::pPhaseBuff, SMS_SynthParams::prevFrame, SMS_SynthParams::pSpectra, SMS_SynthParams::pSynthBuff, and sms_freeFrame().

Here is the call graph for this function:

sfloat sms_fundDeviation ( SMS_AnalParams pAnalParams,
int  iCurrentFrame 
)

get deviation from average fundamental \

Parameters:
pAnalParams pointer to analysis params
iCurrentFrame number of current frame
Returns:
deviation value or -1 if really off

References SMS_AnalFrame::fFundamental, SMS_AnalParams::ppFrames, sfloat, and SMS_MIN_GOOD_FRAMES.

Referenced by ReAnalyzeFrame(), and sms_analyze().

int sms_getFrame ( FILE *  pSmsFile,
SMS_Header pSmsHeader,
int  iFrame,
SMS_Data pSmsFrame 
)

read an SMS data frame

Parameters:
pSmsFile pointer to SMS file
pSmsHeader pointer to SMS header
iFrame frame number
pSmsFrame pointer to SMS frame
Returns:
0 on sucess, -1 on error

References SMS_Header::iFrameBSize, SMS_Header::iHeadBSize, SMS_Data::pSmsData, and sms_error().

Here is the call graph for this function:

int sms_getHeader ( char *  pChFileName,
SMS_Header **  ppSmsHeader,
FILE **  ppSmsFile 
)

function to read SMS header

Parameters:
pChFileName file name for SMS file
ppSmsHeader (double pointer to) SMS header
ppSmsFile (double pointer to) inputfile
Returns:
error code
See also:
SMS_ERRORS

References sms_error(), and SMS_MAGIC.

Here is the call graph for this function:

int sms_getSound ( SMS_SndHeader pSoundHeader,
long  sizeSound,
sfloat *  pSound,
long  offset 
)

get a chunk of sound from input file

This function will copy to samples from the channel specified by SMS_SndHeader->iReadChannel to an array, which is by default the first channel.

Parameters:
pSoundHeader sound header information to hold extracted information
sizeSound number of samples read
pSound buffer for samples read
offset which sound frame to start reading from
Returns:
0 on success, -1 on failure

References SMS_SndHeader::channelCount, SMS_SndHeader::iReadChannel, MAX_SAMPLES, pSNDStream, sfloat, sms_error(), and SMS_MALLOC.

Here is the call graph for this function:

void sms_getWindow ( int  sizeWindow,
sfloat *  pFWindow,
int  iWindowType 
)

main function for getting various windows

Todo:
note on window scales
See also:
SMS_WINDOWS for the different window types available
Parameters:
sizeWindow window size
pFWindow window array
iWindowType the desired window type defined by SMS_WINDOWS

References BlackmanHarris(), BlackmanHarris62(), BlackmanHarris70(), BlackmanHarris74(), BlackmanHarris92(), Hamming(), Hanning(), IFFTwindow(), SMS_WIN_BH_62, SMS_WIN_BH_70, SMS_WIN_BH_74, SMS_WIN_BH_92, SMS_WIN_HAMMING, SMS_WIN_HANNING, and SMS_WIN_IFFT.

Referenced by InitializeHybrid(), sms_analyze(), sms_analyzeFrame(), sms_changeSynthHop(), and sms_initSynth().

Here is the call graph for this function:

void sms_harmDetection ( SMS_AnalFrame pFrame,
sfloat  fRefFundamental,
SMS_PeakParams pPeakParams 
)

main harmonic detection function

find a given harmonic peak from a set of spectral peaks, put the frequency of the fundamental in the current frame

Parameters:
pFrame pointer to current frame
fRefFundamental frequency of previous frame
pPeakParams pointer to analysis parameters
Todo:

is it possible to use pSpectralPeaks instead of SMS_AnalFrame?

move pCHarmonic array to SMS_AnalFrame structure

  • this will allow for analysis of effectiveness from outside this file This really should only be for sms_analyzeFrame

<

Bug:
sfloat comparison to zero

References SMS_HarmCandidate::fFreq, SMS_Peak::fFreq, SMS_AnalFrame::fFundamental, SMS_PeakParams::fHighestFundamental, SMS_PeakParams::fLowestFreq, SMS_Peak::fMag, GetBestCandidate(), GoodCandidate(), SMS_PeakParams::iRefHarmonic, N_HARM_PEAKS, SMS_AnalFrame::pSpectralPeaks, and sfloat.

Referenced by sms_analyzeFrame().

Here is the call graph for this function:

void sms_ifft ( int  sizeFft,
sfloat *  pArray 
)

Inverse Forward Fast Fourier Transform.

function to call the OOURA routines to calculate the Inverse FFT. Operation is in place.

Parameters:
sizeFft size of the FFT in samples (must be a power of 2 >= 2)
pArray pointer to real array (n >= 2, n = power of 2)

References ip, rdft(), and w.

Referenced by SineSynthIFFT(), sms_invQuickSpectrumW(), sms_invSpectrum(), and sms_synthesize().

Here is the call graph for this function:

int sms_init ( void   ) 

initialize global data

Currently, just generating the sine and sinc tables. This is necessary before both analysis and synthesis.

If using the Mersenne Twister algorithm for random number generation, initialize (seed) it.

Returns:
error code
See also:
SMS_MALLOC or SMS_OK in SMS_ERRORS

References init_gen_rand(), initIsDone, SIZE_TABLES, sms_error(), sms_prepSinc(), and sms_prepSine().

Here is the call graph for this function:

void sms_initAnalParams ( SMS_AnalParams pAnalParams  ) 

give default values to an SMS_AnalParams struct

This will initialize an SMS_AnalParams with values that work for common analyses. It is useful to start with and then adjust the parameters manually to fit a particular sound

Certain things are hard coded in here that will have to be updated later (i.e. samplerate), so it is best to call this function first, then fill whatever parameters need to be adjusted.

Parameters:
pAnalParams pointer to analysis data structure

< depends on iFrameRate normally

< depends on iFrameRate normally

< no sound yet

< no frames yet

References SMS_AnalParams::fDefaultFundamental, SMS_AnalParams::fFreqDeviation, SMS_AnalParams::fFundContToGuide, SMS_AnalParams::fHighestFreq, SMS_AnalParams::fHighestFundamental, SMS_SEnvParams::fLambda, SMS_AnalParams::fLowestFundamental, SMS_AnalParams::fMinPeakMag, SMS_AnalParams::fMinRefHarmMag, SMS_AnalParams::fPeakContToGuide, SMS_AnalParams::fRefHarmMagDiffFromMax, SMS_AnalParams::fResidualAccumPerc, SMS_AnalParams::fSizeWindow, SMS_AnalParams::iAnalysisDirection, SMS_SEnvParams::iAnchor, SMS_AnalParams::iCleanTracks, SMS_AnalParams::iDebugMode, SMS_AnalParams::iDefaultSizeWindow, SMS_AnalParams::iFormat, SMS_AnalParams::iFrameRate, SMS_AnalParams::iMaxDelayFrames, SMS_SEnvParams::iMaxFreq, SMS_AnalParams::iMaxSleepingTime, SMS_AnalParams::iMinTrackLength, SMS_SEnvParams::iOrder, SMS_AnalParams::iRefHarmonic, SMS_AnalParams::iSamplingRate, SMS_AnalParams::iSizeSound, SMS_AnalParams::iSoundType, SMS_AnalParams::iStochasticType, SMS_SEnvParams::iType, SMS_AnalParams::iWindowType, MAX, SMS_SEnvParams::nCoeff, SMS_AnalParams::nFrames, SMS_AnalParams::nGuides, SMS_AnalParams::nStochasticCoeff, SMS_AnalParams::nTracks, SMS_AnalParams::sizeHop, SMS_DELAY_FRAMES, SMS_DIR_FWD, SMS_ENV_NONE, SMS_FORMAT_H, SMS_SOUND_TYPE_MELODY, SMS_STOC_APPROX, SMS_WIN_BH_70, and SMS_AnalParams::specEnvParams.

int sms_initAnalysis ( SMS_AnalParams pAnalParams,
SMS_SndHeader pSoundHeader 
)

initialize analysis data structure's arrays

based on the SMS_AnalParams current settings, this function will initialize the sound, synth, and fft arrays. It is necessary before analysis. there can be multple SMS_AnalParams at the same time

Parameters:
pAnalParams pointer to analysis paramaters
pSoundHeader pointer to sound header
Returns:
0 on success, -1 on error

References SMS_AnalFrame::deterministic, SMS_AnalParams::fDefaultFundamental, SMS_PeakParams::fHighestFreq, SMS_AnalParams::fHighestFreq, SMS_PeakParams::fHighestFundamental, SMS_AnalParams::fHighestFundamental, SMS_PeakParams::fLowestFreq, SMS_AnalParams::fLowestFundamental, SMS_AnalParams::fMinPeakMag, SMS_PeakParams::fMinPeakMag, SMS_AnalParams::fMinRefHarmMag, SMS_PeakParams::fMinRefHarmMag, SMS_AnalParams::fRefHarmMagDiffFromMax, SMS_PeakParams::fRefHarmMagDiffFromMax, SMS_AnalParams::fSizeWindow, SMS_AnalParams::iDefaultSizeWindow, SMS_SndBuffer::iFirstGood, SMS_AnalParams::iFrameRate, SMS_SndBuffer::iMarker, SMS_AnalParams::iMaxDelayFrames, SMS_SEnvParams::iMaxFreq, SMS_PeakParams::iMaxPeaks, SMS_SEnvParams::iOrder, SMS_AnalParams::iRefHarmonic, SMS_PeakParams::iRefHarmonic, SMS_PeakParams::iSamplingRate, SMS_AnalParams::iSamplingRate, SMS_SndHeader::iSamplingRate, SMS_AnalParams::iSizeSound, SMS_AnalParams::iSoundType, SMS_PeakParams::iSoundType, SMS_AnalFrame::iStatus, SMS_AnalParams::iStochasticType, SMS_SEnvParams::iType, SMS_SEnvParams::nCoeff, SMS_AnalParams::nFrames, SMS_AnalParams::nGuides, SMS_SndHeader::nSamples, SMS_AnalParams::nStochasticCoeff, SMS_AnalParams::peakParams, SMS_SndBuffer::pFBuffer, SMS_AnalParams::pFrames, SMS_AnalParams::ppFrames, SMS_AnalParams::prevFrame, sfloat, SMS_SndBuffer::sizeBuffer, SMS_AnalParams::sizeHop, SMS_AnalParams::sizeNextRead, sms_allocFrame(), SMS_ENV_CEP, SMS_ENV_FBINS, sms_error(), SMS_FRAME_EMPTY, SMS_MAX_NPEAKS, SMS_MAX_WINDOW, sms_power2(), SMS_STOC_IFFT, SMS_AnalParams::soundBuffer, SMS_AnalParams::specEnvParams, and SMS_AnalParams::synthBuffer.

Here is the call graph for this function:

int sms_initFrame ( int  iCurrentFrame,
SMS_AnalParams pAnalParams,
int  sizeWindow 
)

initialize the current frame

initializes arrays to zero and sets the correct sample position. Special care is taken at the end the sample source (if there is not enough samples for an entire frame.

Parameters:
iCurrentFrame frame number of current frame in buffer
pAnalParams analysis parameters
sizeWindow size of analysis window
Returns:
-1 on error
Todo:
make this return void

References SMS_AnalFrame::deterministic, SMS_AnalFrame::fFundamental, SMS_AnalFrame::iFrameNum, SMS_AnalFrame::iFrameSample, SMS_AnalFrame::iFrameSize, SMS_SndBuffer::iMarker, SMS_AnalParams::iSizeSound, SMS_AnalFrame::iStatus, SMS_AnalParams::nGuides, SMS_AnalFrame::nPeaks, SMS_Data::pFSinAmp, SMS_Data::pFSinFreq, SMS_Data::pFSinPha, SMS_AnalParams::ppFrames, SMS_AnalFrame::pSpectralPeaks, sfloat, SMS_AnalParams::sizeHop, sms_error(), SMS_FRAME_END, SMS_FRAME_READY, SMS_MAX_NPEAKS, SMS_OK, and SMS_AnalParams::soundBuffer.

Referenced by sms_analyze().

Here is the call graph for this function:

void sms_initHeader ( SMS_Header pSmsHeader  ) 
void sms_initModify ( SMS_Header header,
SMS_ModifyParams params 
)

initialize a modifications structure based on an SMS_Header

Parameters:
params pointer to parameter structure
header pointer to sms header

References SMS_Header::iMaxFreq, SMS_ModifyParams::maxFreq, SMS_Header::nEnvCoeff, SMS_ModifyParams::ready, sfloat, SMS_ModifyParams::sinEnv, SMS_ModifyParams::sizeSinEnv, and sms_error().

Here is the call graph for this function:

void sms_initModifyParams ( SMS_ModifyParams params  ) 
int sms_initSynth ( SMS_Header pSmsHeader,
SMS_SynthParams pSynthParams 
)

initialize synthesis data structure's arrays

Initialize the synthesis and fft arrays. It is necessary before synthesis. there can be multple SMS_SynthParams at the same time This function also sets some initial values that will create a sane synthesis environment.

This function requires an SMS_Header because it may be called to synthesize a stored .sms file, which contains a header with necessary information.

Parameters:
pSmsHeader pointer to SMS_Header
pSynthParams pointer to synthesis paramaters
Returns:
0 on success, -1 on error

References SMS_Header::iFrameRate, SMS_Header::iMaxFreq, SMS_SynthParams::iOriginalSRate, SMS_SynthParams::iSamplingRate, SMS_Header::iSamplingRate, SMS_Header::iStochasticType, SMS_SynthParams::iStochasticType, SMS_ModifyParams::maxFreq, SMS_SynthParams::modParams, SMS_Header::nEnvCoeff, SMS_Header::nStochasticCoeff, SMS_Header::nTracks, SMS_SynthParams::origSizeHop, SMS_SynthParams::pFDetWindow, SMS_SynthParams::pFStocWindow, SMS_SynthParams::pMagBuff, SMS_SynthParams::pPhaseBuff, SMS_SynthParams::prevFrame, SMS_SynthParams::pSpectra, SMS_SynthParams::pSynthBuff, sfloat, SMS_SynthParams::sizeHop, sms_allocFrame(), sms_error(), sms_getWindow(), SMS_OK, sms_power2(), SMS_WIN_HANNING, and SMS_WIN_IFFT.

Here is the call graph for this function:

void sms_initSynthParams ( SMS_SynthParams synthParams  ) 

give default values to an SMS_SynthParams struct

This will initialize an SMS_SynthParams with values that work for common analyses. It is useful to start with and then adjust the parameters manually to fit a particular sound

Parameters:
synthParams pointer to synthesis parameters data structure

References SMS_SynthParams::iDetSynthType, SMS_SynthParams::iSamplingRate, SMS_SynthParams::iSynthesisType, SMS_SynthParams::modParams, SMS_SynthParams::sizeHop, SMS_DET_IFFT, sms_initModifyParams(), SMS_MIN_SIZE_FRAME, and SMS_STYPE_ALL.

Here is the call graph for this function:

void sms_interpolateFrames ( SMS_Data pSmsFrame1,
SMS_Data pSmsFrame2,
SMS_Data pSmsFrameOut,
sfloat  fInterpFactor 
)

function to interpolate two SMS frames

this assumes that the two frames are of the same size

Parameters:
pSmsFrame1 sms frame 1
pSmsFrame2 sms frame 2
pSmsFrameOut sms output frame
fInterpFactor interpolation factor

Todo:
how to interpolate residual phase spectrum

References SMS_Data::nCoeff, SMS_Data::nEnvCoeff, SMS_Data::nTracks, SMS_Data::pFSinAmp, SMS_Data::pFSinFreq, SMS_Data::pFStocCoeff, SMS_Data::pFStocGain, SMS_Data::pSpecEnv, and sfloat.

int sms_invQuickSpectrumW ( sfloat *  pFMagSpectrum,
float *  pFPhaseSpectrum,
int  sizeFft,
sfloat *  pFWaveform,
int  sizeWave,
sfloat *  pFWindow 
)

Referenced by StocSynthApprox().

int sms_invSpectrum ( int  sizeWaveform,
sfloat *  pWaveform,
float *  pWindow,
int  sizeMag,
sfloat *  pMag,
float *  pPhase 
)
void sms_modify ( SMS_Data frame,
SMS_ModifyParams params 
)
int sms_openSF ( char *  pChInputSoundFile,
SMS_SndHeader pSoundHeader 
)

open a sound file and check its header

Defualt channel to read is 1. If the user wishes to read from a different channel when calling sms_getSound, they need to set SMS_SndHeader->iReadChannel to the desired channel number.

Parameters:
pChInputSoundFile name of soundfile
pSoundHeader information of the sound
Returns:
0 on success, -1 on failure

References SMS_SndHeader::channelCount, SMS_SndHeader::iReadChannel, SMS_SndHeader::iSamplingRate, SMS_SndHeader::nSamples, pSNDStream, sfSoundHeader, SMS_SndHeader::sizeHeader, and sms_error().

Here is the call graph for this function:

int sms_peakContinuation ( int  iFrame,
SMS_AnalParams pAnalParams 
)
void sms_PolarToRect ( int  sizeSpec,
sfloat *  pReal,
float *  pMag,
float *  pPhase 
)

Referenced by sms_invSpectrum(), and sms_stochastic().

sfloat sms_preEmphasis ( float  fInput  ) 

References sfloat, and SMS_EMPH_COEF.

Referenced by sms_fillSoundBuffer().

int sms_prepSinc ( int  nTableSize  ) 

prepare the Sinc table

used for the main lobe of a frequency domain BlackmanHarris92 window

Parameters:
nTableSize size of table
Returns:
error code
See also:
SMS_MALLOC in SMS_ERRORS

References fSincScale, sfloat, Sinc(), SMS_MALLOC, SMS_OK, sms_tab_sinc, and TWO_PI.

Referenced by sms_init().

Here is the call graph for this function:

int sms_prepSine ( int  nTableSize  ) 

prepares the sine table

Parameters:
nTableSize size of table
Returns:
error code
See also:
SMS_MALLOC in SMS_ERRORS

References fSineIncr, fSineScale, sfloat, SMS_MALLOC, SMS_OK, sms_tab_sine, and TWO_PI.

Referenced by sms_init().

void sms_RectToPolar ( int  sizeSpec,
sfloat *  pReal,
float *  pMag,
float *  pPhase 
)
int sms_residual ( int  sizeWindow,
sfloat *  pSynthesis,
float *  pOriginal,
float *  pResidual,
float *  pWindow 
)
void sms_scaleDet ( sfloat *  pSynthBuffer,
float *  pOriginalBuffer,
sfloat *  pSinAmp,
SMS_AnalParams pAnalParams,
int  nTracks 
)
void sms_scaleWindow ( int  sizeWindow,
sfloat *  pWindow 
)

References sfloat.

Referenced by sms_analyze(), and sms_analyzeFrame().

void sms_sineSynthFrame ( SMS_Data pSmsData,
sfloat *  pFBuffer,
int  sizeBuffer,
SMS_Data pLastFrame,
int  iSamplingRate 
)

generate all the sinusoids for a given frame

Parameters:
pSmsData SMS data for current frame
pFBuffer pointer to output waveform
sizeBuffer size of the synthesis buffer
pLastFrame SMS data from last frame
iSamplingRate sampling rate to synthesize for

References SMS_Data::nTracks, SMS_Data::pFSinAmp, SMS_Data::pFSinFreq, SMS_Data::pFSinPha, sfloat, SinePhaSynth(), SineSynth(), and TWO_PI.

Referenced by sms_analyze(), and sms_synthesize().

Here is the call graph for this function:

int sms_sizeNextWindow ( int  iCurrentFrame,
SMS_AnalParams pAnalParams 
)

set window size for next frame

adjusts the next window size to fit the currently detected fundamental frequency, or resets to a default window size if unstable.

Parameters:
iCurrentFrame number of current frame
pAnalParams analysis parameters
Returns:
the size of the next window in samples

References SMS_AnalFrame::fFundamental, SMS_AnalParams::fSizeWindow, SMS_AnalParams::iDefaultSizeWindow, SMS_AnalParams::iSamplingRate, SMS_AnalParams::ppFrames, sfloat, and SMS_MAX_WINDOW.

Referenced by sms_analyze().

int sms_spectralApprox ( sfloat *  pFSpec1,
int  sizeSpec1,
int  sizeSpec1Used,
sfloat *  pFSpec2,
int  sizeSpec2,
int  nCoefficients 
)

approximate a magnitude spectrum First downsampling using local maxima and then upsampling using linear interpolation. The output spectrum doesn't have to be the same size as the input one.

Parameters:
pFSpec1 magnitude spectrum to approximate
sizeSpec1 size of input spectrum
sizeSpec1Used size of the spectrum to use
pFSpec2 output envelope
sizeSpec2 size of output envelope
nCoefficients number of coefficients to use in approximation
Returns:
error code
See also:
SMS_ERRORS (or -1 if the algorithm just messes up, it will print an error of its own.

References MAX, MIN, sfloat, sms_error(), SMS_MALLOC, and SMS_OK.

Referenced by InterpolateArrays(), sms_hybridize(), sms_stocAnalysis(), sms_stochastic(), and StocSynthApprox().

Here is the call graph for this function:

void sms_spectralEnvelope ( SMS_Data pSmsData,
SMS_SEnvParams pSpecEnvParams 
)

main function for computing spectral envelope from sinusoidal peaks

Magnitudes should already be in linear for this function. If pSmsData->iEnvelope == SMS_ENV_CEP, will return cepstrum coefficeints If pSmsData->iEnvelope == SMS_ENV_FBINS, will return linear magnitude spectrum

Parameters:
pSmsData pointer to SMS_Data structure with all the arrays necessary
pSpecEnvParams pointer to a structure of parameters for spectral enveloping

References SMS_SEnvParams::fLambda, SMS_SEnvParams::iAnchor, SMS_SEnvParams::iMaxFreq, SMS_SEnvParams::iOrder, SMS_SEnvParams::iType, SMS_SEnvParams::nCoeff, SMS_Data::nEnvCoeff, SMS_Data::nTracks, SMS_Data::pFSinAmp, SMS_Data::pFSinFreq, SMS_Data::pSpecEnv, sfloat, sms_dCepstrum(), sms_dCepstrumEnvelope(), SMS_ENV_FBINS, and sms_error().

Referenced by sms_analyze().

Here is the call graph for this function:

int sms_spectrum ( int  sizeWindow,
sfloat *  pWaveform,
float *  pWindow,
int  sizeMag,
sfloat *  pMag,
float *  pPhase 
)

Referenced by sms_analyze(), and sms_analyzeFrame().

int sms_spectrumMag ( int  sizeWindow,
sfloat *  pWaveform,
float *  pWindow,
int  sizeMag,
sfloat *  pMag 
)

Referenced by sms_stocAnalysis().

void sms_spectrumRMS ( int  sizeMag,
sfloat *  pReal,
float *  pMag 
)
int sms_stocAnalysis ( int  sizeWindow,
sfloat *  pResidual,
float *  pWindow,
SMS_Data pSmsFrame 
)

Referenced by sms_analyze().

void sms_synthesize ( SMS_Data pSmsData,
sfloat *  pFSynthesis,
SMS_SynthParams pSynthParams 
)

synthesizes one frame of SMS data

Parameters:
pSmsData input SMS data
pFSynthesis output sound buffer
pSynthParams synthesis parameters

<

Todo:
use a comb filter of harmonics to better combine the signal here

References SMS_SynthParams::iDetSynthType, SMS_SynthParams::iSamplingRate, SMS_SynthParams::iStochasticType, SMS_SynthParams::iSynthesisType, SMS_SynthParams::pFDetWindow, SMS_SynthParams::prevFrame, SMS_SynthParams::pSpectra, SMS_SynthParams::pSynthBuff, sfloat, SineSynthIFFT(), SMS_SynthParams::sizeHop, sms_deEmphasis(), SMS_DET_IFFT, sms_deterministic(), sms_ifft(), sms_sineSynthFrame(), SMS_STOC_IFFT, SMS_STYPE_ALL, SMS_STYPE_DET, and StocSynthApprox().

Here is the call graph for this function:

void sms_windowCentered ( int  sizeWindow,
sfloat *  pWaveform,
float *  pWindow,
int  sizeFft,
float *  pFftBuffer 
)

Referenced by sms_spectrum().

void sms_writeDebugData ( sfloat *  pBuffer1,
float *  pBuffer2,
sfloat *  pBuffer3,
int  sizeBuffer 
)
void sms_writeDebugFile ( void   ) 

function to write the residual sound file to disk

writes the "debug.txt" file to disk and closes the file.

References pDebug.

int sms_writeFile ( FILE *  pSmsFile,
SMS_Header pSmsHeader 
)

rewrite SMS header and close file

Parameters:
pSmsFile pointer to SMS file
pSmsHeader pointer to header for SMS file
Returns:
error code
See also:
SMS_WRERR in SMS_ERRORS

References SMS_Header::iHeadBSize, SMS_Header::nTextCharacters, and sms_error().

Here is the call graph for this function:

int sms_writeFrame ( FILE *  pSmsFile,
SMS_Header pSmsHeader,
SMS_Data pSmsFrame 
)

write SMS frame

Parameters:
pSmsFile pointer to SMS file
pSmsHeader pointer to SMS header
pSmsFrame pointer to SMS data frame
Returns:
0 on success, -1 on failure

References SMS_Header::iFrameBSize, SMS_Data::pSmsData, and sms_error().

Here is the call graph for this function:

int sms_writeHeader ( char *  pChFileName,
SMS_Header pSmsHeader,
FILE **  ppSmsFile 
)

write SMS header to file

Parameters:
pChFileName file name for SMS file
pSmsHeader header for SMS file
ppSmsFile (double pointer to) file to be created
Returns:
error code
See also:
SMS_WRERR in SMS_ERRORS

References SMS_Header::iHeadBSize, SMS_Header::iSmsMagic, SMS_Header::nTextCharacters, sms_error(), and SMS_MAGIC.

Here is the call graph for this function:

void sms_writeResSF ( void   ) 

write the residual sound file to disk

References pOutputSNDStream.

int sms_writeResSound ( sfloat *  pBuffer,
int  sizeBuffer 
)

function to write to the residual sound file

Parameters:
pBuffer data to write to residual file
sizeBuffer size of data buffer
Returns:
error code
See also:
SMS_SNDERR in SMS_ERRORS

References pResidualSNDStream, sfloat, sms_deEmphasis(), SMS_MALLOC, and SMS_OK.

Here is the call graph for this function:

void sms_writeSF ( void   ) 

function to write the output sound file to disk

References pOutputSNDStream.

void sms_writeSound ( sfloat *  pFBuffer,
int  sizeBuffer 
)

write to the sound file data

Parameters:
pFBuffer data to write to file
sizeBuffer size of data buffer

References pOutputSNDStream.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Thu Oct 29 04:08:07 2009 for libsms by  doxygen 1.6.1