1 /*
2 * Copyright (c) 2012 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 // We don't test the value of pitch gain and lags as they are created by iSAC
12 // routines. However, interpolation of pitch-gain and lags is in a separate
13 // class and has its own unit-test.
14
15 #include "modules/audio_processing/vad/vad_audio_proc.h"
16
17 #include <math.h>
18 #include <stdio.h>
19
20 #include <string>
21
22 #include "modules/audio_processing/vad/common.h"
23 #include "test/gtest.h"
24 #include "test/testsupport/file_utils.h"
25
26 namespace webrtc {
27
TEST(AudioProcessingTest,DISABLED_ComputingFirstSpectralPeak)28 TEST(AudioProcessingTest, DISABLED_ComputingFirstSpectralPeak) {
29 VadAudioProc audioproc;
30
31 std::string peak_file_name =
32 test::ResourcePath("audio_processing/agc/agc_spectral_peak", "dat");
33 FILE* peak_file = fopen(peak_file_name.c_str(), "rb");
34 ASSERT_TRUE(peak_file != NULL);
35
36 std::string pcm_file_name =
37 test::ResourcePath("audio_processing/agc/agc_audio", "pcm");
38 FILE* pcm_file = fopen(pcm_file_name.c_str(), "rb");
39 ASSERT_TRUE(pcm_file != NULL);
40
41 // Read 10 ms audio in each iteration.
42 const size_t kDataLength = kLength10Ms;
43 int16_t data[kDataLength] = {0};
44 AudioFeatures features;
45 double sp[kMaxNumFrames];
46 while (fread(data, sizeof(int16_t), kDataLength, pcm_file) == kDataLength) {
47 audioproc.ExtractFeatures(data, kDataLength, &features);
48 if (features.num_frames > 0) {
49 ASSERT_LT(features.num_frames, kMaxNumFrames);
50 // Read reference values.
51 const size_t num_frames = features.num_frames;
52 ASSERT_EQ(num_frames, fread(sp, sizeof(sp[0]), num_frames, peak_file));
53 for (size_t n = 0; n < features.num_frames; n++)
54 EXPECT_NEAR(features.spectral_peak[n], sp[n], 3);
55 }
56 }
57
58 fclose(peak_file);
59 fclose(pcm_file);
60 }
61
62 } // namespace webrtc
63