g711a1_plc.h

Go to the documentation of this file.
00001 /*
00002  * g711a1_plc.h
00003  *
00004  * packet loss concealment algorithm is based on the ITU recommendation
00005  * G.711 Appendix I.
00006  *
00007  * Copyright (c) 2008 Christian Hoene, University of Tuebingen, Germany
00008  *
00009  * The contents of this file are subject to the Mozilla Public License
00010  * Version 1.0 (the "License"); you may not use this file except in
00011  * compliance with the License. You may obtain a copy of the License at
00012  * http://www.mozilla.org/MPL/
00013  *
00014  * Software distributed under the License is distributed on an "AS IS"
00015  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00016  * the License for the specific language governing rights and limitations
00017  * under the License.
00018  *
00019  * The Initial Developer of the Original Code is Christian Hoene
00020  * based on the code given in ITU-T Recommendation G.711 Appendix I (09/99) 
00021  * "A high quality low-complexity algorithm for packet loss concealment with G.711"
00022  * Approved in 1999-09, www.itu.int.
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Revision: 24499 $
00027  * $Author: rjongbloed $
00028  * $Date: 2010-06-15 04:29:05 -0500 (Tue, 15 Jun 2010) $
00029  */
00030 
00031 #ifndef OPAL_CODEC_G711A1_PLC_H
00032 #define OPAL_CODEC_G711A1_PLC_H
00033 
00034 #ifndef SBC_DISABLE_PTLIB
00035 #include <opal/buildopts.h>
00036 #endif
00037 
00038 #if OPAL_G711PLC
00039 
00040 #include <string.h>
00041 
00046 class OpalG711_PLC
00047 {
00048   private:
00049     enum modes {
00050       LOSS_PERIOD1=10,            
00051       LOSS_PERIOD2start=20,       
00052       LOSS_PERIOD2overlap=21,     
00053       LOSS_PERIOD2=22,            
00054       LOSS_PERIOD3=30,            
00055       TRANSITION=40,              
00056       NOLOSS=0                    
00057     };
00058 
00059     int      conceal_count;       
00061     short  * transition_buf;      
00063     int      hist_len;            
00064     int      pitch_overlapmax;    
00066     short  * hist_buf;            
00067     short  * tmp_buf;             
00069     short *  conceal_overlapbuf;  
00071     double * pitch_buf;           
00072     double * pitch_lastq;         
00074     int      pitch_min;           
00075     int      pitch_max;           
00077     struct channel_counters {
00078       enum modes mode;            
00079       int      conceal_count;     
00080       int      transition_len;    
00081       int      transition_count;  
00083       int      pitch_overlap;     
00084       int      pitch_offset;      
00085       int      pitch;             
00086       int      pitch_blen;        
00087     } *channel;
00088 
00089     int      rate;                
00090     int      channels;            
00092     int ms2samples(int ms) const  
00093     {
00094       return ms*rate/1000;
00095     }
00096 
00097 
00098    public:
00099     OpalG711_PLC(int rate=8000, int channels=1, double pitch_low=66.6, double pitch_high=200);    
00100     ~OpalG711_PLC();
00101 
00102     void dofe(short *s, int size);         
00103     void addtohistory(short *s, int size);       
00104     int getAlgDelay() const { return pitch_overlapmax; };  
00105     void drop(short *s, int size);               
00107    private:
00108     void scalespeech(short *inout, int c, int sz, bool decay=true) const;
00109     void getfespeech(short *out, int c, int sz);
00110     void hist_savespeech(short *s, int size);
00111     int findpitch(int c);
00112     void overlapadd(double *l, double *r, double *o, int c, int cnt) const;
00113     void overlapadds(short *l, short *r, short *o, int c, int cnt) const;
00114     void overlapaddatend(short *s, short *f, int c, int start, int end, int count) const;
00115     void convertsf(short *f, double *t, int c, int cnt) const;
00116     void convertfs(double *f, short *t, int c, int cnt) const;
00117 
00118     inline void copy(double *f, double *t, int cnt) const { memmove(t,f,cnt*channels*sizeof(double)); };
00119     inline void copy(short *f, short *t, int cnt) const { memmove(t,f,cnt*channels*sizeof(short)); };
00120 
00121     int dofe_partly(short *out, int c, int size);
00122 };
00123 
00124 
00125 #endif // OPAL_G711PLC
00126 
00127 #endif // OPAL_CODEC_G711A1_PLC_H

Generated on Sun Nov 21 20:20:50 2010 for OPAL by  doxygen 1.4.7