00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef OPAL_CODEC_G711A1_PLC_H
00032 #define OPAL_CODEC_G711A1_PLC_H
00033
00034 #include <opal/buildopts.h>
00035
00036 #if OPAL_G711PLC
00037
00038
00043 class OpalG711_PLC
00044 {
00045 private:
00046 enum {
00047 LOSS_PERIOD1=10,
00048 LOSS_PERIOD2start=20,
00049 LOSS_PERIOD2overlap=21,
00050 LOSS_PERIOD2=22,
00051 LOSS_PERIOD3=30,
00052 TRANSITION=40,
00053 NOLOSS=0
00054 } mode;
00056 int conceal_count;
00058 short * transition_buf;
00059 int transition_len;
00060 int transition_count;
00062 int hist_len;
00063 short * hist_buf;
00064 short * tmp_buf;
00066 short * conceal_overlapbuf;
00068 double * pitch_buf;
00069 double * pitch_lastq;
00071 int pitch_min;
00072 int pitch_max;
00073 int pitch_overlap;
00074 int pitch_offset;
00075 int pitch;
00076 int pitch_blen;
00077 int pitch_overlapmax;
00079 int rate;
00081 int ms2samples(int ms) const
00082 {
00083 return ms*rate/1000;
00084 }
00085
00086
00087 public:
00088 OpalG711_PLC(int rate=8000, double pitch_low=66.6, double pitch_high=200);
00089 ~OpalG711_PLC();
00090
00091 void dofe(short *s, int size);
00092 void addtohistory(short *s, int size);
00093 int getAlgDelay() const { return pitch_overlapmax; };
00094 void drop(short *s, int size);
00096 private:
00097 void scalespeech(short *inout, int sz, bool decay=true) const;
00098 void getfespeech(short *out, int sz);
00099 void hist_savespeech(short *s, int size);
00100 int findpitch();
00101 void overlapadd(double *l, double *r, double *o, int cnt) const;
00102 void overlapadds(short *l, short *r, short *o, int cnt) const;
00103 void overlapaddatend(short *s, short *f, int start, int end, int count) const;
00104 void convertsf(short *f, double *t, int cnt) const;
00105 void convertfs(double *f, short *t, int cnt) const;
00106
00107 inline void copy(double *f, double *t, int cnt) const { memmove(t,f,cnt*sizeof(double)); };
00108 inline void copy(short *f, short *t, int cnt) const { memmove(t,f,cnt*sizeof(short)); };
00109 inline void zero(short *s, int cnt) const { memset(s, 0, cnt*sizeof(short)); };
00110
00111 int dofe_partly(short *out, int size);
00112 };
00113
00114
00115 #endif // OPAL_G711PLC
00116
00117 #endif // OPAL_CODEC_G711A1_PLC_H