blob: 6e9a28316f13c8191cdc111e06df340947762698 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11/*
12 * This file contains some help functions that did not fit elsewhere.
13 */
14
15#include "dsp_helpfunctions.h"
16
17
18WebRtc_Word16 WebRtcNetEQ_CalcFsMult(WebRtc_UWord16 fsHz)
19{
20 switch (fsHz)
21 {
22 case 8000:
23 {
24 return 1;
25 }
26 case 16000:
27 {
28 return 2;
29 }
30 case 32000:
31 {
32 return 4;
33 }
34 case 48000:
35 {
36 return 6;
37 }
38 default:
39 {
40 return 1;
41 }
42 }
43}
44
45
46int WebRtcNetEQ_DownSampleTo4kHz(const WebRtc_Word16 *in, int inLen, WebRtc_UWord16 inFsHz,
47 WebRtc_Word16 *out, int outLen, int compensateDelay)
48{
49 WebRtc_Word16 *B; /* filter coefficients */
50 WebRtc_Word16 Blen; /* number of coefficients */
51 WebRtc_Word16 filterDelay; /* phase delay in samples */
52 WebRtc_Word16 factor; /* conversion rate (inFsHz/8000) */
53 int ok;
54
55 /* Set constants depending on frequency used */
56 /* NOTE: The phase delay values are wrong compared to the true phase delay
57 of the filters. However, the error is preserved (through the +1 term)
58 for consistency. */
59 switch (inFsHz)
60 {
61 case 8000:
62 {
63 Blen = 3;
64 factor = 2;
65 B = (WebRtc_Word16*) WebRtcNetEQ_kDownsample8kHzTbl;
66 filterDelay = 1 + 1;
67 break;
68 }
69#ifdef NETEQ_WIDEBAND
70 case 16000:
71 {
72 Blen = 5;
73 factor = 4;
74 B = (WebRtc_Word16*) WebRtcNetEQ_kDownsample16kHzTbl;
75 filterDelay = 2 + 1;
76 break;
77 }
78#endif
79#ifdef NETEQ_32KHZ_WIDEBAND
80 case 32000:
81 {
82 Blen = 7;
83 factor = 8;
84 B = (WebRtc_Word16*) WebRtcNetEQ_kDownsample32kHzTbl;
85 filterDelay = 3 + 1;
86 break;
87 }
88#endif
89#ifdef NETEQ_48KHZ_WIDEBAND
90 case 48000:
91 {
92 Blen = 7;
93 factor = 12;
94 B = (WebRtc_Word16*) WebRtcNetEQ_kDownsample48kHzTbl;
95 filterDelay = 3 + 1;
96 break;
97 }
98#endif
99 default:
100 {
101 /* unsupported or wrong sample rate */
102 return -1;
103 }
104 }
105
106 if (!compensateDelay)
107 {
108 /* disregard delay compensation */
109 filterDelay = 0;
110 }
111
112 ok = WebRtcSpl_DownsampleFast((WebRtc_Word16*) &in[Blen - 1],
113 (WebRtc_Word16) (inLen - (Blen - 1)), /* number of input samples */
114 out, (WebRtc_Word16) outLen, /* number of output samples to produce */
115 B, Blen, factor, filterDelay); /* filter parameters */
116
117 return ok; /* return value is -1 if input signal is too short */
118
119}
120