blob: ec434a4b1936edcf593cc858cc0b0ea22530e8ba [file] [log] [blame]
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_coding/neteq/dsp_helper.h"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "modules/audio_coding/neteq/audio_multi_vector.h"
14#include "test/gtest.h"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000015
16namespace webrtc {
17
18TEST(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 Gerey665174f2018-06-19 15:03:05 +020032 int stop_factor =
33 DspHelper::RampSignal(input, kLen, start_factor, increment, output);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000034 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
47TEST(DspHelper, RampSignalAudioMultiVector) {
48 static const int kLen = 100;
49 static const int kChannels = 5;
henrik.lundin@webrtc.orgfd11bbf2013-09-30 20:38:44 +000050 AudioMultiVector input(kChannels, kLen * 3);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000051 // 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 Gerey665174f2018-06-19 15:03:05 +020065 int stop_factor =
66 DspHelper::RampSignal(&input, start_index, kLen, start_factor, increment);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000067 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