LPC.h

Go to the documentation of this file.
00001 //
00002 //  LPC.h -- specification of the classes that perform LPC-based analysis/resynthesis.
00003 //  These use Peter Kabal's libtsp routines (http://WWW.TSP.ECE.McGill.CA) for the heavy lifting.
00004 //  See the copyright notice and acknowledgment of authors in the file COPYRIGHT
00005 //
00006 
00007 #ifndef CSL_LPC_H
00008 #define CSL_LPC_H
00009 
00010 #include "CSL_Includes.h"
00011 
00012 namespace csl {
00013 
00014 // File header and ferame srtuct for LPC data files
00015 // This could use SDIF or add chunk types to AIFF files
00016 
00017 // File header
00018 
00019 typedef struct lpc_header {
00020     unsigned int keyword;       // magic #, chunk type
00021     unsigned int filesize;
00022     float duration;
00023     unsigned int numframes;
00024     unsigned int order;
00025     unsigned int windowSize;
00026     unsigned int hopSize;
00027     double preEmphasis;
00028 } CSL_LPC_HEADER;
00029 
00030 // Frame header - similar to an MIR database record; holds frame's derived ampl-domain and freq-domain data
00031 
00032 typedef struct frame_header {
00033     unsigned int keyword;
00034     unsigned int framesize;
00035     unsigned int order;     // size of LPC refl. coeff. array
00036     unsigned int windowSize;    // frame/window size
00037     float rmsamp;           // RMS ampl
00038     float hifreq;               // hpf energy > 2 kHz
00039     float lofreq;               // lpf energy < 200 Hz
00040     float freqest1;         // autocorr freq estimate
00041     float freqest2;         // HPS freq estimate
00042     unsigned int zeroes;        // count of zero-crossings
00043     float smoothfreq;       // smoothed freq estimate
00044     float noisiness;            // autocorr noise estimate
00045     float resid;                // LPC residual energy
00046     float formant1;         // LPC 1st formant
00047     float formant2;         // LPC 2nd formant
00048     float centroid;         // spectral centroid
00049 //  float mfccPeak1;            // 1st MFCC peak
00050 //  float mfccPeak2;            // 2nd MFCC peak
00051     unsigned int MIDIKey;       // MIDI key #
00052     unsigned int isTransition;  // state flag (note-on, note-off, continuation, plosive, etc.
00053 //  float[order] data;          // LPC data frame - reflection coefficients
00054 } CSL_LPC_FRAME;
00055 
00056 #define CSL_LPC_LKEY 0x55120942         // Magic number for files
00057 #define CSL_LPC_FKEY 0x55120943         // Magic number for frames
00058 #define CSL_LPC_MAXPOLES    150         // max pre-allocated frame size
00059 #define CSL_HPS_DEPTH   10              // size of harmonic product spectrum reduction
00060 
00066 
00067 class LPCAnalyzer : public Effect {
00068 public:
00069     LPCAnalyzer(UnitGenerator & in, unsigned size = CGestalt::blockSize(), unsigned hopSize = CGestalt::blockSize(), unsigned order = 50);
00070     ~LPCAnalyzer();
00072     unsigned windowSize() { return mWindowSize; }
00073     unsigned hopSize() { return mHopSize; }
00074     unsigned LPCOrder() { return mLPCOrder; }
00075     Buffer getCoefficients() { return mLPCCoefficients; }
00076     Buffer getResidual() { return mLPCResidual; }
00077     double getError() { return mPredErr; }
00078 
00079     void setFileNames(char * coeff, char * resid);  
00080     void setPreEmphasis(double factor) { mPreEmphasis = factor; }
00081     void setBWExpansion(double factor) { mBWExpansion = factor; }
00082     void closeFiles();                      
00083     void setOverwrite(bool reuse) { mOverwriteOutput = reuse; }
00084     void setUseWindow(bool use) { mUseWindow = use; }
00086     void nextBuffer(Buffer& outputBuffer, unsigned outBufNum) throw (CException);
00087     
00088 protected:  
00089     unsigned mWindowSize;               
00090     unsigned mHopSize;                  
00091     unsigned mLPCOrder;                 
00092     double mPredErr;                        
00093     double mPreEmphasis;                
00094     double mBWExpansion;                
00095     bool mOverwriteOutput;              
00096     bool mUseWindow;                    
00097 
00098     Buffer mTempBuffer;                 
00099     Buffer mWindowBuffer;               
00100     Buffer mLPCCoefficients;                
00101     Buffer mFilterCoefficients;         
00102     Buffer mFilterInput;                    
00103     Buffer mPCCoefficients;             
00104     Buffer mLPCResidual;                    
00105     
00106     RingBuffer mRing;                   
00107 
00108     Butter * mLoPass;                   
00109     Butter * mHiPass;                       
00110     FFT * mFFT;                         
00111                             // Output files
00112     FILE * mCoeffFile;                  
00113     SoundFile * mResidFile;             
00114     
00115 };
00116 
00117 //  typical BW expansion factor in range 0.996 - 0.990
00118 //      b           BW exp
00119 //      1.000      0
00120 //      0.996     10.2 Hz
00121 //      0.995     12.8 Hz
00122 //      0.994     15.3 Hz
00123 //      0.990     25.6 Hz
00124 //      0.980     51.4 Hz
00125 
00129 
00130 class LPCFilter : public Effect, public Scalable {
00131 public:
00132     LPCFilter(UnitGenerator & in, char * lpcFile);
00133     LPCFilter(UnitGenerator & in, Buffer & lpcData, unsigned size, unsigned hopSize, unsigned order);
00134     ~LPCFilter();
00135 
00136     unsigned windowSize() { return mWindowSize; }
00137     unsigned hopSize() { return mHopSize; }
00138     unsigned LPCOrder() { return mLPCOrder; }
00139     double deEmphasis() { return mDeEmphasis; }
00140     
00141     Envelope * timeEnvelope() { return mTimeEnvelope; }
00142     void setTimeEnvelope(Envelope * env) { mTimeEnvelope = env; }
00143     
00144     void nextBuffer(Buffer& outputBuffer, unsigned outBufNum) throw (CException);   
00145 
00146 protected:  
00147     unsigned mWindowSize;           
00148     unsigned mHopSize;              
00149     unsigned mLPCOrder;             
00150     double mDeEmphasis;
00151     
00152     Envelope * mTimeEnvelope;       
00153 
00154     FILE * mLPCFile;                    
00155     Buffer mLPCBuffer;              
00156 
00157     Buffer mTempBuffer;             
00158 
00159 };
00160 
00161 }
00162 
00163 #endif

Generated on Thu Sep 17 23:14:16 2009 for CSL by  doxygen 1.5.8