ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 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 | |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 11 | #include <math.h> |
| 12 | #include <stdlib.h> |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 13 | |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 14 | #include <algorithm> |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 15 | #include <memory> |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "api/array_view.h" |
| 19 | #include "common_audio/signal_processing/include/signal_processing_library.h" |
| 20 | #include "modules/audio_processing/audio_buffer.h" |
| 21 | #include "modules/audio_processing/intelligibility/intelligibility_enhancer.h" |
| 22 | #include "modules/audio_processing/noise_suppression_impl.h" |
| 23 | #include "modules/audio_processing/test/audio_buffer_tools.h" |
| 24 | #include "modules/audio_processing/test/bitexactness_tools.h" |
| 25 | #include "rtc_base/arraysize.h" |
| 26 | #include "test/gtest.h" |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
| 29 | |
| 30 | namespace { |
| 31 | |
| 32 | // Target output for ERB create test. Generated with matlab. |
| 33 | const float kTestCenterFreqs[] = { |
Alejandro Luebs | 18fcbcf | 2016-02-22 15:57:38 -0800 | [diff] [blame] | 34 | 14.5213f, 29.735f, 45.6781f, 62.3884f, 79.9058f, 98.2691f, 117.521f, |
| 35 | 137.708f, 158.879f, 181.084f, 204.378f, 228.816f, 254.459f, 281.371f, |
| 36 | 309.618f, 339.273f, 370.411f, 403.115f, 437.469f, 473.564f, 511.497f, |
| 37 | 551.371f, 593.293f, 637.386f, 683.77f, 732.581f, 783.96f, 838.06f, |
| 38 | 895.046f, 955.09f, 1018.38f, 1085.13f, 1155.54f, 1229.85f, 1308.32f, |
| 39 | 1391.22f, 1478.83f, 1571.5f, 1669.55f, 1773.37f, 1883.37f, 2000.f}; |
| 40 | const float kTestFilterBank[][33] = { |
| 41 | {0.2f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 42 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 43 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 44 | {0.2f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 45 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 46 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 47 | {0.2f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 48 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 49 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 50 | {0.2f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 51 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 52 | 0.f, 0.f, 0.f, 0.f, 0.f, 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f}, |
| 101 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.285714f, 0.315789f, 0.176471f, 0.f, |
| 102 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 103 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 104 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.315789f, 0.352941f, 0.142857f, |
| 105 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 106 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 107 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.352941f, 0.285714f, |
| 108 | 0.157895f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 109 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 110 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.285714f, |
| 111 | 0.210526f, 0.111111f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 112 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 113 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 114 | 0.f, 0.285714f, 0.315789f, 0.222222f, 0.111111f, 0.f, 0.f, 0.f, 0.f, |
| 115 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 116 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 117 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 118 | 0.f, 0.f, 0.315789f, 0.333333f, 0.222222f, 0.111111f, 0.f, 0.f, 0.f, |
| 119 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 120 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 121 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 122 | 0.f, 0.f, 0.f, 0.333333f, 0.333333f, 0.222222f, 0.111111f, 0.f, 0.f, |
| 123 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 124 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 125 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 126 | 0.f, 0.f, 0.f, 0.f, 0.333333f, 0.333333f, 0.222222f, 0.111111f, 0.f, |
| 127 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 128 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 129 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 130 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.333333f, 0.333333f, 0.222222f, 0.111111f, |
| 131 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 132 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 133 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 134 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.333333f, 0.333333f, 0.222222f, |
| 135 | 0.108108f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 136 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 137 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 138 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.333333f, 0.333333f, |
| 139 | 0.243243f, 0.153846f, 0.0833333f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 140 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 141 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 142 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.333333f, |
| 143 | 0.324324f, 0.230769f, 0.166667f, 0.0909091f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 144 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 145 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 146 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 147 | 0.324324f, 0.307692f, 0.25f, 0.181818f, 0.0833333f, 0.f, 0.f, 0.f, 0.f, |
| 148 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 149 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 150 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 151 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.307692f, 0.333333f, |
| 152 | 0.363636f, 0.25f, 0.151515f, 0.0793651f, 0.f, 0.f, 0.f, |
| 153 | 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 154 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 155 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 156 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 157 | 0.f, 0.f, 0.166667f, 0.363636f, 0.333333f, 0.242424f, |
| 158 | 0.190476f, 0.133333f, 0.0689655f, 0.f, 0.f, 0.f, |
| 159 | 0.f, 0.f, 0.f}, |
| 160 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 161 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 162 | 0.f, 0.f, 0.f, 0.f, 0.333333f, 0.30303f, 0.253968f, 0.2f, 0.137931f, |
| 163 | 0.0714286f, 0.f, 0.f, 0.f, 0.f, 0.f}, |
| 164 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 165 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 166 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 167 | 0.f, 0.f, 0.30303f, 0.31746f, 0.333333f, 0.275862f, 0.214286f, |
| 168 | 0.125f, 0.0655738f, 0.f, 0.f, 0.f}, |
| 169 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 170 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 171 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 172 | 0.f, 0.f, 0.f, 0.15873f, 0.333333f, 0.344828f, 0.357143f, |
| 173 | 0.25f, 0.196721f, 0.137931f, 0.0816327f, 0.f}, |
| 174 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 175 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 176 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 177 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.172414f, 0.357143f, |
| 178 | 0.3125f, 0.245902f, 0.172414f, 0.102041f, 0.f}, |
| 179 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 180 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 181 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 182 | 0.f, 0.3125f, 0.327869f, 0.344828f, 0.204082f, 0.f}, |
| 183 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 184 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 185 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.163934f, 0.344828f, 0.408163f, 0.5f}, |
| 186 | {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 187 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
| 188 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.204082f, 0.5f}}; |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 189 | static_assert(arraysize(kTestCenterFreqs) == arraysize(kTestFilterBank), |
| 190 | "Test filterbank badly initialized."); |
| 191 | |
| 192 | // Target output for gain solving test. Generated with matlab. |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 193 | const size_t kTestStartFreq = 12; // Lowest integral frequency for ERBs. |
aluebs | f99af6b | 2016-02-24 17:25:42 -0800 | [diff] [blame] | 194 | const float kTestZeroVar = 1.f; |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 195 | const float kTestNonZeroVarLambdaTop[] = { |
aluebs | f99af6b | 2016-02-24 17:25:42 -0800 | [diff] [blame] | 196 | 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 0.f, 0.f, |
Alejandro Luebs | 18fcbcf | 2016-02-22 15:57:38 -0800 | [diff] [blame] | 197 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, |
aluebs | f99af6b | 2016-02-24 17:25:42 -0800 | [diff] [blame] | 198 | 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 199 | static_assert(arraysize(kTestCenterFreqs) == |
| 200 | arraysize(kTestNonZeroVarLambdaTop), |
Alejandro Luebs | 3234819 | 2016-02-17 20:04:19 -0800 | [diff] [blame] | 201 | "Power test data badly initialized."); |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 202 | const float kMaxTestError = 0.005f; |
| 203 | |
| 204 | // Enhancer initialization parameters. |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 205 | const int kSamples = 10000; |
Alejandro Luebs | 18fcbcf | 2016-02-22 15:57:38 -0800 | [diff] [blame] | 206 | const int kSampleRate = 4000; |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 207 | const int kNumChannels = 1; |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 208 | const int kFragmentSize = kSampleRate / 100; |
Alex Luebs | 57ae829 | 2016-03-09 16:24:34 +0100 | [diff] [blame] | 209 | const size_t kNumNoiseBins = 129; |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 210 | const size_t kNumBands = 1; |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 211 | |
peah | 4b0c741 | 2016-03-28 23:43:49 -0700 | [diff] [blame] | 212 | // Number of frames to process in the bitexactness tests. |
| 213 | const size_t kNumFramesToProcess = 1000; |
| 214 | |
| 215 | int IntelligibilityEnhancerSampleRate(int sample_rate_hz) { |
| 216 | return (sample_rate_hz > AudioProcessing::kSampleRate16kHz |
| 217 | ? AudioProcessing::kSampleRate16kHz |
| 218 | : sample_rate_hz); |
| 219 | } |
| 220 | |
| 221 | // Process one frame of data and produce the output. |
| 222 | void ProcessOneFrame(int sample_rate_hz, |
| 223 | AudioBuffer* render_audio_buffer, |
| 224 | AudioBuffer* capture_audio_buffer, |
| 225 | NoiseSuppressionImpl* noise_suppressor, |
| 226 | IntelligibilityEnhancer* intelligibility_enhancer) { |
| 227 | if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) { |
| 228 | render_audio_buffer->SplitIntoFrequencyBands(); |
| 229 | capture_audio_buffer->SplitIntoFrequencyBands(); |
| 230 | } |
| 231 | |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 232 | intelligibility_enhancer->ProcessRenderAudio(render_audio_buffer); |
peah | 4b0c741 | 2016-03-28 23:43:49 -0700 | [diff] [blame] | 233 | |
| 234 | noise_suppressor->AnalyzeCaptureAudio(capture_audio_buffer); |
| 235 | noise_suppressor->ProcessCaptureAudio(capture_audio_buffer); |
| 236 | |
| 237 | intelligibility_enhancer->SetCaptureNoiseEstimate( |
aluebs | 11d4a42 | 2016-04-28 14:58:32 -0700 | [diff] [blame] | 238 | noise_suppressor->NoiseEstimate(), 0); |
peah | 4b0c741 | 2016-03-28 23:43:49 -0700 | [diff] [blame] | 239 | |
| 240 | if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) { |
| 241 | render_audio_buffer->MergeFrequencyBands(); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | // Processes a specified amount of frames, verifies the results and reports |
| 246 | // any errors. |
| 247 | void RunBitexactnessTest(int sample_rate_hz, |
| 248 | size_t num_channels, |
| 249 | rtc::ArrayView<const float> output_reference) { |
| 250 | const StreamConfig render_config(sample_rate_hz, num_channels, false); |
| 251 | AudioBuffer render_buffer( |
| 252 | render_config.num_frames(), render_config.num_channels(), |
| 253 | render_config.num_frames(), render_config.num_channels(), |
| 254 | render_config.num_frames()); |
| 255 | test::InputAudioFile render_file( |
| 256 | test::GetApmRenderTestVectorFileName(sample_rate_hz)); |
| 257 | std::vector<float> render_input(render_buffer.num_frames() * |
| 258 | render_buffer.num_channels()); |
| 259 | |
| 260 | const StreamConfig capture_config(sample_rate_hz, num_channels, false); |
| 261 | AudioBuffer capture_buffer( |
| 262 | capture_config.num_frames(), capture_config.num_channels(), |
| 263 | capture_config.num_frames(), capture_config.num_channels(), |
| 264 | capture_config.num_frames()); |
| 265 | test::InputAudioFile capture_file( |
| 266 | test::GetApmCaptureTestVectorFileName(sample_rate_hz)); |
| 267 | std::vector<float> capture_input(render_buffer.num_frames() * |
| 268 | capture_buffer.num_channels()); |
| 269 | |
| 270 | rtc::CriticalSection crit_capture; |
| 271 | NoiseSuppressionImpl noise_suppressor(&crit_capture); |
| 272 | noise_suppressor.Initialize(capture_config.num_channels(), sample_rate_hz); |
| 273 | noise_suppressor.Enable(true); |
| 274 | |
| 275 | IntelligibilityEnhancer intelligibility_enhancer( |
| 276 | IntelligibilityEnhancerSampleRate(sample_rate_hz), |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 277 | render_config.num_channels(), kNumBands, |
| 278 | NoiseSuppressionImpl::num_noise_bins()); |
peah | 4b0c741 | 2016-03-28 23:43:49 -0700 | [diff] [blame] | 279 | |
| 280 | for (size_t frame_no = 0u; frame_no < kNumFramesToProcess; ++frame_no) { |
| 281 | ReadFloatSamplesFromStereoFile(render_buffer.num_frames(), |
| 282 | render_buffer.num_channels(), &render_file, |
| 283 | render_input); |
| 284 | ReadFloatSamplesFromStereoFile(capture_buffer.num_frames(), |
| 285 | capture_buffer.num_channels(), &capture_file, |
| 286 | capture_input); |
| 287 | |
| 288 | test::CopyVectorToAudioBuffer(render_config, render_input, &render_buffer); |
| 289 | test::CopyVectorToAudioBuffer(capture_config, capture_input, |
| 290 | &capture_buffer); |
| 291 | |
| 292 | ProcessOneFrame(sample_rate_hz, &render_buffer, &capture_buffer, |
| 293 | &noise_suppressor, &intelligibility_enhancer); |
| 294 | } |
| 295 | |
| 296 | // Extract and verify the test results. |
| 297 | std::vector<float> render_output; |
| 298 | test::ExtractVectorFromAudioBuffer(render_config, &render_buffer, |
| 299 | &render_output); |
| 300 | |
peah | 7ea928e | 2016-03-30 08:13:57 -0700 | [diff] [blame] | 301 | const float kElementErrorBound = 1.f / static_cast<float>(1 << 15); |
peah | 4b0c741 | 2016-03-28 23:43:49 -0700 | [diff] [blame] | 302 | |
| 303 | // Compare the output with the reference. Only the first values of the output |
| 304 | // from last frame processed are compared in order not having to specify all |
| 305 | // preceeding frames as testvectors. As the algorithm being tested has a |
| 306 | // memory, testing only the last frame implicitly also tests the preceeding |
| 307 | // frames. |
peah | 7ea928e | 2016-03-30 08:13:57 -0700 | [diff] [blame] | 308 | EXPECT_TRUE(test::VerifyDeinterleavedArray( |
| 309 | render_buffer.num_frames(), render_config.num_channels(), |
| 310 | output_reference, render_output, kElementErrorBound)); |
peah | 4b0c741 | 2016-03-28 23:43:49 -0700 | [diff] [blame] | 311 | } |
| 312 | |
aluebs | 11d4a42 | 2016-04-28 14:58:32 -0700 | [diff] [blame] | 313 | float float_rand() { |
| 314 | return std::rand() * 2.f / RAND_MAX - 1; |
| 315 | } |
| 316 | |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 317 | } // namespace |
| 318 | |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 319 | class IntelligibilityEnhancerTest : public ::testing::Test { |
| 320 | protected: |
| 321 | IntelligibilityEnhancerTest() |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 322 | : clear_buffer_(kFragmentSize, |
| 323 | kNumChannels, |
| 324 | kFragmentSize, |
| 325 | kNumChannels, |
| 326 | kFragmentSize), |
| 327 | stream_config_(kSampleRate, kNumChannels), |
| 328 | clear_data_(kSamples), |
| 329 | noise_data_(kNumNoiseBins), |
| 330 | orig_data_(kSamples) { |
aluebs | 11d4a42 | 2016-04-28 14:58:32 -0700 | [diff] [blame] | 331 | std::srand(1); |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 332 | enh_.reset(new IntelligibilityEnhancer(kSampleRate, kNumChannels, kNumBands, |
| 333 | kNumNoiseBins)); |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 334 | } |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 335 | |
Alejandro Luebs | 3234819 | 2016-02-17 20:04:19 -0800 | [diff] [blame] | 336 | bool CheckUpdate() { |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 337 | enh_.reset(new IntelligibilityEnhancer(kSampleRate, kNumChannels, kNumBands, |
| 338 | kNumNoiseBins)); |
aluebs | 0a00759 | 2016-02-26 17:17:38 -0800 | [diff] [blame] | 339 | float* clear_cursor = clear_data_.data(); |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 340 | for (int i = 0; i < kSamples; i += kFragmentSize) { |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 341 | enh_->SetCaptureNoiseEstimate(noise_data_, 1); |
| 342 | clear_buffer_.CopyFrom(&clear_cursor, stream_config_); |
| 343 | enh_->ProcessRenderAudio(&clear_buffer_); |
| 344 | clear_buffer_.CopyTo(stream_config_, &clear_cursor); |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 345 | clear_cursor += kFragmentSize; |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 346 | } |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 347 | for (int i = initial_delay_; i < kSamples; i++) { |
| 348 | if (std::fabs(clear_data_[i] - orig_data_[i - initial_delay_]) > |
| 349 | kMaxTestError) { |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 350 | return true; |
| 351 | } |
| 352 | } |
| 353 | return false; |
| 354 | } |
| 355 | |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 356 | std::unique_ptr<IntelligibilityEnhancer> enh_; |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 357 | // Render clean speech buffer. |
| 358 | AudioBuffer clear_buffer_; |
| 359 | StreamConfig stream_config_; |
Alejandro Luebs | 3234819 | 2016-02-17 20:04:19 -0800 | [diff] [blame] | 360 | std::vector<float> clear_data_; |
| 361 | std::vector<float> noise_data_; |
| 362 | std::vector<float> orig_data_; |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 363 | size_t initial_delay_; |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 364 | }; |
| 365 | |
Alejandro Luebs | 3234819 | 2016-02-17 20:04:19 -0800 | [diff] [blame] | 366 | // For each class of generated data, tests that render stream is updated when |
| 367 | // it should be. |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 368 | TEST_F(IntelligibilityEnhancerTest, TestRenderUpdate) { |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 369 | initial_delay_ = enh_->render_mangler_->initial_delay(); |
Alejandro Luebs | 18fcbcf | 2016-02-22 15:57:38 -0800 | [diff] [blame] | 370 | std::fill(noise_data_.begin(), noise_data_.end(), 0.f); |
| 371 | std::fill(orig_data_.begin(), orig_data_.end(), 0.f); |
| 372 | std::fill(clear_data_.begin(), clear_data_.end(), 0.f); |
Alejandro Luebs | 3234819 | 2016-02-17 20:04:19 -0800 | [diff] [blame] | 373 | EXPECT_FALSE(CheckUpdate()); |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 374 | std::generate(clear_data_.begin(), clear_data_.end(), float_rand); |
| 375 | orig_data_ = clear_data_; |
Alejandro Luebs | 3234819 | 2016-02-17 20:04:19 -0800 | [diff] [blame] | 376 | EXPECT_FALSE(CheckUpdate()); |
| 377 | std::generate(clear_data_.begin(), clear_data_.end(), float_rand); |
| 378 | orig_data_ = clear_data_; |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 379 | std::generate(noise_data_.begin(), noise_data_.end(), float_rand); |
| 380 | FloatToFloatS16(noise_data_.data(), noise_data_.size(), noise_data_.data()); |
Alejandro Luebs | 3234819 | 2016-02-17 20:04:19 -0800 | [diff] [blame] | 381 | EXPECT_TRUE(CheckUpdate()); |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | // Tests ERB bank creation, comparing against matlab output. |
| 385 | TEST_F(IntelligibilityEnhancerTest, TestErbCreation) { |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 386 | ASSERT_EQ(arraysize(kTestCenterFreqs), enh_->bank_size_); |
| 387 | for (size_t i = 0; i < enh_->bank_size_; ++i) { |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 388 | EXPECT_NEAR(kTestCenterFreqs[i], enh_->center_freqs_[i], kMaxTestError); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 389 | ASSERT_EQ(arraysize(kTestFilterBank[0]), enh_->freqs_); |
| 390 | for (size_t j = 0; j < enh_->freqs_; ++j) { |
aluebs | c466bad | 2016-02-10 12:03:00 -0800 | [diff] [blame] | 391 | EXPECT_NEAR(kTestFilterBank[i][j], enh_->render_filter_bank_[i][j], |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 392 | kMaxTestError); |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | // Tests analytic solution for optimal gains, comparing |
| 398 | // against matlab output. |
| 399 | TEST_F(IntelligibilityEnhancerTest, TestSolveForGains) { |
ekmeyerson | 60d9b33 | 2015-08-14 10:35:55 -0700 | [diff] [blame] | 400 | ASSERT_EQ(kTestStartFreq, enh_->start_freq_); |
Alejandro Luebs | 3234819 | 2016-02-17 20:04:19 -0800 | [diff] [blame] | 401 | std::vector<float> sols(enh_->bank_size_); |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 402 | float lambda = -0.001f; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 403 | for (size_t i = 0; i < enh_->bank_size_; i++) { |
Alejandro Luebs | 18fcbcf | 2016-02-22 15:57:38 -0800 | [diff] [blame] | 404 | enh_->filtered_clear_pow_[i] = 0.f; |
| 405 | enh_->filtered_noise_pow_[i] = 0.f; |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 406 | } |
aluebs | 0a00759 | 2016-02-26 17:17:38 -0800 | [diff] [blame] | 407 | enh_->SolveForGainsGivenLambda(lambda, enh_->start_freq_, sols.data()); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 408 | for (size_t i = 0; i < enh_->bank_size_; i++) { |
aluebs | f99af6b | 2016-02-24 17:25:42 -0800 | [diff] [blame] | 409 | EXPECT_NEAR(kTestZeroVar, sols[i], kMaxTestError); |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 410 | } |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 411 | for (size_t i = 0; i < enh_->bank_size_; i++) { |
Alejandro Luebs | 3234819 | 2016-02-17 20:04:19 -0800 | [diff] [blame] | 412 | enh_->filtered_clear_pow_[i] = static_cast<float>(i + 1); |
| 413 | enh_->filtered_noise_pow_[i] = static_cast<float>(enh_->bank_size_ - i); |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 414 | } |
aluebs | 0a00759 | 2016-02-26 17:17:38 -0800 | [diff] [blame] | 415 | enh_->SolveForGainsGivenLambda(lambda, enh_->start_freq_, sols.data()); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 416 | for (size_t i = 0; i < enh_->bank_size_; i++) { |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 417 | EXPECT_NEAR(kTestNonZeroVarLambdaTop[i], sols[i], kMaxTestError); |
| 418 | } |
Alejandro Luebs | 18fcbcf | 2016-02-22 15:57:38 -0800 | [diff] [blame] | 419 | lambda = -1.f; |
aluebs | 0a00759 | 2016-02-26 17:17:38 -0800 | [diff] [blame] | 420 | enh_->SolveForGainsGivenLambda(lambda, enh_->start_freq_, sols.data()); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 421 | for (size_t i = 0; i < enh_->bank_size_; i++) { |
aluebs | f99af6b | 2016-02-24 17:25:42 -0800 | [diff] [blame] | 422 | EXPECT_NEAR(kTestNonZeroVarLambdaTop[i], sols[i], kMaxTestError); |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
aluebs | 11d4a42 | 2016-04-28 14:58:32 -0700 | [diff] [blame] | 426 | TEST_F(IntelligibilityEnhancerTest, TestNoiseGainHasExpectedResult) { |
Alejandro Luebs | 5041110 | 2016-06-30 15:35:41 -0700 | [diff] [blame] | 427 | const float kGain = 2.f; |
aluebs | 7bd5f25 | 2016-06-21 11:30:25 -0700 | [diff] [blame] | 428 | const float kTolerance = 0.007f; |
aluebs | 11d4a42 | 2016-04-28 14:58:32 -0700 | [diff] [blame] | 429 | std::vector<float> noise(kNumNoiseBins); |
| 430 | std::vector<float> noise_psd(kNumNoiseBins); |
| 431 | std::generate(noise.begin(), noise.end(), float_rand); |
| 432 | for (size_t i = 0; i < kNumNoiseBins; ++i) { |
Alejandro Luebs | 5041110 | 2016-06-30 15:35:41 -0700 | [diff] [blame] | 433 | noise_psd[i] = kGain * kGain * noise[i] * noise[i]; |
aluebs | 11d4a42 | 2016-04-28 14:58:32 -0700 | [diff] [blame] | 434 | } |
| 435 | float* clear_cursor = clear_data_.data(); |
| 436 | for (size_t i = 0; i < kNumFramesToProcess; ++i) { |
Alejandro Luebs | 5041110 | 2016-06-30 15:35:41 -0700 | [diff] [blame] | 437 | enh_->SetCaptureNoiseEstimate(noise, kGain); |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 438 | clear_buffer_.CopyFrom(&clear_cursor, stream_config_); |
| 439 | enh_->ProcessRenderAudio(&clear_buffer_); |
aluebs | 11d4a42 | 2016-04-28 14:58:32 -0700 | [diff] [blame] | 440 | } |
| 441 | const std::vector<float>& estimated_psd = |
| 442 | enh_->noise_power_estimator_.power(); |
| 443 | for (size_t i = 0; i < kNumNoiseBins; ++i) { |
| 444 | EXPECT_LT(std::abs(estimated_psd[i] - noise_psd[i]) / noise_psd[i], |
| 445 | kTolerance); |
| 446 | } |
| 447 | } |
| 448 | |
Alejandro Luebs | ef00925 | 2016-09-20 14:51:56 -0700 | [diff] [blame] | 449 | TEST_F(IntelligibilityEnhancerTest, TestAllBandsHaveSameDelay) { |
| 450 | const int kTestSampleRate = AudioProcessing::kSampleRate32kHz; |
| 451 | const int kTestSplitRate = AudioProcessing::kSampleRate16kHz; |
| 452 | const size_t kTestNumBands = |
| 453 | rtc::CheckedDivExact(kTestSampleRate, kTestSplitRate); |
| 454 | const size_t kTestFragmentSize = rtc::CheckedDivExact(kTestSampleRate, 100); |
| 455 | const size_t kTestSplitFragmentSize = |
| 456 | rtc::CheckedDivExact(kTestSplitRate, 100); |
| 457 | enh_.reset(new IntelligibilityEnhancer(kTestSplitRate, kNumChannels, |
| 458 | kTestNumBands, kNumNoiseBins)); |
| 459 | size_t initial_delay = enh_->render_mangler_->initial_delay(); |
| 460 | std::vector<float> rand_gen_buf(kTestFragmentSize); |
| 461 | AudioBuffer original_buffer(kTestFragmentSize, kNumChannels, |
| 462 | kTestFragmentSize, kNumChannels, |
| 463 | kTestFragmentSize); |
| 464 | AudioBuffer audio_buffer(kTestFragmentSize, kNumChannels, kTestFragmentSize, |
| 465 | kNumChannels, kTestFragmentSize); |
| 466 | for (size_t i = 0u; i < kTestNumBands; ++i) { |
| 467 | std::generate(rand_gen_buf.begin(), rand_gen_buf.end(), float_rand); |
| 468 | original_buffer.split_data_f()->SetDataForTesting(rand_gen_buf.data(), |
| 469 | rand_gen_buf.size()); |
| 470 | audio_buffer.split_data_f()->SetDataForTesting(rand_gen_buf.data(), |
| 471 | rand_gen_buf.size()); |
| 472 | } |
| 473 | enh_->ProcessRenderAudio(&audio_buffer); |
| 474 | for (size_t i = 0u; i < kTestNumBands; ++i) { |
| 475 | const float* original_ptr = original_buffer.split_bands_const_f(0)[i]; |
| 476 | const float* audio_ptr = audio_buffer.split_bands_const_f(0)[i]; |
| 477 | for (size_t j = initial_delay; j < kTestSplitFragmentSize; ++j) { |
| 478 | EXPECT_LT(std::fabs(original_ptr[j - initial_delay] - audio_ptr[j]), |
| 479 | kMaxTestError); |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | |
peah | 4b0c741 | 2016-03-28 23:43:49 -0700 | [diff] [blame] | 484 | TEST(IntelligibilityEnhancerBitExactnessTest, DISABLED_Mono8kHz) { |
| 485 | const float kOutputReference[] = {-0.001892f, -0.003296f, -0.001953f}; |
| 486 | |
| 487 | RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 1, kOutputReference); |
| 488 | } |
| 489 | |
| 490 | TEST(IntelligibilityEnhancerBitExactnessTest, DISABLED_Mono16kHz) { |
| 491 | const float kOutputReference[] = {-0.000977f, -0.003296f, -0.002441f}; |
| 492 | |
| 493 | RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 1, kOutputReference); |
| 494 | } |
| 495 | |
| 496 | TEST(IntelligibilityEnhancerBitExactnessTest, DISABLED_Mono32kHz) { |
| 497 | const float kOutputReference[] = {0.003021f, -0.011780f, -0.008209f}; |
| 498 | |
| 499 | RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 1, kOutputReference); |
| 500 | } |
| 501 | |
| 502 | TEST(IntelligibilityEnhancerBitExactnessTest, DISABLED_Mono48kHz) { |
| 503 | const float kOutputReference[] = {-0.027696f, -0.026253f, -0.018001f}; |
| 504 | |
| 505 | RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 1, kOutputReference); |
| 506 | } |
| 507 | |
| 508 | TEST(IntelligibilityEnhancerBitExactnessTest, DISABLED_Stereo8kHz) { |
| 509 | const float kOutputReference[] = {0.021454f, 0.035919f, 0.026428f, |
| 510 | -0.000641f, 0.000366f, 0.000641f}; |
| 511 | |
| 512 | RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 2, kOutputReference); |
| 513 | } |
| 514 | |
| 515 | TEST(IntelligibilityEnhancerBitExactnessTest, DISABLED_Stereo16kHz) { |
| 516 | const float kOutputReference[] = {0.021362f, 0.035736f, 0.023895f, |
| 517 | -0.001404f, -0.001465f, 0.000549f}; |
| 518 | |
| 519 | RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 2, kOutputReference); |
| 520 | } |
| 521 | |
| 522 | TEST(IntelligibilityEnhancerBitExactnessTest, DISABLED_Stereo32kHz) { |
| 523 | const float kOutputReference[] = {0.030641f, 0.027406f, 0.028321f, |
| 524 | -0.001343f, -0.004578f, 0.000977f}; |
| 525 | |
| 526 | RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 2, kOutputReference); |
| 527 | } |
| 528 | |
| 529 | TEST(IntelligibilityEnhancerBitExactnessTest, DISABLED_Stereo48kHz) { |
| 530 | const float kOutputReference[] = {-0.009276f, -0.001601f, -0.008255f, |
| 531 | -0.012975f, -0.015940f, -0.017820f}; |
| 532 | |
| 533 | RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 2, kOutputReference); |
| 534 | } |
| 535 | |
ekm | 35b72fb | 2015-07-10 14:11:52 -0700 | [diff] [blame] | 536 | } // namespace webrtc |