Skip to content
This repository was archived by the owner on Jun 9, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion include/sphinxbase/cmn.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ extern "C" {
typedef enum cmn_type_e {
CMN_NONE = 0,
CMN_CURRENT,
CMN_PRIOR
CMN_PRIOR,
CMN_ADAPT
} cmn_type_t;

/** String representations of cmn_type_t values. */
Expand All @@ -127,6 +128,7 @@ cmn_type_t cmn_type_from_str(const char *str);

typedef struct {
mfcc_t *cmn_mean; /**< Temporary variable: current means */
mfcc_t *max; /**< Temporary variable: current maximums */
mfcc_t *cmn_var; /**< Temporary variables: stored the cmn variance */
mfcc_t *sum; /**< The sum of the cmn frames */
int32 nframe; /**< Number of frames */
Expand Down Expand Up @@ -184,6 +186,18 @@ void cmn_prior_get(cmn_t *cmn, mfcc_t *vec);
SPHINXBASE_EXPORT
void cmn_free (cmn_t *cmn);

/**
* CMN for one block of data, using adapted mean
*/
SPHINXBASE_EXPORT
void cmn_adapt(cmn_t *cmn, /**< In/Out: cmn normalization, which contains
the cmn_mean and cmn_var) */
mfcc_t **incep, /**< In/Out: mfc[f] = mfc vector in frame f*/
int32 varnorm, /**< varnorm is supported */
int32 nfr /**< Number of incoming frames */
);


#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions include/sphinxbase/feat.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ extern "C" {
{ "-cmn", \
ARG_STRING, \
"current", \
"Cepstral mean normalization scheme ('current', 'prior', or 'none')" }, \
"Cepstral mean normalization scheme ('current', 'prior', 'adapt' or 'none')" }, \
{ "-cmninit", \
ARG_STRING, \
"8.0", \
"Initial values (comma-separated) for cepstral mean when 'prior' is used" }, \
"Initial values (comma-separated) for cepstral mean when 'prior' or 'adapt' is used" }, \
{ "-varnorm", \
ARG_BOOLEAN, \
"no", \
"Variance normalize each utterance (only if CMN == current)" }, \
"Variance normalize each utterance (only if CMN == 'current' or 'adapt')" }, \
{ "-agc", \
ARG_STRING, \
"none", \
Expand Down
1 change: 1 addition & 0 deletions src/libsphinxbase/feat/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ libsphinxfeat_la_SOURCES = \
agc.c \
cmn.c \
cmn_prior.c \
cmn_adapt.c \
lda.c \
feat.c

Expand Down
8 changes: 7 additions & 1 deletion src/libsphinxbase/feat/cmn.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
const char *cmn_type_str[] = {
"none",
"current",
"prior"
"prior",
"adapt"
};
static const int n_cmn_type_str = sizeof(cmn_type_str)/sizeof(cmn_type_str[0]);

Expand All @@ -136,8 +137,10 @@ cmn_init(int32 veclen)
cmn->cmn_mean = (mfcc_t *) ckd_calloc(veclen, sizeof(mfcc_t));
cmn->cmn_var = (mfcc_t *) ckd_calloc(veclen, sizeof(mfcc_t));
cmn->sum = (mfcc_t *) ckd_calloc(veclen, sizeof(mfcc_t));
cmn->max = (mfcc_t *) ckd_calloc(veclen, sizeof(mfcc_t));
/* A front-end dependent magic number */
cmn->cmn_mean[0] = FLOAT2MFCC(12.0);
cmn->max[0] = FLOAT2MFCC(24.0);
cmn->nframe = 0;
E_INFO("mean[0]= %.2f, mean[1..%d]= 0.0\n",
MFCC2FLOAT(cmn->cmn_mean[0]), veclen - 1);
Expand Down Expand Up @@ -233,6 +236,9 @@ cmn_free(cmn_t * cmn)
if (cmn->sum)
ckd_free((void *) cmn->sum);

if (cmn->max)
ckd_free((void *) cmn->max);

ckd_free((void *) cmn);
}
}
58 changes: 58 additions & 0 deletions src/libsphinxbase/feat/cmn_adapt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 26-Feb-2016 Zamir Ostroukhov ([email protected])
*/

#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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add curly braces.

return;

for (j = 0; j < cmn->veclen; j++)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put on the same line as the for statement.

cep_cur[j] = 0.0f;
for (i = 0; i < nfr; i++)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curly braces.

if ( abs(incep[i][j]) > cep_cur[j] ) { cep_cur[j] = abs(incep[i][j]); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No one-line if.


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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does 0.001f mean here. Also please note that mfcc_t can be a fixed point number (int) in fixed point mode, floating point operation is not easy here.


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
}
}
4 changes: 3 additions & 1 deletion src/libsphinxbase/feat/feat.c
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ feat_cmn(feat_t *fcb, mfcc_t **mfc, int32 nfr, int32 beginutt, int32 endutt)
cmn_type_t cmn_type = fcb->cmn;

if (!(beginutt && endutt)
&& cmn_type != CMN_NONE) /* Only cmn_prior in block computation mode. */
&& cmn_type != CMN_NONE && cmn_type != CMN_ADAPT ) /* Only cmn_prior in block computation mode. */
fcb->cmn = cmn_type = CMN_PRIOR;

switch (cmn_type) {
Expand All @@ -929,6 +929,8 @@ feat_cmn(feat_t *fcb, mfcc_t **mfc, int32 nfr, int32 beginutt, int32 endutt)
cmn_prior(fcb->cmn_struct, mfc, fcb->varnorm, nfr);
if (endutt)
cmn_prior_update(fcb->cmn_struct);
case CMN_ADAPT:
cmn_adapt(fcb->cmn_struct, mfc, fcb->varnorm, nfr);
break;
default:
;
Expand Down
8 changes: 6 additions & 2 deletions win32/sphinxbase/sphinxbase.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<AdditionalIncludeDirectories>../../include/win32;../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;_USRDLL;SPHINX_DLL;SPHINXBASE_EXPORTS;HAVE_CONFIG_H;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_USRDLL;SPHINXBASE_EXPORTS;HAVE_CONFIG_H;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeaderOutputFile>.\$(Configuration)\$(Platform)/sphinxbase.pch</PrecompiledHeaderOutputFile>
Expand Down Expand Up @@ -102,7 +102,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../../include/win32;../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;_USRDLL;SPHINX_DLL;SPHINXBASE_EXPORTS;HAVE_CONFIG_H;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;_USRDLL;SPHINXBASE_EXPORTS;HAVE_CONFIG_H;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
Expand Down Expand Up @@ -137,6 +137,7 @@
<ClCompile Include="..\..\src\libsphinxbase\feat\agc.c" />
<ClCompile Include="..\..\src\libsphinxbase\feat\cmn.c" />
<ClCompile Include="..\..\src\libsphinxbase\feat\cmn_prior.c" />
<ClCompile Include="..\..\src\libsphinxbase\feat\cmn_adapt.c" />
<ClCompile Include="..\..\src\libsphinxbase\feat\feat.c" />
<ClCompile Include="..\..\src\libsphinxbase\feat\lda.c" />
<ClCompile Include="..\..\src\libsphinxbase\fe\fe_interface.c" />
Expand Down Expand Up @@ -174,6 +175,7 @@
<ClCompile Include="..\..\src\libsphinxbase\util\glist.c" />
<ClCompile Include="..\..\src\libsphinxbase\util\hash_table.c" />
<ClCompile Include="..\..\src\libsphinxbase\util\heap.c" />
<ClCompile Include="..\..\src\libsphinxbase\util\huff_code.c" />
<ClCompile Include="..\..\src\libsphinxbase\util\listelem_alloc.c" />
<ClCompile Include="..\..\src\libsphinxbase\util\logmath.c" />
<ClCompile Include="..\..\src\libsphinxbase\util\matrix.c" />
Expand Down Expand Up @@ -209,11 +211,13 @@
<ClInclude Include="..\..\include\sphinxbase\glist.h" />
<ClInclude Include="..\..\include\sphinxbase\hash_table.h" />
<ClInclude Include="..\..\include\sphinxbase\heap.h" />
<ClInclude Include="..\..\include\sphinxbase\huff_code.h" />
<ClInclude Include="..\..\include\sphinxbase\jsgf.h" />
<ClInclude Include="..\..\include\sphinxbase\logmath.h" />
<ClInclude Include="..\..\include\sphinxbase\listelem_alloc.h" />
<ClInclude Include="..\..\include\sphinxbase\matrix.h" />
<ClInclude Include="..\..\include\sphinxbase\mmio.h" />
<ClInclude Include="..\..\include\sphinxbase\mulaw.h" />
<ClInclude Include="..\..\include\sphinxbase\ngram_model.h" />
<ClInclude Include="..\..\include\sphinxbase\pio.h" />
<ClInclude Include="..\..\include\sphinxbase\prim_type.h" />
Expand Down
12 changes: 12 additions & 0 deletions win32/sphinxbase/sphinxbase.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<ClCompile Include="..\..\src\libsphinxbase\feat\cmn_prior.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\libsphinxbase\feat\cmn_adapt.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\libsphinxbase\util\dtoa.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -86,6 +89,9 @@
<ClCompile Include="..\..\src\libsphinxbase\util\heap.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\libsphinxbase\util\huff_code.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\libsphinxbase\lm\jsgf.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -247,6 +253,9 @@
<ClInclude Include="..\..\include\sphinxbase\heap.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\sphinxbase\huff_code.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\sphinxbase\jsgf.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand All @@ -271,6 +280,9 @@
<ClInclude Include="..\..\include\sphinxbase\mmio.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\sphinxbase\mulaw.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\sphinxbase\ngram_model.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down