~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.1.0/third_party/ilbc/gainquant.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
   /******************************************************************
 
3
 
 
4
       iLBC Speech Coder ANSI-C Source Code
 
5
 
 
6
 
 
7
 
 
8
 
 
9
 
 
10
 
 
11
       gainquant.c
 
12
 
 
13
       Copyright (C) The Internet Society (2004).
 
14
       All Rights Reserved.
 
15
 
 
16
   ******************************************************************/
 
17
 
 
18
   #include <string.h>
 
19
   #include <math.h>
 
20
   #include "constants.h"
 
21
   #include "filter.h"
 
22
 
 
23
   /*----------------------------------------------------------------*
 
24
    *  quantizer for the gain in the gain-shape coding of residual
 
25
    *---------------------------------------------------------------*/
 
26
 
 
27
   float gainquant(/* (o) quantized gain value */
 
28
       float in,       /* (i) gain value */
 
29
       float maxIn,/* (i) maximum of gain value */
 
30
       int cblen,      /* (i) number of quantization indices */
 
31
       int *index      /* (o) quantization index */
 
32
   ){
 
33
       int i, tindex;
 
34
       float minmeasure,measure, *cb, scale;
 
35
 
 
36
       /* ensure a lower bound on the scaling factor */
 
37
 
 
38
       scale=maxIn;
 
39
 
 
40
       if (scale<0.1) {
 
41
           scale=(float)0.1;
 
42
       }
 
43
 
 
44
       /* select the quantization table */
 
45
 
 
46
       if (cblen == 8) {
 
47
           cb = gain_sq3Tbl;
 
48
       } else if (cblen == 16) {
 
49
           cb = gain_sq4Tbl;
 
50
       } else  {
 
51
           cb = gain_sq5Tbl;
 
52
       }
 
53
 
 
54
       /* select the best index in the quantization table */
 
55
 
 
56
       minmeasure=10000000.0;
 
57
       tindex=0;
 
58
       for (i=0; i<cblen; i++) {
 
59
 
 
60
 
 
61
 
 
62
 
 
63
 
 
64
           measure=(in-scale*cb[i])*(in-scale*cb[i]);
 
65
 
 
66
           if (measure<minmeasure) {
 
67
               tindex=i;
 
68
               minmeasure=measure;
 
69
           }
 
70
       }
 
71
       *index=tindex;
 
72
 
 
73
       /* return the quantized value */
 
74
 
 
75
       return scale*cb[tindex];
 
76
   }
 
77
 
 
78
   /*----------------------------------------------------------------*
 
79
    *  decoder for quantized gains in the gain-shape coding of
 
80
    *  residual
 
81
    *---------------------------------------------------------------*/
 
82
 
 
83
   float gaindequant(  /* (o) quantized gain value */
 
84
       int index,      /* (i) quantization index */
 
85
       float maxIn,/* (i) maximum of unquantized gain */
 
86
       int cblen       /* (i) number of quantization indices */
 
87
   ){
 
88
       float scale;
 
89
 
 
90
       /* obtain correct scale factor */
 
91
 
 
92
       scale=(float)fabs(maxIn);
 
93
 
 
94
       if (scale<0.1) {
 
95
           scale=(float)0.1;
 
96
       }
 
97
 
 
98
       /* select the quantization table and return the decoded value */
 
99
 
 
100
       if (cblen==8) {
 
101
           return scale*gain_sq3Tbl[index];
 
102
       } else if (cblen==16) {
 
103
           return scale*gain_sq4Tbl[index];
 
104
       }
 
105
       else if (cblen==32) {
 
106
           return scale*gain_sq5Tbl[index];
 
107
       }
 
108
 
 
109
       return 0.0;
 
110
   }
 
111
 
 
112
 
 
113
 
 
114
 
 
115
 
 
116