| 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/modules/audio_coding/neteq/audio_classifier.h" | 11 #include "webrtc/modules/audio_coding/neteq/audio_classifier.h" |
| 12 | 12 |
| 13 #include <math.h> | 13 #include <math.h> |
| 14 #include <stdio.h> | 14 #include <stdio.h> |
| 15 #include <stdlib.h> | 15 #include <stdlib.h> |
| 16 #include <string.h> | 16 #include <string.h> |
| 17 #include <memory> |
| 17 #include <string> | 18 #include <string> |
| 18 | 19 |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "webrtc/test/testsupport/fileutils.h" | 21 #include "webrtc/test/testsupport/fileutils.h" |
| 21 | 22 |
| 22 namespace webrtc { | 23 namespace webrtc { |
| 23 | 24 |
| 24 static const size_t kFrameSize = 960; | 25 static const size_t kFrameSize = 960; |
| 25 | 26 |
| 26 TEST(AudioClassifierTest, AllZeroInput) { | 27 TEST(AudioClassifierTest, AllZeroInput) { |
| 27 int16_t in_mono[kFrameSize] = {0}; | 28 int16_t in_mono[kFrameSize] = {0}; |
| 28 | 29 |
| 29 // Test all-zero vectors and let the classifier converge from its default | 30 // Test all-zero vectors and let the classifier converge from its default |
| 30 // to the expected value. | 31 // to the expected value. |
| 31 AudioClassifier zero_classifier; | 32 AudioClassifier zero_classifier; |
| 32 for (int i = 0; i < 100; ++i) { | 33 for (int i = 0; i < 100; ++i) { |
| 33 zero_classifier.Analysis(in_mono, kFrameSize, 1); | 34 zero_classifier.Analysis(in_mono, kFrameSize, 1); |
| 34 } | 35 } |
| 35 EXPECT_TRUE(zero_classifier.is_music()); | 36 EXPECT_TRUE(zero_classifier.is_music()); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void RunAnalysisTest(const std::string& audio_filename, | 39 void RunAnalysisTest(const std::string& audio_filename, |
| 39 const std::string& data_filename, | 40 const std::string& data_filename, |
| 40 size_t channels) { | 41 size_t channels) { |
| 41 AudioClassifier classifier; | 42 AudioClassifier classifier; |
| 42 rtc::scoped_ptr<int16_t[]> in(new int16_t[channels * kFrameSize]); | 43 std::unique_ptr<int16_t[]> in(new int16_t[channels * kFrameSize]); |
| 43 bool is_music_ref; | 44 bool is_music_ref; |
| 44 | 45 |
| 45 FILE* audio_file = fopen(audio_filename.c_str(), "rb"); | 46 FILE* audio_file = fopen(audio_filename.c_str(), "rb"); |
| 46 ASSERT_TRUE(audio_file != NULL) << "Failed to open file " << audio_filename | 47 ASSERT_TRUE(audio_file != NULL) << "Failed to open file " << audio_filename |
| 47 << std::endl; | 48 << std::endl; |
| 48 FILE* data_file = fopen(data_filename.c_str(), "rb"); | 49 FILE* data_file = fopen(data_filename.c_str(), "rb"); |
| 49 ASSERT_TRUE(audio_file != NULL) << "Failed to open file " << audio_filename | 50 ASSERT_TRUE(audio_file != NULL) << "Failed to open file " << audio_filename |
| 50 << std::endl; | 51 << std::endl; |
| 51 while (fread(in.get(), sizeof(int16_t), channels * kFrameSize, audio_file) == | 52 while (fread(in.get(), sizeof(int16_t), channels * kFrameSize, audio_file) == |
| 52 channels * kFrameSize) { | 53 channels * kFrameSize) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 72 #endif // WEBRTC_ARCH_ARM | 73 #endif // WEBRTC_ARCH_ARM |
| 73 } | 74 } |
| 74 | 75 |
| 75 TEST(AudioClassifierTest, DoAnalysisStereo) { | 76 TEST(AudioClassifierTest, DoAnalysisStereo) { |
| 76 RunAnalysisTest(test::ResourcePath("short_mixed_stereo_48", "pcm"), | 77 RunAnalysisTest(test::ResourcePath("short_mixed_stereo_48", "pcm"), |
| 77 test::ResourcePath("short_mixed_stereo_48", "dat"), | 78 test::ResourcePath("short_mixed_stereo_48", "dat"), |
| 78 2); | 79 2); |
| 79 } | 80 } |
| 80 | 81 |
| 81 } // namespace webrtc | 82 } // namespace webrtc |
| OLD | NEW |