blob: ef721d5599717559f20bf3c4229c6fcf7d11785a [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
pbos@webrtc.org0946a562013-04-09 00:28:06 +000018int16_t WebRtcNetEQ_CalcFsMult(uint16_t fsHz)
niklase@google.com470e71d2011-07-07 08:21:25 +000019{
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
pbos@webrtc.org0946a562013-04-09 00:28:06 +000046int WebRtcNetEQ_DownSampleTo4kHz(const int16_t *in, int inLen, uint16_t inFsHz,
47 int16_t *out, int outLen, int compensateDelay)
niklase@google.com470e71d2011-07-07 08:21:25 +000048{
pbos@webrtc.org0946a562013-04-09 00:28:06 +000049 int16_t *B; /* filter coefficients */
50 int16_t Blen; /* number of coefficients */
51 int16_t filterDelay; /* phase delay in samples */
52 int16_t factor; /* conversion rate (inFsHz/8000) */
niklase@google.com470e71d2011-07-07 08:21:25 +000053 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;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000065 B = (int16_t*) WebRtcNetEQ_kDownsample8kHzTbl;
niklase@google.com470e71d2011-07-07 08:21:25 +000066 filterDelay = 1 + 1;
67 break;
68 }
69#ifdef NETEQ_WIDEBAND
70 case 16000:
71 {
72 Blen = 5;
73 factor = 4;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000074 B = (int16_t*) WebRtcNetEQ_kDownsample16kHzTbl;
niklase@google.com470e71d2011-07-07 08:21:25 +000075 filterDelay = 2 + 1;
76 break;
77 }
78#endif
79#ifdef NETEQ_32KHZ_WIDEBAND
80 case 32000:
81 {
82 Blen = 7;
83 factor = 8;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000084 B = (int16_t*) WebRtcNetEQ_kDownsample32kHzTbl;
niklase@google.com470e71d2011-07-07 08:21:25 +000085 filterDelay = 3 + 1;
86 break;
87 }
88#endif
89#ifdef NETEQ_48KHZ_WIDEBAND
90 case 48000:
91 {
92 Blen = 7;
93 factor = 12;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000094 B = (int16_t*) WebRtcNetEQ_kDownsample48kHzTbl;
niklase@google.com470e71d2011-07-07 08:21:25 +000095 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
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000112 ok = WebRtcSpl_DownsampleFast((int16_t*) &in[Blen - 1],
113 (int16_t) (inLen - (Blen - 1)), /* number of input samples */
114 out, (int16_t) outLen, /* number of output samples to produce */
niklase@google.com470e71d2011-07-07 08:21:25 +0000115 B, Blen, factor, filterDelay); /* filter parameters */
116
117 return ok; /* return value is -1 if input signal is too short */
118
119}
120