Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: webrtc/common_audio/include/audio_util.h

Issue 1234463003: Integrate Intelligibility with APM (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix Mac Error (3) Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 static const float kMinInt16Inverse = 1.f / limits_int16::min(); 58 static const float kMinInt16Inverse = 1.f / limits_int16::min();
59 return v * (v > 0 ? kMaxInt16Inverse : -kMinInt16Inverse); 59 return v * (v > 0 ? kMaxInt16Inverse : -kMinInt16Inverse);
60 } 60 }
61 61
62 void FloatToS16(const float* src, size_t size, int16_t* dest); 62 void FloatToS16(const float* src, size_t size, int16_t* dest);
63 void S16ToFloat(const int16_t* src, size_t size, float* dest); 63 void S16ToFloat(const int16_t* src, size_t size, float* dest);
64 void FloatS16ToS16(const float* src, size_t size, int16_t* dest); 64 void FloatS16ToS16(const float* src, size_t size, int16_t* dest);
65 void FloatToFloatS16(const float* src, size_t size, float* dest); 65 void FloatToFloatS16(const float* src, size_t size, float* dest);
66 void FloatS16ToFloat(const float* src, size_t size, float* dest); 66 void FloatS16ToFloat(const float* src, size_t size, float* dest);
67 67
68 // Copy audio from |src| channels to |dest| channels unless |src| and |dest|
69 // point to the same address. |src| and |dest| must have the same number of
70 // channels, and there must be sufficient space allocated in |dest|.
71 template <typename T>
72 void CopyAudioIfNeeded(const T* const* src,
73 int num_frames,
74 int num_channels,
75 T* const* dest) {
76 for (int i = 0; i < num_channels; ++i) {
77 if (src[i] != dest[i]) {
78 std::copy(src[i], src[i] + num_frames, dest[i]);
79 }
80 }
81 }
82
68 // Deinterleave audio from |interleaved| to the channel buffers pointed to 83 // Deinterleave audio from |interleaved| to the channel buffers pointed to
69 // by |deinterleaved|. There must be sufficient space allocated in the 84 // by |deinterleaved|. There must be sufficient space allocated in the
70 // |deinterleaved| buffers (|num_channel| buffers with |samples_per_channel| 85 // |deinterleaved| buffers (|num_channel| buffers with |samples_per_channel|
71 // per buffer). 86 // per buffer).
72 template <typename T> 87 template <typename T>
73 void Deinterleave(const T* interleaved, 88 void Deinterleave(const T* interleaved,
74 int samples_per_channel, 89 int samples_per_channel,
75 int num_channels, 90 int num_channels,
76 T* const* deinterleaved) { 91 T* const* deinterleaved) {
77 for (int i = 0; i < num_channels; ++i) { 92 for (int i = 0; i < num_channels; ++i) {
(...skipping 17 matching lines...) Expand all
95 for (int i = 0; i < num_channels; ++i) { 110 for (int i = 0; i < num_channels; ++i) {
96 const T* channel = deinterleaved[i]; 111 const T* channel = deinterleaved[i];
97 int interleaved_idx = i; 112 int interleaved_idx = i;
98 for (int j = 0; j < samples_per_channel; ++j) { 113 for (int j = 0; j < samples_per_channel; ++j) {
99 interleaved[interleaved_idx] = channel[j]; 114 interleaved[interleaved_idx] = channel[j];
100 interleaved_idx += num_channels; 115 interleaved_idx += num_channels;
101 } 116 }
102 } 117 }
103 } 118 }
104 119
120 // Copies audio from a single channel buffer pointed to by |mono| to each
121 // channel of |interleaved|. There must be sufficient space allocated in
122 // |interleaved| (|samples_per_channel| * |num_channels|).
123 template <typename T>
124 void UpmixMonoToInterleaved(const T* mono,
125 int num_frames,
126 int num_channels,
127 T* interleaved) {
128 int interleaved_idx = 0;
129 for (int i = 0; i < num_frames; ++i) {
130 for (int j = 0; j < num_channels; ++j) {
131 interleaved[interleaved_idx++] = mono[i];
132 }
133 }
134 }
135
105 template <typename T, typename Intermediate> 136 template <typename T, typename Intermediate>
106 void DownmixToMono(const T* const* input_channels, 137 void DownmixToMono(const T* const* input_channels,
107 int num_frames, 138 int num_frames,
108 int num_channels, 139 int num_channels,
109 T* out) { 140 T* out) {
110 for (int i = 0; i < num_frames; ++i) { 141 for (int i = 0; i < num_frames; ++i) {
111 Intermediate value = input_channels[0][i]; 142 Intermediate value = input_channels[0][i];
112 for (int j = 1; j < num_channels; ++j) { 143 for (int j = 1; j < num_channels; ++j) {
113 value += input_channels[j][i]; 144 value += input_channels[j][i];
114 } 145 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 179
149 template <> 180 template <>
150 void DownmixInterleavedToMono<int16_t>(const int16_t* interleaved, 181 void DownmixInterleavedToMono<int16_t>(const int16_t* interleaved,
151 int num_frames, 182 int num_frames,
152 int num_channels, 183 int num_channels,
153 int16_t* deinterleaved); 184 int16_t* deinterleaved);
154 185
155 } // namespace webrtc 186 } // namespace webrtc
156 187
157 #endif // WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_ 188 #endif // WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_
OLDNEW
« no previous file with comments | « talk/media/webrtc/fakewebrtcvoiceengine.h ('k') | webrtc/modules/audio_processing/audio_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698