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