1 /*
2 * Copyright (c) 2014 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 // Unit tests for test InputAudioFile class.
12
13 #include "modules/audio_coding/neteq/tools/input_audio_file.h"
14
15 #include "rtc_base/numerics/safe_conversions.h"
16 #include "test/gtest.h"
17
18 namespace webrtc {
19 namespace test {
20
TEST(TestInputAudioFile,DuplicateInterleaveSeparateSrcDst)21 TEST(TestInputAudioFile, DuplicateInterleaveSeparateSrcDst) {
22 static const size_t kSamples = 10;
23 static const size_t kChannels = 2;
24 int16_t input[kSamples];
25 for (size_t i = 0; i < kSamples; ++i) {
26 input[i] = rtc::checked_cast<int16_t>(i);
27 }
28 int16_t output[kSamples * kChannels];
29 InputAudioFile::DuplicateInterleaved(input, kSamples, kChannels, output);
30
31 // Verify output
32 int16_t* output_ptr = output;
33 for (size_t i = 0; i < kSamples; ++i) {
34 for (size_t j = 0; j < kChannels; ++j) {
35 EXPECT_EQ(static_cast<int16_t>(i), *output_ptr++);
36 }
37 }
38 }
39
TEST(TestInputAudioFile,DuplicateInterleaveSameSrcDst)40 TEST(TestInputAudioFile, DuplicateInterleaveSameSrcDst) {
41 static const size_t kSamples = 10;
42 static const size_t kChannels = 5;
43 int16_t input[kSamples * kChannels];
44 for (size_t i = 0; i < kSamples; ++i) {
45 input[i] = rtc::checked_cast<int16_t>(i);
46 }
47 InputAudioFile::DuplicateInterleaved(input, kSamples, kChannels, input);
48
49 // Verify output
50 int16_t* output_ptr = input;
51 for (size_t i = 0; i < kSamples; ++i) {
52 for (size_t j = 0; j < kChannels; ++j) {
53 EXPECT_EQ(static_cast<int16_t>(i), *output_ptr++);
54 }
55 }
56 }
57
58 } // namespace test
59 } // namespace webrtc
60