| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/common_audio/lapped_transform.h" | 11 #include "webrtc/common_audio/lapped_transform.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <cmath> | 14 #include <cmath> |
| 15 #include <cstring> | 15 #include <cstring> |
| 16 | 16 |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 using std::complex; | 19 using std::complex; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class NoopCallback : public webrtc::LappedTransform::Callback { | 23 class NoopCallback : public webrtc::LappedTransform::Callback { |
| 24 public: | 24 public: |
| 25 NoopCallback() : block_num_(0) {} | 25 NoopCallback() : block_num_(0) {} |
| 26 | 26 |
| 27 virtual void ProcessAudioBlock(const complex<float>* const* in_block, | 27 virtual void ProcessAudioBlock(const complex<float>* const* in_block, |
| 28 int in_channels, | 28 int in_channels, |
| 29 int frames, | 29 size_t frames, |
| 30 int out_channels, | 30 int out_channels, |
| 31 complex<float>* const* out_block) { | 31 complex<float>* const* out_block) { |
| 32 CHECK_EQ(in_channels, out_channels); | 32 CHECK_EQ(in_channels, out_channels); |
| 33 for (int i = 0; i < out_channels; ++i) { | 33 for (int i = 0; i < out_channels; ++i) { |
| 34 memcpy(out_block[i], in_block[i], sizeof(**in_block) * frames); | 34 memcpy(out_block[i], in_block[i], sizeof(**in_block) * frames); |
| 35 } | 35 } |
| 36 ++block_num_; | 36 ++block_num_; |
| 37 } | 37 } |
| 38 | 38 |
| 39 int block_num() { | 39 int block_num() { |
| 40 return block_num_; | 40 return block_num_; |
| 41 } | 41 } |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 int block_num_; | 44 int block_num_; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 class FftCheckerCallback : public webrtc::LappedTransform::Callback { | 47 class FftCheckerCallback : public webrtc::LappedTransform::Callback { |
| 48 public: | 48 public: |
| 49 FftCheckerCallback() : block_num_(0) {} | 49 FftCheckerCallback() : block_num_(0) {} |
| 50 | 50 |
| 51 virtual void ProcessAudioBlock(const complex<float>* const* in_block, | 51 virtual void ProcessAudioBlock(const complex<float>* const* in_block, |
| 52 int in_channels, | 52 int in_channels, |
| 53 int frames, | 53 size_t frames, |
| 54 int out_channels, | 54 int out_channels, |
| 55 complex<float>* const* out_block) { | 55 complex<float>* const* out_block) { |
| 56 CHECK_EQ(in_channels, out_channels); | 56 CHECK_EQ(in_channels, out_channels); |
| 57 | 57 |
| 58 int full_length = (frames - 1) * 2; | 58 size_t full_length = (frames - 1) * 2; |
| 59 ++block_num_; | 59 ++block_num_; |
| 60 | 60 |
| 61 if (block_num_ > 0) { | 61 if (block_num_ > 0) { |
| 62 ASSERT_NEAR(in_block[0][0].real(), static_cast<float>(full_length), | 62 ASSERT_NEAR(in_block[0][0].real(), static_cast<float>(full_length), |
| 63 1e-5f); | 63 1e-5f); |
| 64 ASSERT_NEAR(in_block[0][0].imag(), 0.0f, 1e-5f); | 64 ASSERT_NEAR(in_block[0][0].imag(), 0.0f, 1e-5f); |
| 65 for (int i = 1; i < frames; ++i) { | 65 for (size_t i = 1; i < frames; ++i) { |
| 66 ASSERT_NEAR(in_block[0][i].real(), 0.0f, 1e-5f); | 66 ASSERT_NEAR(in_block[0][i].real(), 0.0f, 1e-5f); |
| 67 ASSERT_NEAR(in_block[0][i].imag(), 0.0f, 1e-5f); | 67 ASSERT_NEAR(in_block[0][i].imag(), 0.0f, 1e-5f); |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 int block_num() { | 72 int block_num() { |
| 73 return block_num_; | 73 return block_num_; |
| 74 } | 74 } |
| 75 | 75 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } | 183 } |
| 184 | 184 |
| 185 TEST(LappedTransformTest, chunk_length) { | 185 TEST(LappedTransformTest, chunk_length) { |
| 186 const int kBlockLength = 64; | 186 const int kBlockLength = 64; |
| 187 FftCheckerCallback call; | 187 FftCheckerCallback call; |
| 188 const float window[kBlockLength] = {}; | 188 const float window[kBlockLength] = {}; |
| 189 | 189 |
| 190 // Make sure that chunk_length returns the same value passed to the | 190 // Make sure that chunk_length returns the same value passed to the |
| 191 // LappedTransform constructor. | 191 // LappedTransform constructor. |
| 192 { | 192 { |
| 193 const int kExpectedChunkLength = 512; | 193 const size_t kExpectedChunkLength = 512; |
| 194 const LappedTransform trans(1, 1, kExpectedChunkLength, window, | 194 const LappedTransform trans(1, 1, kExpectedChunkLength, window, |
| 195 kBlockLength, kBlockLength, &call); | 195 kBlockLength, kBlockLength, &call); |
| 196 | 196 |
| 197 EXPECT_EQ(kExpectedChunkLength, trans.chunk_length()); | 197 EXPECT_EQ(kExpectedChunkLength, trans.chunk_length()); |
| 198 } | 198 } |
| 199 { | 199 { |
| 200 const int kExpectedChunkLength = 160; | 200 const size_t kExpectedChunkLength = 160; |
| 201 const LappedTransform trans(1, 1, kExpectedChunkLength, window, | 201 const LappedTransform trans(1, 1, kExpectedChunkLength, window, |
| 202 kBlockLength, kBlockLength, &call); | 202 kBlockLength, kBlockLength, &call); |
| 203 | 203 |
| 204 EXPECT_EQ(kExpectedChunkLength, trans.chunk_length()); | 204 EXPECT_EQ(kExpectedChunkLength, trans.chunk_length()); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 } // namespace webrtc | 208 } // namespace webrtc |
| OLD | NEW |