1 /*
2  * Copyright (C) 2002-2003 Fhg Fokus
3  *
4  * This file is part of SEMS, a free SIP media server.
5  *
6  * SEMS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * For a license to use the sems software under conditions
12  * other than those described here, or to purchase support for this
13  * software, please contact iptel.org by e-mail at the following addresses:
14  *    info@iptel.org
15  *
16  * SEMS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25 
26 #ifndef _LowcFE_h_
27 #define _LowcFE_h_
28 
29 #include "AmAudio.h"
30 
31 typedef float Float;
32 
33 #define PITCH_MIN  ((unsigned int) (sample_rate / 200))  /* minimum allowed pitch, 200 Hz */
34 #define PITCH_MAX  ((unsigned int) (sample_rate / 66.6)) /* maximum allowed pitch, 66 Hz */
35 #define PITCHDIFF  (PITCH_MAX - PITCH_MIN)
36 #define POVERLAPMAX   (PITCH_MAX >> 2)              /* maximum pitch OLA window */
37 #define HISTORYLEN    (PITCH_MAX * 3 + POVERLAPMAX) /* history buff length*/
38 #define NDEC          2                             /* 2:1 decimation */
39 #define CORRLEN       20 * sample_rate / 1000 /* 20 msec correlation length */
40 #define CORRBUFLEN    (CORRLEN + PITCH_MAX)         /* correlation buffer length */
41 #define CORRMINPOWER  (((Float)250.) * (sample_rate / 8000))                 /* minimum power */
42 #define EOVERLAPINCR  32                            /* end OLA increment per frame,4 ms */
43 #define FRAMESZ       (10 * sample_rate / 1000) /* 10 msec */
44 #define ATTENFAC      ((Float).2)                   /* attenu. factor per 10 ms frame */
45 #define ATTENINCR     (ATTENFAC/(Float)(FRAMESZ))   /* attenuation per sample */
46 
47 /** \brief LowcFE erased frame generator for fec (plc) */
48 class LowcFE {
49 
50  public:
51   LowcFE(unsigned int sample_rate);
52   ~LowcFE();
53   void dofe(short *s); /* synthesize speech for erasure */
54   void addtohistory(short *s); /* add a good frame to history buf */
55 
56  protected:
57   unsigned int sample_rate;
58   int erasecnt; /* consecutive erased frames */
59   int poverlap; /* overlap based on pitch */
60   int poffset; /* offset into pitch period */
61   int pitch; /* pitch estimate */
62   int pitchblen; /* current pitch buffer length */
63   Float *pitchbufend; /* end of pitch buffer */
64   Float *pitchbufstart; /* start of pitch buffer */
65   Float *pitchbuf; /* buffer for cycles of speech */
66   Float *lastq; /* saved last quarter wavelength */
67   short *history; /* history buffer */
68 
69   void scalespeech(short *out);
70   void getfespeech(short *out, int sz);
71   void savespeech(short *s);
72   int findpitch();
73   void overlapadd(Float *l, Float *r, Float *o, int cnt);
74   void overlapadd(short *l, short *r, short *o, int cnt);
75   void overlapaddatend(short *s, short *f, int cnt);
76   void convertsf(short *f, Float *t, int cnt);
77   void convertfs(Float *f, short *t, int cnt);
78   void copyf(Float *f, Float *t, int cnt);
79   void copys(short *f, short *t, int cnt);
80   void zeros(short *s, int cnt);
81 };
82 
83 
84 #endif
85