initialization, free, and debug functions More...
#include "sms.h"
#include "SFMT.h"
Defines | |
#define | SIZE_TABLES 4096 |
#define | HALF_MAX 1073741823.5 |
#define | INV_HALF_MAX (1.0 / HALF_MAX) |
#define | TWENTY_OVER_LOG10 (20. / LOG10) |
Functions | |
int | sms_init (void) |
initialize global data | |
void | sms_free (void) |
free global data | |
void | sms_initAnalParams (SMS_AnalParams *pAnalParams) |
give default values to an SMS_AnalParams struct | |
int | sms_initAnalysis (SMS_AnalParams *pAnalParams, SMS_SndHeader *pSoundHeader) |
initialize analysis data structure's arrays | |
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 | |
int | sms_sizeNextWindow (int iCurrentFrame, SMS_AnalParams *pAnalParams) |
set window size for next frame | |
int | sms_initFrame (int iCurrentFrame, SMS_AnalParams *pAnalParams, int sizeWindow) |
initialize the current frame | |
sfloat | sms_fundDeviation (SMS_AnalParams *pAnalParams, int iCurrentFrame) |
get deviation from average fundamental \ | |
int | sms_createDebugFile (SMS_AnalParams *pAnalParams) |
function to create the debug file | |
void | sms_writeDebugData (sfloat *pFBuffer1, sfloat *pFBuffer2, sfloat *pFBuffer3, int sizeBuffer) |
function to write to the debug file | |
void | sms_writeDebugFile () |
function to write the residual sound file to disk | |
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 | |
void | sms_error (char *pErrorMessage) |
get a string containing information about the error code | |
int | sms_errorCheck () |
check if an error has been reported | |
char * | sms_errorString () |
get a string containing information about the last error | |
sfloat | sms_random () |
random number genorator | |
sfloat | sms_rms (int sizeArray, sfloat *pArray) |
Root Mean Squared of an array. | |
int | sms_power2 (int n) |
make sure a number is a power of 2 | |
sfloat | sms_scalarTempered (sfloat x) |
compute a value for scaling frequency based on the well-tempered scale | |
void | sms_arrayScalarTempered (int sizeArray, sfloat *pArray) |
scale an array of linear frequencies to the well-tempered scale | |
Variables | |
char * | pChDebugFile = "debug.txt" |
FILE * | pDebug |
static char | error_message [256] |
static int | error_status = 0 |
static sfloat | mag_thresh = .00001 |
static sfloat | inv_mag_thresh = 100000. |
static int | initIsDone = 0 |
initialization, free, and debug functions
#define HALF_MAX 1073741823.5 |
half the max of a 32-bit word
#define INV_HALF_MAX (1.0 / HALF_MAX) |
Referenced by sms_random().
#define SIZE_TABLES 4096 |
Referenced by sms_init().
#define TWENTY_OVER_LOG10 (20. / LOG10) |
Referenced by sms_magToDB().
int sms_changeSynthHop | ( | SMS_SynthParams * | pSynthParams, | |
int | sizeHop | |||
) |
References SMS_SynthParams::pFDetWindow, SMS_SynthParams::pFStocWindow, SMS_SynthParams::pMagBuff, SMS_SynthParams::pPhaseBuff, SMS_SynthParams::pSpectra, SMS_SynthParams::pSynthBuff, sfloat, SMS_SynthParams::sizeHop, sms_getWindow(), SMS_OK, SMS_WIN_HANNING, and SMS_WIN_IFFT.
int sms_createDebugFile | ( | SMS_AnalParams * | pAnalParams | ) |
function to create the debug file
pAnalParams | pointer to analysis params |
References pChDebugFile, pDebug, SMS_OK, and SMS_WRERR.
void sms_error | ( | char * | pErrorMessage | ) |
get a string containing information about the error code
pErrorMessage | pointer to error message string |
References error_message, and error_status.
Referenced by sms_allocFrame(), sms_analyze(), sms_createResSF(), sms_createSF(), sms_dCepstrumEnvelope(), sms_getFrame(), sms_getHeader(), sms_getSound(), sms_init(), sms_initAnalysis(), sms_initFrame(), sms_initModify(), sms_initSynth(), sms_invSpectrum(), sms_openSF(), sms_spectralApprox(), sms_spectralEnvelope(), sms_spectrum(), sms_spectrumMag(), sms_stocAnalysis(), sms_writeFile(), sms_writeFrame(), and sms_writeHeader().
int sms_errorCheck | ( | void | ) |
check if an error has been reported
References error_status.
Referenced by sms_analyze().
char* sms_errorString | ( | void | ) |
get a string containing information about the last error
References error_message, and error_status.
Referenced by sms_analyze().
void sms_free | ( | void | ) |
free global data
deallocates memory allocated to global arrays (windows and tables)
References initIsDone, sms_clearSinc(), and sms_clearSine().
void sms_freeAnalysis | ( | SMS_AnalParams * | pAnalParams | ) |
free analysis data
frees all the memory allocated to an SMS_AnalParams by sms_initAnalysis
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.
void sms_freeSynth | ( | SMS_SynthParams * | pSynthParams | ) |
free analysis data
frees all the memory allocated to an SMS_SynthParams by sms_initSynthesis
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().
sfloat sms_fundDeviation | ( | SMS_AnalParams * | pAnalParams, | |
int | iCurrentFrame | |||
) |
get deviation from average fundamental \
pAnalParams | pointer to analysis params | |
iCurrentFrame | number of current frame |
References SMS_AnalFrame::fFundamental, SMS_AnalParams::ppFrames, sfloat, and SMS_MIN_GOOD_FRAMES.
Referenced by ReAnalyzeFrame(), and sms_analyze().
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.
References init_gen_rand(), initIsDone, SIZE_TABLES, sms_error(), sms_prepSinc(), and sms_prepSine().
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.
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
pAnalParams | pointer to analysis paramaters | |
pSoundHeader | pointer to sound header |
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.
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.
iCurrentFrame | frame number of current frame in buffer | |
pAnalParams | analysis parameters | |
sizeWindow | size of analysis window |
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().
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.
pSmsHeader | pointer to SMS_Header | |
pSynthParams | pointer to synthesis paramaters |
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.
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
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.
sfloat sms_scalarTempered | ( | sfloat | x | ) |
compute a value for scaling frequency based on the well-tempered scale
x | linear frequency value |
Referenced by sms_arrayScalarTempered(), and sms_transpose().
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.
iCurrentFrame | number of current frame | |
pAnalParams | analysis parameters |
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().
void sms_writeDebugData | ( | sfloat * | pFBuffer1, | |
sfloat * | pFBuffer2, | |||
sfloat * | pFBuffer3, | |||
int | sizeBuffer | |||
) |
function to write to the debug file
writes three arrays of equal size to a debug text file ("./debug.txt"). There are three arrays for the frequency, magnitude, phase sets.
pFBuffer1 | pointer to array 1 | |
pFBuffer2 | pointer to array 2 | |
pFBuffer3 | pointer to array 3 | |
sizeBuffer | the size of the buffers |
References pDebug.
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.
char error_message[256] [static] |
Referenced by sms_error(), and sms_errorString().
int error_status = 0 [static] |
Referenced by sms_error(), sms_errorCheck(), and sms_errorString().
int initIsDone = 0 [static] |
Referenced by sms_free(), and sms_init().
sfloat inv_mag_thresh = 100000. [static] |
inv(.00001)
Referenced by sms_magToDB(), and sms_setMagThresh().
sfloat mag_thresh = .00001 [static] |
magnitude threshold for db conversion (-100db)
Referenced by sms_dBToMag(), sms_magToDB(), and sms_setMagThresh().
char* pChDebugFile = "debug.txt" |
< mersenne twister random number genorator debug text file
Referenced by sms_createDebugFile().
FILE* pDebug |
pointer to debug file
Referenced by sms_createDebugFile(), sms_writeDebugData(), and sms_writeDebugFile().