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 #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 {
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 } mode;
00059 int conceal_count;
00061 short * transition_buf;
00062 int transition_len;
00063 int transition_count;
00065 int hist_len;
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;
00076 int pitch_overlap;
00077 int pitch_offset;
00078 int pitch;
00079 int pitch_blen;
00080 int pitch_overlapmax;
00082 int rate;
00084 int ms2samples(int ms) const
00085 {
00086 return ms*rate/1000;
00087 }
00088
00089
00090 public:
00091 OpalG711_PLC(int rate=8000, double pitch_low=66.6, double pitch_high=200);
00092 ~OpalG711_PLC();
00093
00094 void dofe(short *s, int size);
00095 void addtohistory(short *s, int size);
00096 int getAlgDelay() const { return pitch_overlapmax; };
00097 void drop(short *s, int size);
00099 private:
00100 void scalespeech(short *inout, int sz, bool decay=true) const;
00101 void getfespeech(short *out, int sz);
00102 void hist_savespeech(short *s, int size);
00103 int findpitch();
00104 void overlapadd(double *l, double *r, double *o, int cnt) const;
00105 void overlapadds(short *l, short *r, short *o, int cnt) const;
00106 void overlapaddatend(short *s, short *f, int start, int end, int count) const;
00107 void convertsf(short *f, double *t, int cnt) const;
00108 void convertfs(double *f, short *t, int cnt) const;
00109
00110 inline void copy(double *f, double *t, int cnt) const { memmove(t,f,cnt*sizeof(double)); };
00111 inline void copy(short *f, short *t, int cnt) const { memmove(t,f,cnt*sizeof(short)); };
00112 inline void zero(short *s, int cnt) const { memset(s, 0, cnt*sizeof(short)); };
00113
00114 int dofe_partly(short *out, int size);
00115 };
00116
00117
00118 #endif // OPAL_G711PLC
00119
00120 #endif // OPAL_CODEC_G711A1_PLC_H