Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(559)

Side by Side Diff: webrtc/modules/audio_processing/agc/gmm.cc

Issue 1208793002: Revert "Pull the Voice Activity Detector out from the AGC" (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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_processing/vad/gmm.h" 11 #include "webrtc/modules/audio_processing/agc/gmm.h"
12 12
13 #include <math.h> 13 #include <math.h>
14 #include <stdlib.h> 14 #include <stdlib.h>
15 15
16 #include "webrtc/typedefs.h" 16 #include "webrtc/typedefs.h"
17 17
18 namespace webrtc { 18 namespace webrtc {
19 19
20 static const int kMaxDimension = 10; 20 static const int kMaxDimension = 10;
21 21
22 static void RemoveMean(const double* in, 22 static void RemoveMean(const double* in, const double* mean_vec,
23 const double* mean_vec, 23 int dimension, double* out) {
24 int dimension,
25 double* out) {
26 for (int n = 0; n < dimension; ++n) 24 for (int n = 0; n < dimension; ++n)
27 out[n] = in[n] - mean_vec[n]; 25 out[n] = in[n] - mean_vec[n];
28 } 26 }
29 27
30 static double ComputeExponent(const double* in, 28 static double ComputeExponent(const double* in, const double* covar_inv,
31 const double* covar_inv,
32 int dimension) { 29 int dimension) {
33 double q = 0; 30 double q = 0;
34 for (int i = 0; i < dimension; ++i) { 31 for (int i = 0; i < dimension; ++i) {
35 double v = 0; 32 double v = 0;
36 for (int j = 0; j < dimension; j++) 33 for (int j = 0; j < dimension; j++)
37 v += (*covar_inv++) * in[j]; 34 v += (*covar_inv++) * in[j];
38 q += v * in[i]; 35 q += v * in[i];
39 } 36 }
40 q *= -0.5; 37 q *= -0.5;
41 return q; 38 return q;
42 } 39 }
43 40
44 double EvaluateGmm(const double* x, const GmmParameters& gmm_parameters) { 41 double EvaluateGmm(const double* x, const GmmParameters& gmm_parameters) {
45 if (gmm_parameters.dimension > kMaxDimension) { 42 if (gmm_parameters.dimension > kMaxDimension) {
46 return -1; // This is invalid pdf so the caller can check this. 43 return -1; // This is invalid pdf so the caller can check this.
47 } 44 }
48 double f = 0; 45 double f = 0;
49 double v[kMaxDimension]; 46 double v[kMaxDimension];
50 const double* mean_vec = gmm_parameters.mean; 47 const double* mean_vec = gmm_parameters.mean;
51 const double* covar_inv = gmm_parameters.covar_inverse; 48 const double* covar_inv = gmm_parameters.covar_inverse;
52 49
53 for (int n = 0; n < gmm_parameters.num_mixtures; n++) { 50 for (int n = 0; n < gmm_parameters.num_mixtures; n++) {
54 RemoveMean(x, mean_vec, gmm_parameters.dimension, v); 51 RemoveMean(x, mean_vec, gmm_parameters.dimension, v);
55 double q = ComputeExponent(v, covar_inv, gmm_parameters.dimension) + 52 double q = ComputeExponent(v, covar_inv, gmm_parameters.dimension) +
56 gmm_parameters.weight[n]; 53 gmm_parameters.weight[n];
57 f += exp(q); 54 f += exp(q);
58 mean_vec += gmm_parameters.dimension; 55 mean_vec += gmm_parameters.dimension;
59 covar_inv += gmm_parameters.dimension * gmm_parameters.dimension; 56 covar_inv += gmm_parameters.dimension * gmm_parameters.dimension;
60 } 57 }
61 return f; 58 return f;
62 } 59 }
63 60
64 } // namespace webrtc 61 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/agc/gmm.h ('k') | webrtc/modules/audio_processing/agc/gmm_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698