andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | |
Mirko Bonadei | f0b8dee | 2019-03-15 10:47:11 +0100 | [diff] [blame] | 11 | #include <cmath> |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 12 | |
Fredrik Solenberg | a8b7c7f | 2018-01-17 11:18:31 +0100 | [diff] [blame] | 13 | #include "audio/remix_resample.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "common_audio/resampler/include/push_resampler.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "rtc_base/arraysize.h" |
Fredrik Solenberg | bbf21a3 | 2018-04-12 22:44:09 +0200 | [diff] [blame] | 16 | #include "rtc_base/checks.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "rtc_base/format_macros.h" |
| 18 | #include "test/gtest.h" |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | namespace voe { |
| 22 | namespace { |
| 23 | |
andrew@webrtc.org | a78a41f | 2014-04-08 23:09:28 +0000 | [diff] [blame] | 24 | class UtilityTest : public ::testing::Test { |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 25 | protected: |
andrew@webrtc.org | a78a41f | 2014-04-08 23:09:28 +0000 | [diff] [blame] | 26 | UtilityTest() { |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 27 | src_frame_.sample_rate_hz_ = 16000; |
| 28 | src_frame_.samples_per_channel_ = src_frame_.sample_rate_hz_ / 100; |
| 29 | src_frame_.num_channels_ = 1; |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 30 | dst_frame_.CopyFrom(src_frame_); |
| 31 | golden_frame_.CopyFrom(src_frame_); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Alejandro Luebs | cdfe20b | 2015-09-23 12:49:12 -0700 | [diff] [blame] | 34 | void RunResampleTest(int src_channels, |
| 35 | int src_sample_rate_hz, |
| 36 | int dst_channels, |
| 37 | int dst_sample_rate_hz); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 38 | |
andrew@webrtc.org | f5a33f1 | 2014-04-19 00:32:07 +0000 | [diff] [blame] | 39 | PushResampler<int16_t> resampler_; |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 40 | AudioFrame src_frame_; |
| 41 | AudioFrame dst_frame_; |
| 42 | AudioFrame golden_frame_; |
| 43 | }; |
| 44 | |
| 45 | // Sets the signal value to increase by |data| with every sample. Floats are |
| 46 | // used so non-integer values result in rounding error, but not an accumulating |
| 47 | // error. |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 48 | void SetMonoFrame(float data, int sample_rate_hz, AudioFrame* frame) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 49 | frame->Mute(); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 50 | frame->num_channels_ = 1; |
| 51 | frame->sample_rate_hz_ = sample_rate_hz; |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 52 | frame->samples_per_channel_ = rtc::CheckedDivExact(sample_rate_hz, 100); |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 53 | int16_t* frame_data = frame->mutable_data(); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 54 | for (size_t i = 0; i < frame->samples_per_channel_; i++) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 55 | frame_data[i] = static_cast<int16_t>(data * i); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
| 59 | // Keep the existing sample rate. |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 60 | void SetMonoFrame(float data, AudioFrame* frame) { |
| 61 | SetMonoFrame(data, frame->sample_rate_hz_, frame); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | // Sets the signal value to increase by |left| and |right| with every sample in |
| 65 | // each channel respectively. |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 66 | void SetStereoFrame(float left, |
| 67 | float right, |
| 68 | int sample_rate_hz, |
| 69 | AudioFrame* frame) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 70 | frame->Mute(); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 71 | frame->num_channels_ = 2; |
| 72 | frame->sample_rate_hz_ = sample_rate_hz; |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 73 | frame->samples_per_channel_ = rtc::CheckedDivExact(sample_rate_hz, 100); |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 74 | int16_t* frame_data = frame->mutable_data(); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 75 | for (size_t i = 0; i < frame->samples_per_channel_; i++) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 76 | frame_data[i * 2] = static_cast<int16_t>(left * i); |
| 77 | frame_data[i * 2 + 1] = static_cast<int16_t>(right * i); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
| 81 | // Keep the existing sample rate. |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 82 | void SetStereoFrame(float left, float right, AudioFrame* frame) { |
| 83 | SetStereoFrame(left, right, frame->sample_rate_hz_, frame); |
| 84 | } |
| 85 | |
| 86 | // Sets the signal value to increase by |ch1|, |ch2|, |ch3|, |ch4| with every |
| 87 | // sample in each channel respectively. |
| 88 | void SetQuadFrame(float ch1, |
| 89 | float ch2, |
| 90 | float ch3, |
| 91 | float ch4, |
| 92 | int sample_rate_hz, |
| 93 | AudioFrame* frame) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 94 | frame->Mute(); |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 95 | frame->num_channels_ = 4; |
| 96 | frame->sample_rate_hz_ = sample_rate_hz; |
| 97 | frame->samples_per_channel_ = rtc::CheckedDivExact(sample_rate_hz, 100); |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 98 | int16_t* frame_data = frame->mutable_data(); |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 99 | for (size_t i = 0; i < frame->samples_per_channel_; i++) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 100 | frame_data[i * 4] = static_cast<int16_t>(ch1 * i); |
| 101 | frame_data[i * 4 + 1] = static_cast<int16_t>(ch2 * i); |
| 102 | frame_data[i * 4 + 2] = static_cast<int16_t>(ch3 * i); |
| 103 | frame_data[i * 4 + 3] = static_cast<int16_t>(ch4 * i); |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 104 | } |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void VerifyParams(const AudioFrame& ref_frame, const AudioFrame& test_frame) { |
| 108 | EXPECT_EQ(ref_frame.num_channels_, test_frame.num_channels_); |
| 109 | EXPECT_EQ(ref_frame.samples_per_channel_, test_frame.samples_per_channel_); |
| 110 | EXPECT_EQ(ref_frame.sample_rate_hz_, test_frame.sample_rate_hz_); |
| 111 | } |
| 112 | |
| 113 | // Computes the best SNR based on the error between |ref_frame| and |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 114 | // |test_frame|. It allows for up to a |max_delay| in samples between the |
| 115 | // signals to compensate for the resampling delay. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 116 | float ComputeSNR(const AudioFrame& ref_frame, |
| 117 | const AudioFrame& test_frame, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 118 | size_t max_delay) { |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 119 | VerifyParams(ref_frame, test_frame); |
| 120 | float best_snr = 0; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 121 | size_t best_delay = 0; |
| 122 | for (size_t delay = 0; delay <= max_delay; delay++) { |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 123 | float mse = 0; |
| 124 | float variance = 0; |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 125 | const int16_t* ref_frame_data = ref_frame.data(); |
| 126 | const int16_t* test_frame_data = test_frame.data(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 127 | for (size_t i = 0; |
| 128 | i < ref_frame.samples_per_channel_ * ref_frame.num_channels_ - delay; |
| 129 | i++) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 130 | int error = ref_frame_data[i] - test_frame_data[i + delay]; |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 131 | mse += error * error; |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 132 | variance += ref_frame_data[i] * ref_frame_data[i]; |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 133 | } |
| 134 | float snr = 100; // We assign 100 dB to the zero-error case. |
| 135 | if (mse > 0) |
Mirko Bonadei | f0b8dee | 2019-03-15 10:47:11 +0100 | [diff] [blame] | 136 | snr = 10 * std::log10(variance / mse); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 137 | if (snr > best_snr) { |
| 138 | best_snr = snr; |
| 139 | best_delay = delay; |
| 140 | } |
| 141 | } |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 142 | printf("SNR=%.1f dB at delay=%" PRIuS "\n", best_snr, best_delay); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 143 | return best_snr; |
| 144 | } |
| 145 | |
| 146 | void VerifyFramesAreEqual(const AudioFrame& ref_frame, |
| 147 | const AudioFrame& test_frame) { |
| 148 | VerifyParams(ref_frame, test_frame); |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 149 | const int16_t* ref_frame_data = ref_frame.data(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 150 | const int16_t* test_frame_data = test_frame.data(); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 151 | for (size_t i = 0; |
| 152 | i < ref_frame.samples_per_channel_ * ref_frame.num_channels_; i++) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 153 | EXPECT_EQ(ref_frame_data[i], test_frame_data[i]); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
andrew@webrtc.org | a78a41f | 2014-04-08 23:09:28 +0000 | [diff] [blame] | 157 | void UtilityTest::RunResampleTest(int src_channels, |
andrew@webrtc.org | f5a33f1 | 2014-04-19 00:32:07 +0000 | [diff] [blame] | 158 | int src_sample_rate_hz, |
| 159 | int dst_channels, |
Alejandro Luebs | cdfe20b | 2015-09-23 12:49:12 -0700 | [diff] [blame] | 160 | int dst_sample_rate_hz) { |
andrew@webrtc.org | f5a33f1 | 2014-04-19 00:32:07 +0000 | [diff] [blame] | 161 | PushResampler<int16_t> resampler; // Create a new one with every test. |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 162 | const int16_t kSrcCh1 = 30; // Shouldn't overflow for any used sample rate. |
| 163 | const int16_t kSrcCh2 = 15; |
| 164 | const int16_t kSrcCh3 = 22; |
| 165 | const int16_t kSrcCh4 = 8; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 166 | const float resampling_factor = |
| 167 | (1.0 * src_sample_rate_hz) / dst_sample_rate_hz; |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 168 | const float dst_ch1 = resampling_factor * kSrcCh1; |
| 169 | const float dst_ch2 = resampling_factor * kSrcCh2; |
| 170 | const float dst_ch3 = resampling_factor * kSrcCh3; |
| 171 | const float dst_ch4 = resampling_factor * kSrcCh4; |
| 172 | const float dst_stereo_to_mono = (dst_ch1 + dst_ch2) / 2; |
| 173 | const float dst_quad_to_mono = (dst_ch1 + dst_ch2 + dst_ch3 + dst_ch4) / 4; |
| 174 | const float dst_quad_to_stereo_ch1 = (dst_ch1 + dst_ch2) / 2; |
| 175 | const float dst_quad_to_stereo_ch2 = (dst_ch3 + dst_ch4) / 2; |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 176 | if (src_channels == 1) |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 177 | SetMonoFrame(kSrcCh1, src_sample_rate_hz, &src_frame_); |
| 178 | else if (src_channels == 2) |
| 179 | SetStereoFrame(kSrcCh1, kSrcCh2, src_sample_rate_hz, &src_frame_); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 180 | else |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 181 | SetQuadFrame(kSrcCh1, kSrcCh2, kSrcCh3, kSrcCh4, src_sample_rate_hz, |
| 182 | &src_frame_); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 183 | |
| 184 | if (dst_channels == 1) { |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 185 | SetMonoFrame(0, dst_sample_rate_hz, &dst_frame_); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 186 | if (src_channels == 1) |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 187 | SetMonoFrame(dst_ch1, dst_sample_rate_hz, &golden_frame_); |
| 188 | else if (src_channels == 2) |
| 189 | SetMonoFrame(dst_stereo_to_mono, dst_sample_rate_hz, &golden_frame_); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 190 | else |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 191 | SetMonoFrame(dst_quad_to_mono, dst_sample_rate_hz, &golden_frame_); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 192 | } else { |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 193 | SetStereoFrame(0, 0, dst_sample_rate_hz, &dst_frame_); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 194 | if (src_channels == 1) |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 195 | SetStereoFrame(dst_ch1, dst_ch1, dst_sample_rate_hz, &golden_frame_); |
| 196 | else if (src_channels == 2) |
| 197 | SetStereoFrame(dst_ch1, dst_ch2, dst_sample_rate_hz, &golden_frame_); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 198 | else |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 199 | SetStereoFrame(dst_quad_to_stereo_ch1, dst_quad_to_stereo_ch2, |
| 200 | dst_sample_rate_hz, &golden_frame_); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 201 | } |
| 202 | |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 203 | // The sinc resampler has a known delay, which we compute here. Multiplying by |
| 204 | // two gives us a crude maximum for any resampling, as the old resampler |
| 205 | // typically (but not always) has lower delay. |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 206 | static const size_t kInputKernelDelaySamples = 16; |
| 207 | const size_t max_delay = static_cast<size_t>( |
| 208 | static_cast<double>(dst_sample_rate_hz) / src_sample_rate_hz * |
| 209 | kInputKernelDelaySamples * dst_channels * 2); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 210 | printf("(%d, %d Hz) -> (%d, %d Hz) ", // SNR reported on the same line later. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 211 | src_channels, src_sample_rate_hz, dst_channels, dst_sample_rate_hz); |
Alejandro Luebs | cdfe20b | 2015-09-23 12:49:12 -0700 | [diff] [blame] | 212 | RemixAndResample(src_frame_, &resampler, &dst_frame_); |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 213 | |
andrew@webrtc.org | c1eb560 | 2013-06-03 19:00:29 +0000 | [diff] [blame] | 214 | if (src_sample_rate_hz == 96000 && dst_sample_rate_hz == 8000) { |
| 215 | // The sinc resampler gives poor SNR at this extreme conversion, but we |
| 216 | // expect to see this rarely in practice. |
| 217 | EXPECT_GT(ComputeSNR(golden_frame_, dst_frame_, max_delay), 14.0f); |
| 218 | } else { |
| 219 | EXPECT_GT(ComputeSNR(golden_frame_, dst_frame_, max_delay), 46.0f); |
| 220 | } |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 221 | } |
| 222 | |
andrew@webrtc.org | a78a41f | 2014-04-08 23:09:28 +0000 | [diff] [blame] | 223 | TEST_F(UtilityTest, RemixAndResampleCopyFrameSucceeds) { |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 224 | // Stereo -> stereo. |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 225 | SetStereoFrame(10, 10, &src_frame_); |
| 226 | SetStereoFrame(0, 0, &dst_frame_); |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 227 | RemixAndResample(src_frame_, &resampler_, &dst_frame_); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 228 | VerifyFramesAreEqual(src_frame_, dst_frame_); |
| 229 | |
| 230 | // Mono -> mono. |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 231 | SetMonoFrame(20, &src_frame_); |
| 232 | SetMonoFrame(0, &dst_frame_); |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 233 | RemixAndResample(src_frame_, &resampler_, &dst_frame_); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 234 | VerifyFramesAreEqual(src_frame_, dst_frame_); |
| 235 | } |
| 236 | |
andrew@webrtc.org | a78a41f | 2014-04-08 23:09:28 +0000 | [diff] [blame] | 237 | TEST_F(UtilityTest, RemixAndResampleMixingOnlySucceeds) { |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 238 | // Stereo -> mono. |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 239 | SetStereoFrame(0, 0, &dst_frame_); |
| 240 | SetMonoFrame(10, &src_frame_); |
| 241 | SetStereoFrame(10, 10, &golden_frame_); |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 242 | RemixAndResample(src_frame_, &resampler_, &dst_frame_); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 243 | VerifyFramesAreEqual(dst_frame_, golden_frame_); |
| 244 | |
| 245 | // Mono -> stereo. |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 246 | SetMonoFrame(0, &dst_frame_); |
| 247 | SetStereoFrame(10, 20, &src_frame_); |
| 248 | SetMonoFrame(15, &golden_frame_); |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 249 | RemixAndResample(src_frame_, &resampler_, &dst_frame_); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 250 | VerifyFramesAreEqual(golden_frame_, dst_frame_); |
| 251 | } |
| 252 | |
andrew@webrtc.org | a78a41f | 2014-04-08 23:09:28 +0000 | [diff] [blame] | 253 | TEST_F(UtilityTest, RemixAndResampleSucceeds) { |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 254 | const int kSampleRates[] = {8000, 16000, 32000, 44100, 48000, 96000}; |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 255 | const int kSampleRatesSize = arraysize(kSampleRates); |
| 256 | const int kSrcChannels[] = {1, 2, 4}; |
| 257 | const int kSrcChannelsSize = arraysize(kSrcChannels); |
| 258 | const int kDstChannels[] = {1, 2}; |
| 259 | const int kDstChannelsSize = arraysize(kDstChannels); |
| 260 | |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 261 | for (int src_rate = 0; src_rate < kSampleRatesSize; src_rate++) { |
| 262 | for (int dst_rate = 0; dst_rate < kSampleRatesSize; dst_rate++) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 263 | for (int src_channel = 0; src_channel < kSrcChannelsSize; src_channel++) { |
jens.nielsen | 228c268 | 2017-03-01 05:11:22 -0800 | [diff] [blame] | 264 | for (int dst_channel = 0; dst_channel < kDstChannelsSize; |
| 265 | dst_channel++) { |
| 266 | RunResampleTest(kSrcChannels[src_channel], kSampleRates[src_rate], |
| 267 | kDstChannels[dst_channel], kSampleRates[dst_rate]); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | } // namespace |
| 275 | } // namespace voe |
| 276 | } // namespace webrtc |