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

Generated on Fri Apr 6 20:18:13 2007 for CSL by  doxygen 1.4.5-20051010