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