pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_processing/vad/gmm.h" |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 12 | |
| 13 | #include <math.h> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "modules/audio_processing/vad/noise_gmm_tables.h" |
| 16 | #include "modules/audio_processing/vad/voice_gmm_tables.h" |
| 17 | #include "test/gtest.h" |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 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. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 40 | const double kXVoice[kVoiceGmmDim] = {-1.35893162459863, 602.862491970368, |
| 41 | 178.022069191324}; |
| 42 | const double kXNoise[kNoiseGmmDim] = {-2.33443722724409, 2827.97828765184, |
| 43 | 141.114178166812}; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 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 |