| 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, int frames, int out_channels, | 28 int in_channels, |
| 29 int frames, |
| 30 int out_channels, |
| 29 complex<float>* const* out_block) { | 31 complex<float>* const* out_block) { |
| 30 CHECK_EQ(in_channels, out_channels); | 32 CHECK_EQ(in_channels, out_channels); |
| 31 for (int i = 0; i < out_channels; ++i) { | 33 for (int i = 0; i < out_channels; ++i) { |
| 32 memcpy(out_block[i], in_block[i], sizeof(**in_block) * frames); | 34 memcpy(out_block[i], in_block[i], sizeof(**in_block) * frames); |
| 33 } | 35 } |
| 34 ++block_num_; | 36 ++block_num_; |
| 35 } | 37 } |
| 36 | 38 |
| 37 int block_num() { | 39 int block_num() { |
| 38 return block_num_; | 40 return block_num_; |
| 39 } | 41 } |
| 40 | 42 |
| 41 private: | 43 private: |
| 42 int block_num_; | 44 int block_num_; |
| 43 }; | 45 }; |
| 44 | 46 |
| 45 class FftCheckerCallback : public webrtc::LappedTransform::Callback { | 47 class FftCheckerCallback : public webrtc::LappedTransform::Callback { |
| 46 public: | 48 public: |
| 47 FftCheckerCallback() : block_num_(0) {} | 49 FftCheckerCallback() : block_num_(0) {} |
| 48 | 50 |
| 49 virtual void ProcessAudioBlock(const complex<float>* const* in_block, | 51 virtual void ProcessAudioBlock(const complex<float>* const* in_block, |
| 50 int in_channels, int frames, int out_channels, | 52 int in_channels, |
| 53 int frames, |
| 54 int out_channels, |
| 51 complex<float>* const* out_block) { | 55 complex<float>* const* out_block) { |
| 52 CHECK_EQ(in_channels, out_channels); | 56 CHECK_EQ(in_channels, out_channels); |
| 53 | 57 |
| 54 int full_length = (frames - 1) * 2; | 58 int full_length = (frames - 1) * 2; |
| 55 ++block_num_; | 59 ++block_num_; |
| 56 | 60 |
| 57 if (block_num_ > 0) { | 61 if (block_num_ > 0) { |
| 58 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), |
| 59 1e-5f); | 63 1e-5f); |
| 60 ASSERT_NEAR(in_block[0][0].imag(), 0.0f, 1e-5f); | 64 ASSERT_NEAR(in_block[0][0].imag(), 0.0f, 1e-5f); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 { | 199 { |
| 196 const int kExpectedChunkLength = 160; | 200 const int kExpectedChunkLength = 160; |
| 197 const LappedTransform trans(1, 1, kExpectedChunkLength, window, | 201 const LappedTransform trans(1, 1, kExpectedChunkLength, window, |
| 198 kBlockLength, kBlockLength, &call); | 202 kBlockLength, kBlockLength, &call); |
| 199 | 203 |
| 200 EXPECT_EQ(kExpectedChunkLength, trans.chunk_length()); | 204 EXPECT_EQ(kExpectedChunkLength, trans.chunk_length()); |
| 201 } | 205 } |
| 202 } | 206 } |
| 203 | 207 |
| 204 } // namespace webrtc | 208 } // namespace webrtc |
| OLD | NEW |