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