| OLD | NEW |
| (Empty) |
| 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 #include "webrtc/modules/audio_processing/agc/gmm.h" | |
| 12 | |
| 13 #include <math.h> | |
| 14 | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 #include "webrtc/modules/audio_processing/agc/noise_gmm_tables.h" | |
| 17 #include "webrtc/modules/audio_processing/agc/voice_gmm_tables.h" | |
| 18 | |
| 19 namespace webrtc { | |
| 20 | |
| 21 TEST(GmmTest, EvaluateGmm) { | |
| 22 GmmParameters noise_gmm; | |
| 23 GmmParameters voice_gmm; | |
| 24 | |
| 25 // Setup noise GMM. | |
| 26 noise_gmm.dimension = kNoiseGmmDim; | |
| 27 noise_gmm.num_mixtures = kNoiseGmmNumMixtures; | |
| 28 noise_gmm.weight = kNoiseGmmWeights; | |
| 29 noise_gmm.mean = &kNoiseGmmMean[0][0]; | |
| 30 noise_gmm.covar_inverse = &kNoiseGmmCovarInverse[0][0][0]; | |
| 31 | |
| 32 // Setup voice GMM. | |
| 33 voice_gmm.dimension = kVoiceGmmDim; | |
| 34 voice_gmm.num_mixtures = kVoiceGmmNumMixtures; | |
| 35 voice_gmm.weight = kVoiceGmmWeights; | |
| 36 voice_gmm.mean = &kVoiceGmmMean[0][0]; | |
| 37 voice_gmm.covar_inverse = &kVoiceGmmCovarInverse[0][0][0]; | |
| 38 | |
| 39 // Test vectors. These are the mean of the GMM means. | |
| 40 const double kXVoice[kVoiceGmmDim] = { | |
| 41 -1.35893162459863, 602.862491970368, 178.022069191324}; | |
| 42 const double kXNoise[kNoiseGmmDim] = { | |
| 43 -2.33443722724409, 2827.97828765184, 141.114178166812}; | |
| 44 | |
| 45 // Expected pdf values. These values are computed in MATLAB using EvalGmm.m | |
| 46 const double kPdfNoise = 1.88904409403101e-07; | |
| 47 const double kPdfVoice = 1.30453996982266e-06; | |
| 48 | |
| 49 // Relative error should be smaller that the following value. | |
| 50 const double kAcceptedRelativeErr = 1e-10; | |
| 51 | |
| 52 // Test Voice. | |
| 53 double pdf = EvaluateGmm(kXVoice, voice_gmm); | |
| 54 EXPECT_GT(pdf, 0); | |
| 55 double relative_error = fabs(pdf - kPdfVoice) / kPdfVoice; | |
| 56 EXPECT_LE(relative_error, kAcceptedRelativeErr); | |
| 57 | |
| 58 // Test Noise. | |
| 59 pdf = EvaluateGmm(kXNoise, noise_gmm); | |
| 60 EXPECT_GT(pdf, 0); | |
| 61 relative_error = fabs(pdf - kPdfNoise) / kPdfNoise; | |
| 62 EXPECT_LE(relative_error, kAcceptedRelativeErr); | |
| 63 } | |
| 64 | |
| 65 } // namespace webrtc | |
| OLD | NEW |