andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 "testing/gtest/include/gtest/gtest.h" |
| 12 | #include "webrtc/common_audio/include/audio_util.h" |
| 13 | #include "webrtc/typedefs.h" |
| 14 | |
| 15 | namespace webrtc { |
| 16 | |
| 17 | void ExpectArraysEq(const int16_t* ref, const int16_t* test, int length) { |
| 18 | for (int i = 0; i < length; ++i) { |
| 19 | EXPECT_EQ(test[i], ref[i]); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | TEST(AudioUtilTest, InterleavingStereo) { |
| 24 | const int16_t kInterleaved[] = {2, 3, 4, 9, 8, 27, 16, 81}; |
| 25 | const int kSamplesPerChannel = 4; |
| 26 | const int kNumChannels = 2; |
| 27 | const int kLength = kSamplesPerChannel * kNumChannels; |
| 28 | int16_t left[kSamplesPerChannel], right[kSamplesPerChannel]; |
| 29 | int16_t* deinterleaved[] = {left, right}; |
| 30 | Deinterleave(kInterleaved, kSamplesPerChannel, kNumChannels, deinterleaved); |
| 31 | const int16_t kRefLeft[] = {2, 4, 8, 16}; |
| 32 | const int16_t kRefRight[] = {3, 9, 27, 81}; |
| 33 | ExpectArraysEq(left, kRefLeft, kSamplesPerChannel); |
| 34 | ExpectArraysEq(right, kRefRight, kSamplesPerChannel); |
| 35 | |
| 36 | int16_t interleaved[kLength]; |
| 37 | Interleave(deinterleaved, kSamplesPerChannel, kNumChannels, interleaved); |
| 38 | ExpectArraysEq(interleaved, kInterleaved, kLength); |
| 39 | } |
| 40 | |
| 41 | TEST(AudioUtilTest, InterleavingMonoIsIdentical) { |
| 42 | const int16_t kInterleaved[] = {1, 2, 3, 4, 5}; |
| 43 | const int kSamplesPerChannel = 5; |
| 44 | const int kNumChannels = 1; |
| 45 | int16_t mono[kSamplesPerChannel]; |
| 46 | int16_t* deinterleaved[] = {mono}; |
| 47 | Deinterleave(kInterleaved, kSamplesPerChannel, kNumChannels, deinterleaved); |
| 48 | ExpectArraysEq(mono, kInterleaved, kSamplesPerChannel); |
| 49 | |
| 50 | int16_t interleaved[kSamplesPerChannel]; |
| 51 | Interleave(deinterleaved, kSamplesPerChannel, kNumChannels, interleaved); |
| 52 | ExpectArraysEq(interleaved, mono, kSamplesPerChannel); |
| 53 | } |
| 54 | |
| 55 | } // namespace webrtc |