/* CMP_prep.h C API headerfile specifying ComParser's audio preprocessor. The preprocessor object writes one single normalised feature vector to the specified memory location. Create new audio preprocessor (PREP) objects with function PREP_construct. Call PREP_process() (repeatedly) with new audio. Release the preprocessor after use with function PREP_destruct(). Version 1.40, june 23, 2004. Latest version available at: http://kmt.hku.nl/~pieter/SOFT/ Copyright (c) 2001-2004 Schreck Ensemble - Pieter Suurmond Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. Any person wishing to distribute modifications to the Software is requested to send the modifications to the original developer so that they can be incorporated into the canonical version. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #define kCMP_analysis_overlap (2) /* NOTE: sound analysers should use overlap of 2 (100%). When defined as (1), there would be no overlap, BUT you cannot just change this constant here, code may have implicit overlap of 2 somewhere... No guarentee thus that 'kCMP_analysis_overlap' just says it all,... there may be more things.... */ #define kCMP_varidist_fftStartBin (4) /* Used in init_varidistTable() and */ /* used in bfq-calculations. */ /* Defines lowest FFT bin to use. */ /* When 4, first resolution-interval */ /* is about a major third. */ #define kCMP_min_fps (5.0) /* Minimum and maximum number of feature vectors */ #define kCMP_max_fps (200.0) /* per second during analysis. */ /*----------------------------------------------------------------------------*/ /* The audio preprocessor data object. Contains only internal data, the user of a PREP object must allocate her own input and output buffers. */ typedef struct PREP_STRUCT* PREP; struct PREP_STRUCT { short* previousSamples; /* That's a shame, unnecessary copying. */ short* windowedSamples; /* Start of array alloced by audioProcess(). */ short* halfWindowTable; /* Contains first half (fade-in) of window. */ short* fftSquareOutput; /* Buffer for fft1024() to write into. */ short fftInputSize; /* Size of fft inputdata 1024, 2048 or 4096. */ short* squareRootTable; /* (could be unsigned) */ short previousRMS; /* Taken from fresh audio (half buffer). */ short previousPeak; short* varidistTable; /* Must be signed, negative ones are special. */ short varidistBands; /* Determined by init_varidistTable(). */ short varidistScalars; /* Size (number of linear amplitudes) of one */ /* timeframe from the analysis-layer. Two */ }; /* more than the varidistBands-number above! */ /*----------------------------------------------------------------------------*/ /* Constructor of PREP objects. First argument may not be NULL (best is when it points to NULL though). Returns zero on success, non-zero on failure. Leaves a valid object reference in *prep after a successful return, or NULL after a failure. Argument chunksize determines the input size of the FFT analysis, which is twice as much as must be transferred per time to PREP_process(). */ int PREP_construct(PREP* prep, int chunksize); /*----------------------------------------------------------------------------*/ /* Destructor of PREP objects. Returns 0 on success; 1 when a NULL argument was supplied; 2 when the PREP object was already gone. After return, the object's reference, *prep will be set to NULL to message the cleanup (except when a NULL argument was supplied and 1 was returned). */ int PREP_destruct(PREP* prep); /*----------------------------------------------------------------------------*/ /* Here is the PREP object's main job: preprocessing a block of audio, yiel- ding exactly one normalized feature vector, written at *feature_out. Called by analCallbackVD() in CMP_portaudio.c by the PortAudio engine when audio arrives. It may be called at interrupt level on some machines so don't do anything that could mess up the system like calling malloc() or free(). It is also called (out of realtime) by convert_audiofile_to_avalanchefile() in CMP_avalanche.c. Receives audio, weighs it with hamming-like windows, calculates overlap- ping FFT's, reorganizes the fft bands to a logarithmic frequency scale. */ int PREP_process(PREP prep, /* Audio preprocessor object. */ short* audio_in, /* MUST be half of FFT size! */ short* feature_out); /* Always 1 feature vector. */ /*----------------------------------------------------------------------------*/ /* To test fft, bin-reorganizing and vector normalisation. Argument fftsize is twice the amount of samples per feature vector (because overlap is 2). Second argument may be NULL. Returns zero on success, non-zero on failure. */ int PREP_test(int fftsize, FILE* msg); /*----------------------------------------------------------------------------*/ /* Tests the fft-routine directly, not via the callback(), prints test results to filestream msg (which may be NULL, stdout, stderr or some textfile already opened for writing by the caller). Returns nonzero on invalid first argument or memory failures. Returns zero on success. */ int PREP_test_fft(int inputsize, FILE* msg);