This repository was archived by the owner on Jun 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 269
Expand file tree
/
Copy pathcmn_adapt.c
More file actions
58 lines (44 loc) · 1.59 KB
/
cmn_adapt.c
File metadata and controls
58 lines (44 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* 26-Feb-2016 Zamir Ostroukhov (zamiron@gmail.com)
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef _MSC_VER
#pragma warning (disable: 4244)
#endif
#include "sphinxbase/ckd_alloc.h"
#include "sphinxbase/cmn.h"
void
cmn_adapt(cmn_t *cmn, mfcc_t **incep, int32 varnorm, int32 nfr)
{
int32 i, j;
mfcc_t cep_cur[cmn->veclen]; // is it correctly?
if (nfr <= 0)
return;
for (j = 0; j < cmn->veclen; j++)
{
cep_cur[j] = 0.0f;
for (i = 0; i < nfr; i++)
if ( abs(incep[i][j]) > cep_cur[j] ) { cep_cur[j] = abs(incep[i][j]); }
mfcc_t u_prob = ( cep_cur[j] / cmn->max[j] ) * 0.1f;
if ( u_prob < 0.0f ) { u_prob = 0.0f; }
if ( u_prob > 0.1f ) { u_prob = 0.1f; }
cmn->max[j] = cep_cur[j] * u_prob + cmn->max[j] * (1.0f-u_prob);
}
mfcc_t prob0 = ( cep_cur[0] / cmn->max[0] ) * 0.01f;
if ( prob0 > 0.01 ) { prob0 = 0.01f; }
for (i = 0; i < nfr; i++) {
if ( cep_cur[0] > cmn->max[0] )
cmn->max[0] = cep_cur[0] * prob0 + cmn->max[0] * (1.0f-prob0);
mfcc_t e_prob = incep[i][0] / cmn->max[0] * 0.001f;
for (j = 0; j < cmn->veclen; j++) {
cmn->sum[j] += incep[i][j]; // save compatibility with prior method
cmn->cmn_mean[j] = ( incep[i][j] * e_prob ) + ( cmn->cmn_mean[j] * (1.0f-e_prob) );
incep[i][j] -= cmn->cmn_mean[j];
if (varnorm)
incep[i][j] /= cmn->max[j];
}
++cmn->nframe; // save compatibility with prior method
}
}