blob: 8518e7b1ce4b1cc3c2fd9f83639663911aedbe8d [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:251/*
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/*
13 * This file contains resampling functions between 48 kHz and nb/wb.
14 * The description header can be found in signal_processing_library.h
15 *
16 */
17
18#include <string.h>
Mirko Bonadei92ea95e2017-09-15 04:47:3119#include "common_audio/signal_processing/include/signal_processing_library.h"
20#include "common_audio/signal_processing/resample_by_2_internal.h"
niklase@google.com470e71d2011-07-07 08:21:2521
22////////////////////////////
23///// 48 kHz -> 16 kHz /////
24////////////////////////////
25
26// 48 -> 16 resampler
pbos@webrtc.orgb0913072013-04-09 16:40:2827void WebRtcSpl_Resample48khzTo16khz(const int16_t* in, int16_t* out,
28 WebRtcSpl_State48khzTo16khz* state, int32_t* tmpmem)
niklase@google.com470e71d2011-07-07 08:21:2529{
30 ///// 48 --> 48(LP) /////
pbos@webrtc.orgb0913072013-04-09 16:40:2831 // int16_t in[480]
32 // int32_t out[480]
niklase@google.com470e71d2011-07-07 08:21:2533 /////
34 WebRtcSpl_LPBy2ShortToInt(in, 480, tmpmem + 16, state->S_48_48);
35
36 ///// 48 --> 32 /////
pbos@webrtc.orgb0913072013-04-09 16:40:2837 // int32_t in[480]
38 // int32_t out[320]
niklase@google.com470e71d2011-07-07 08:21:2539 /////
40 // copy state to and from input array
pbos@webrtc.orgb0913072013-04-09 16:40:2841 memcpy(tmpmem + 8, state->S_48_32, 8 * sizeof(int32_t));
42 memcpy(state->S_48_32, tmpmem + 488, 8 * sizeof(int32_t));
niklase@google.com470e71d2011-07-07 08:21:2543 WebRtcSpl_Resample48khzTo32khz(tmpmem + 8, tmpmem, 160);
44
45 ///// 32 --> 16 /////
pbos@webrtc.orgb0913072013-04-09 16:40:2846 // int32_t in[320]
47 // int16_t out[160]
niklase@google.com470e71d2011-07-07 08:21:2548 /////
49 WebRtcSpl_DownBy2IntToShort(tmpmem, 320, out, state->S_32_16);
50}
51
52// initialize state of 48 -> 16 resampler
53void WebRtcSpl_ResetResample48khzTo16khz(WebRtcSpl_State48khzTo16khz* state)
54{
pbos@webrtc.orgb0913072013-04-09 16:40:2855 memset(state->S_48_48, 0, 16 * sizeof(int32_t));
56 memset(state->S_48_32, 0, 8 * sizeof(int32_t));
57 memset(state->S_32_16, 0, 8 * sizeof(int32_t));
niklase@google.com470e71d2011-07-07 08:21:2558}
59
60////////////////////////////
61///// 16 kHz -> 48 kHz /////
62////////////////////////////
63
64// 16 -> 48 resampler
pbos@webrtc.orgb0913072013-04-09 16:40:2865void WebRtcSpl_Resample16khzTo48khz(const int16_t* in, int16_t* out,
66 WebRtcSpl_State16khzTo48khz* state, int32_t* tmpmem)
niklase@google.com470e71d2011-07-07 08:21:2567{
68 ///// 16 --> 32 /////
pbos@webrtc.orgb0913072013-04-09 16:40:2869 // int16_t in[160]
70 // int32_t out[320]
niklase@google.com470e71d2011-07-07 08:21:2571 /////
72 WebRtcSpl_UpBy2ShortToInt(in, 160, tmpmem + 16, state->S_16_32);
73
74 ///// 32 --> 24 /////
pbos@webrtc.orgb0913072013-04-09 16:40:2875 // int32_t in[320]
76 // int32_t out[240]
niklase@google.com470e71d2011-07-07 08:21:2577 // copy state to and from input array
78 /////
pbos@webrtc.orgb0913072013-04-09 16:40:2879 memcpy(tmpmem + 8, state->S_32_24, 8 * sizeof(int32_t));
80 memcpy(state->S_32_24, tmpmem + 328, 8 * sizeof(int32_t));
niklase@google.com470e71d2011-07-07 08:21:2581 WebRtcSpl_Resample32khzTo24khz(tmpmem + 8, tmpmem, 80);
82
83 ///// 24 --> 48 /////
pbos@webrtc.orgb0913072013-04-09 16:40:2884 // int32_t in[240]
85 // int16_t out[480]
niklase@google.com470e71d2011-07-07 08:21:2586 /////
87 WebRtcSpl_UpBy2IntToShort(tmpmem, 240, out, state->S_24_48);
88}
89
90// initialize state of 16 -> 48 resampler
91void WebRtcSpl_ResetResample16khzTo48khz(WebRtcSpl_State16khzTo48khz* state)
92{
pbos@webrtc.orgb0913072013-04-09 16:40:2893 memset(state->S_16_32, 0, 8 * sizeof(int32_t));
94 memset(state->S_32_24, 0, 8 * sizeof(int32_t));
95 memset(state->S_24_48, 0, 8 * sizeof(int32_t));
niklase@google.com470e71d2011-07-07 08:21:2596}
97
98////////////////////////////
99///// 48 kHz -> 8 kHz /////
100////////////////////////////
101
102// 48 -> 8 resampler
pbos@webrtc.orgb0913072013-04-09 16:40:28103void WebRtcSpl_Resample48khzTo8khz(const int16_t* in, int16_t* out,
104 WebRtcSpl_State48khzTo8khz* state, int32_t* tmpmem)
niklase@google.com470e71d2011-07-07 08:21:25105{
106 ///// 48 --> 24 /////
pbos@webrtc.orgb0913072013-04-09 16:40:28107 // int16_t in[480]
108 // int32_t out[240]
niklase@google.com470e71d2011-07-07 08:21:25109 /////
110 WebRtcSpl_DownBy2ShortToInt(in, 480, tmpmem + 256, state->S_48_24);
111
112 ///// 24 --> 24(LP) /////
pbos@webrtc.orgb0913072013-04-09 16:40:28113 // int32_t in[240]
114 // int32_t out[240]
niklase@google.com470e71d2011-07-07 08:21:25115 /////
116 WebRtcSpl_LPBy2IntToInt(tmpmem + 256, 240, tmpmem + 16, state->S_24_24);
117
118 ///// 24 --> 16 /////
pbos@webrtc.orgb0913072013-04-09 16:40:28119 // int32_t in[240]
120 // int32_t out[160]
niklase@google.com470e71d2011-07-07 08:21:25121 /////
122 // copy state to and from input array
pbos@webrtc.orgb0913072013-04-09 16:40:28123 memcpy(tmpmem + 8, state->S_24_16, 8 * sizeof(int32_t));
124 memcpy(state->S_24_16, tmpmem + 248, 8 * sizeof(int32_t));
niklase@google.com470e71d2011-07-07 08:21:25125 WebRtcSpl_Resample48khzTo32khz(tmpmem + 8, tmpmem, 80);
126
127 ///// 16 --> 8 /////
pbos@webrtc.orgb0913072013-04-09 16:40:28128 // int32_t in[160]
129 // int16_t out[80]
niklase@google.com470e71d2011-07-07 08:21:25130 /////
131 WebRtcSpl_DownBy2IntToShort(tmpmem, 160, out, state->S_16_8);
132}
133
134// initialize state of 48 -> 8 resampler
135void WebRtcSpl_ResetResample48khzTo8khz(WebRtcSpl_State48khzTo8khz* state)
136{
pbos@webrtc.orgb0913072013-04-09 16:40:28137 memset(state->S_48_24, 0, 8 * sizeof(int32_t));
138 memset(state->S_24_24, 0, 16 * sizeof(int32_t));
139 memset(state->S_24_16, 0, 8 * sizeof(int32_t));
140 memset(state->S_16_8, 0, 8 * sizeof(int32_t));
niklase@google.com470e71d2011-07-07 08:21:25141}
142
143////////////////////////////
144///// 8 kHz -> 48 kHz /////
145////////////////////////////
146
147// 8 -> 48 resampler
pbos@webrtc.orgb0913072013-04-09 16:40:28148void WebRtcSpl_Resample8khzTo48khz(const int16_t* in, int16_t* out,
149 WebRtcSpl_State8khzTo48khz* state, int32_t* tmpmem)
niklase@google.com470e71d2011-07-07 08:21:25150{
151 ///// 8 --> 16 /////
pbos@webrtc.orgb0913072013-04-09 16:40:28152 // int16_t in[80]
153 // int32_t out[160]
niklase@google.com470e71d2011-07-07 08:21:25154 /////
155 WebRtcSpl_UpBy2ShortToInt(in, 80, tmpmem + 264, state->S_8_16);
156
157 ///// 16 --> 12 /////
pbos@webrtc.orgb0913072013-04-09 16:40:28158 // int32_t in[160]
159 // int32_t out[120]
niklase@google.com470e71d2011-07-07 08:21:25160 /////
161 // copy state to and from input array
pbos@webrtc.orgb0913072013-04-09 16:40:28162 memcpy(tmpmem + 256, state->S_16_12, 8 * sizeof(int32_t));
163 memcpy(state->S_16_12, tmpmem + 416, 8 * sizeof(int32_t));
niklase@google.com470e71d2011-07-07 08:21:25164 WebRtcSpl_Resample32khzTo24khz(tmpmem + 256, tmpmem + 240, 40);
165
166 ///// 12 --> 24 /////
pbos@webrtc.orgb0913072013-04-09 16:40:28167 // int32_t in[120]
168 // int16_t out[240]
niklase@google.com470e71d2011-07-07 08:21:25169 /////
170 WebRtcSpl_UpBy2IntToInt(tmpmem + 240, 120, tmpmem, state->S_12_24);
171
172 ///// 24 --> 48 /////
pbos@webrtc.orgb0913072013-04-09 16:40:28173 // int32_t in[240]
174 // int16_t out[480]
niklase@google.com470e71d2011-07-07 08:21:25175 /////
176 WebRtcSpl_UpBy2IntToShort(tmpmem, 240, out, state->S_24_48);
177}
178
179// initialize state of 8 -> 48 resampler
180void WebRtcSpl_ResetResample8khzTo48khz(WebRtcSpl_State8khzTo48khz* state)
181{
pbos@webrtc.orgb0913072013-04-09 16:40:28182 memset(state->S_8_16, 0, 8 * sizeof(int32_t));
183 memset(state->S_16_12, 0, 8 * sizeof(int32_t));
184 memset(state->S_12_24, 0, 8 * sizeof(int32_t));
185 memset(state->S_24_48, 0, 8 * sizeof(int32_t));
niklase@google.com470e71d2011-07-07 08:21:25186}