OPAL  Version 3.18.8
g711a1_plc.h
Go to the documentation of this file.
1 /*
2  * g711a1_plc.h
3  *
4  * packet loss concealment algorithm is based on the ITU recommendation
5  * G.711 Appendix I.
6  *
7  * Copyright (c) 2008 Christian Hoene, University of Tuebingen, Germany
8  *
9  * The contents of this file are subject to the Mozilla Public License
10  * Version 1.0 (the "License"); you may not use this file except in
11  * compliance with the License. You may obtain a copy of the License at
12  * http://www.mozilla.org/MPL/
13  *
14  * Software distributed under the License is distributed on an "AS IS"
15  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
16  * the License for the specific language governing rights and limitations
17  * under the License.
18  *
19  * The Initial Developer of the Original Code is Christian Hoene
20  * based on the code given in ITU-T Recommendation G.711 Appendix I (09/99)
21  * "A high quality low-complexity algorithm for packet loss concealment with G.711"
22  * Approved in 1999-09, www.itu.int.
23  *
24  * Contributor(s): ______________________________________.
25  */
26 
27 #ifndef OPAL_CODEC_G711A1_PLC_H
28 #define OPAL_CODEC_G711A1_PLC_H
29 
30 #ifndef SBC_DISABLE_PTLIB
31 #include <opal_config.h>
32 #endif
33 
34 #if OPAL_G711PLC
35 
36 #include <string.h>
37 
43 {
44  private:
45  enum modes {
46  LOSS_PERIOD1=10,
47  LOSS_PERIOD2start=20,
48  LOSS_PERIOD2overlap=21,
49  LOSS_PERIOD2=22,
50  LOSS_PERIOD3=30,
51  TRANSITION=40,
52  NOLOSS=0
53  };
54 
55  int conceal_count;
57  std::vector<short> transition_buf;
59  int hist_len;
60  int pitch_overlapmax;
62  std::vector<short> hist_buf;
63  std::vector<short> tmp_buf;
65  std::vector<short> conceal_overlapbuf;
67  std::vector<double> pitch_buf;
68  std::vector<double> pitch_lastq;
70  int pitch_min;
71  int pitch_max;
73  struct channel_counters
74  {
75  enum modes mode;
76  int conceal_count;
77  int transition_len;
78  int transition_count;
80  int pitch_overlap;
81  int pitch_offset;
82  int pitch;
83  int pitch_blen;
85  channel_counters() { memset(this, 0, sizeof(*this)); }
86  };
87  std::vector<channel_counters> channel;
88 
89  int rate;
90  int channels;
92  int ms2samples(int ms) const
93  {
94  return ms*rate/1000;
95  }
96 
97 
98  public:
99  OpalG711_PLC(int rate=8000, int channels=1, double pitch_low=66.6, double pitch_high=200);
100  ~OpalG711_PLC();
101 
102  void dofe(short *s, int size);
103  void addtohistory(short *s, int size);
104  int getAlgDelay() const { return pitch_overlapmax; };
105  void drop(short *s, int size);
107  private:
108  void scalespeech(short *inout, int c, int sz, bool decay=true) const;
109  void getfespeech(short *out, int c, int sz);
110  void hist_savespeech(short *s, int size);
111  int findpitch(int c);
112  void overlapadd(double *l, double *r, double *o, int c, int cnt) const;
113  void overlapadds(short *l, short *r, short *o, int c, int cnt) const;
114  void overlapaddatend(short *s, short *f, int c, int start, int end, int count) const;
115  void convertsf(short *f, double *t, int c, int cnt) const;
116  void convertfs(double *f, short *t, int c, int cnt) const;
117 
118  inline void copy(double *f, double *t, int cnt) const { memmove(t,f,cnt*channels*sizeof(double)); };
119  inline void copy(short *f, short *t, int cnt) const { memmove(t,f,cnt*channels*sizeof(short)); };
120 
121  int dofe_partly(short *out, int c, int size);
122 };
123 
124 
125 #endif // OPAL_G711PLC
126 
127 #endif // OPAL_CODEC_G711A1_PLC_H
Definition: g711a1_plc.h:42
OpalG711_PLC(int rate=8000, int channels=1, double pitch_low=66.6, double pitch_high=200)
void drop(short *s, int size)
void addtohistory(short *s, int size)
void dofe(short *s, int size)
int getAlgDelay() const
Definition: g711a1_plc.h:104