henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +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 | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_coding/neteq/dsp_helper.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "modules/audio_coding/neteq/audio_multi_vector.h" |
| 14 | #include "test/gtest.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
| 17 | |
| 18 | TEST(DspHelper, RampSignalArray) { |
| 19 | static const int kLen = 100; |
| 20 | int16_t input[kLen]; |
| 21 | int16_t output[kLen]; |
| 22 | // Fill input with 1000. |
| 23 | for (int i = 0; i < kLen; ++i) { |
| 24 | input[i] = 1000; |
| 25 | } |
| 26 | int start_factor = 0; |
| 27 | // Ramp from 0 to 1 (in Q14) over the array. Note that |increment| is in Q20, |
| 28 | // while the factor is in Q14, hence the shift by 6. |
| 29 | int increment = (16384 << 6) / kLen; |
| 30 | |
| 31 | // Test first method. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 32 | int stop_factor = |
| 33 | DspHelper::RampSignal(input, kLen, start_factor, increment, output); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 34 | EXPECT_EQ(16383, stop_factor); // Almost reach 1 in Q14. |
| 35 | for (int i = 0; i < kLen; ++i) { |
| 36 | EXPECT_EQ(1000 * i / kLen, output[i]); |
| 37 | } |
| 38 | |
| 39 | // Test second method. (Note that this modifies |input|.) |
| 40 | stop_factor = DspHelper::RampSignal(input, kLen, start_factor, increment); |
| 41 | EXPECT_EQ(16383, stop_factor); // Almost reach 1 in Q14. |
| 42 | for (int i = 0; i < kLen; ++i) { |
| 43 | EXPECT_EQ(1000 * i / kLen, input[i]); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | TEST(DspHelper, RampSignalAudioMultiVector) { |
| 48 | static const int kLen = 100; |
| 49 | static const int kChannels = 5; |
henrik.lundin@webrtc.org | fd11bbf | 2013-09-30 20:38:44 +0000 | [diff] [blame] | 50 | AudioMultiVector input(kChannels, kLen * 3); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 51 | // Fill input with 1000. |
| 52 | for (int i = 0; i < kLen * 3; ++i) { |
| 53 | for (int channel = 0; channel < kChannels; ++channel) { |
| 54 | input[channel][i] = 1000; |
| 55 | } |
| 56 | } |
| 57 | // We want to start ramping at |start_index| and keep ramping for |kLen| |
| 58 | // samples. |
| 59 | int start_index = kLen; |
| 60 | int start_factor = 0; |
| 61 | // Ramp from 0 to 1 (in Q14) in |kLen| samples. Note that |increment| is in |
| 62 | // Q20, while the factor is in Q14, hence the shift by 6. |
| 63 | int increment = (16384 << 6) / kLen; |
| 64 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 65 | int stop_factor = |
| 66 | DspHelper::RampSignal(&input, start_index, kLen, start_factor, increment); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 67 | EXPECT_EQ(16383, stop_factor); // Almost reach 1 in Q14. |
| 68 | // Verify that the first |kLen| samples are left untouched. |
| 69 | int i; |
| 70 | for (i = 0; i < kLen; ++i) { |
| 71 | for (int channel = 0; channel < kChannels; ++channel) { |
| 72 | EXPECT_EQ(1000, input[channel][i]); |
| 73 | } |
| 74 | } |
| 75 | // Verify that the next block of |kLen| samples are ramped. |
| 76 | for (; i < 2 * kLen; ++i) { |
| 77 | for (int channel = 0; channel < kChannels; ++channel) { |
| 78 | EXPECT_EQ(1000 * (i - kLen) / kLen, input[channel][i]); |
| 79 | } |
| 80 | } |
| 81 | // Verify the last |kLen| samples are left untouched. |
| 82 | for (; i < 3 * kLen; ++i) { |
| 83 | for (int channel = 0; channel < kChannels; ++channel) { |
| 84 | EXPECT_EQ(1000, input[channel][i]); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | } // namespace webrtc |