📄 wav2mfcc-pipe.c
字号:
/** * @file wav2mfcc-pipe.c * * <JA> * @brief 不兰侨妨から MFCC 泼魔翁へ恃垂する (フレ〖ム帽疤) * * ここでは wav2mfcc.c の簇眶をフレ〖ム票袋に借妄するために恃垂した * 簇眶が羌められていますˉ千急借妄を不兰掐蜗と士乖して乖う眷圭·こちらの * 簇眶が脱いられますˉ * </JA> * * <EN> * @brief Convert speech inputs into MFCC parameter vectors (per input frame) * * There are functions are derived from wav2mfcc.c, to compute * MFCC vectors in per-frame basis. When performing on-line recognition, * these functions will be used instead of ones in wav2mfcc.c * </EN> * * @author Akinobu LEE * @date Thu Feb 17 18:12:30 2005 * * $Revision: 1.3 $ * *//* * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology * Copyright (c) 2005-2007 Julius project team, Nagoya Institute of Technology * All rights reserved *//* wav2mfcc-pipe.c --- split Wav2MFCC to perform per-frame-basis, and also realtime CMN for 1st-pass pipe-lining *//************************************************************************//* wav2mfcc.c Convert Speech file to MFCC_E_D_(Z) file *//*----------------------------------------------------------------------*//* Author : Yuichiro Nakano *//* *//* Copyright(C) Yuichiro Nakano 1996-1998 *//*----------------------------------------------------------------------*//************************************************************************/#include <sent/stddefs.h>#include <sent/mfcc.h>#include <sent/htk_param.h>/***********************************************************************//** * Allocate a new delta cycle buffer. * * @param veclen [in] length of a vector * @param windowlen [in] window width for computing delta * * @return pointer to newly allocated delta cycle buffer structure. */DeltaBuf *WMP_deltabuf_new(int veclen, int windowlen){ int i; DeltaBuf *db; db = (DeltaBuf *)mymalloc(sizeof(DeltaBuf)); db->veclen = veclen; db->win = windowlen; db->len = windowlen * 2 + 1; db->mfcc = (float **)mymalloc(sizeof(float *) * db->len); db->is_on = (boolean *) mymalloc(sizeof(boolean) * db->len); for (i=0;i<db->len;i++) { db->mfcc[i] = (float *)mymalloc(sizeof(float) * veclen * 2); } db->B = 0; for(i = 1; i <= windowlen; i++) db->B += i * i; db->B *= 2; return (db);}/** * Destroy the delta cycle buffer. * * @param db [i/o] delta cycle buffer */voidWMP_deltabuf_free(DeltaBuf *db){ int i; for (i=0;i<db->len;i++) { free(db->mfcc[i]); } free(db->is_on); free(db->mfcc); free(db);}/** * Reset and clear the delta cycle buffer. * * @param db [i/o] delta cycle buffer */voidWMP_deltabuf_prepare(DeltaBuf *db){ int i; db->store = 0; for (i=0;i<db->len;i++) { db->is_on[i] = FALSE; }}/** * Calculate delta coefficients of the specified point in the cycle buffer. * * @param db [i/o] delta cycle buffer * @param cur [in] target point to calculate the delta coefficients */static voidWMP_deltabuf_calc(DeltaBuf *db, int cur){ int n, theta, p; float A1, A2, sum; int last_valid_left, last_valid_right; for (n = 0; n < db->veclen; n++) { sum = 0.0; last_valid_left = last_valid_right = cur; for (theta = 1; theta <= db->win; theta++) { p = cur - theta; if (p < 0) p += db->len; if (db->is_on[p]) { A1 = db->mfcc[p][n]; last_valid_left = p; } else { A1 = db->mfcc[last_valid_left][n]; } p = cur + theta; if (p >= db->len) p -= db->len; if (db->is_on[p]) { A2 = db->mfcc[p][n]; last_valid_right = p; } else { A2 = db->mfcc[last_valid_right][n]; } sum += theta * (A2 - A1); } db->mfcc[cur][db->veclen + n] = sum / db->B; }}/** * Store the given MFCC vector into the delta cycle buffer, and compute the * latest delta coefficients. * * @param db [i/o] delta cycle buffer * @param new_mfcc [in] MFCC vector * * @return TRUE if next delta coeff. computed, in that case it is saved * in db->delta[], or FALSE if delta is not yet computed by short of data. */booleanWMP_deltabuf_proceed(DeltaBuf *db, float *new_mfcc) { int cur; boolean ret; /* copy data to store point */ memcpy(db->mfcc[db->store], new_mfcc, sizeof(float) * db->veclen); db->is_on[db->store] = TRUE; /* get current calculation point */ cur = db->store - db->win; if (cur < 0) cur += db->len; /* if the current point is fulfilled, compute delta */ if (db->is_on[cur]) { WMP_deltabuf_calc(db, cur); db->vec = db->mfcc[cur]; ret = TRUE; } else { ret = FALSE; } /* move store pointer to next */ db->store++; if (db->store >= db->len) db->store -= db->len; /* return TRUE if delta computed for current, or -1 if not calculated yet */ return (ret);}/** * Flush the delta cycle buffer the delta coefficients * left in the cycle buffer. * * @param db [i/o] delta cycle buffer * * @return TRUE if next delta coeff. computed, in that case it is saved * in db->delta[], or FALSE if all delta computation has been flushed and * no data is available. * */booleanWMP_deltabuf_flush(DeltaBuf *db) { int cur; boolean ret; /* clear store point */ db->is_on[db->store] = FALSE; /* get current calculation point */ cur = db->store - db->win; if (cur < 0) cur += db->len; /* if the current point if fulfilled, compute delta */ if (db->is_on[cur]) { WMP_deltabuf_calc(db, cur); db->vec = db->mfcc[cur]; ret = TRUE; } else { ret = FALSE; } /* move store pointer to next */ db->store++; if (db->store >= db->len) db->store -= db->len; /* return TRUE if delta computed for current, or -1 if not calculated yet */ return (ret);}/***********************************************************************//* MAP-CMN *//***********************************************************************//** * Initialize MAP-CMN at startup. * * @param para [in] MFCC computation configuration parameter * @param weight [in] initial cepstral mean weight * */CMNWork *CMN_realtime_new(Value *para, float weight){ int i; CMNWork *c; c = (CMNWork *)mymalloc(sizeof(CMNWork)); c->cweight = weight; c->mfcc_dim = para->mfcc_dim + (para->c0 ? 1 : 0); c->veclen = para->veclen; c->mean = para->cmn ? TRUE : FALSE; c->var = para->cvn ? TRUE : FALSE; c->clist_max = CPSTEP; c->clist_num = 0; c->clist = (CMEAN *)mymalloc(sizeof(CMEAN) * c->clist_max); for(i=0;i<c->clist_max;i++) { c->clist[i].mfcc_sum = (float *)mymalloc(sizeof(float)*c->veclen); if (c->var) c->clist[i].mfcc_var = (float *)mymalloc(sizeof(float)*c->veclen); c->clist[i].framenum = 0; } c->now.mfcc_sum = (float *)mymalloc(sizeof(float) * c->veclen); if (c->var) c->now.mfcc_var = (float *)mymalloc(sizeof(float) * c->veclen); c->cmean_init = (float *)mymalloc(sizeof(float) * c->veclen); if (c->var) c->cvar_init = (float *)mymalloc(sizeof(float) * c->veclen); c->cmean_init_set = FALSE; return c;}/** * Free work area for real-time CMN. * * @param c [i/o] CMN calculation work area * */voidCMN_realtime_free(CMNWork *c){ int i; free(c->cmean_init); free(c->now.mfcc_sum); if (c->var) { free(c->cvar_init); free(c->now.mfcc_var); } for(i=0;i<c->clist_max;i++) { if (c->var) free(c->clist[i].mfcc_var); free(c->clist[i].mfcc_sum); } free(c->clist); free(c);}/** * Prepare for MAP-CMN at start of each input * * @param c [i/o] CMN calculation work area */voidCMN_realtime_prepare(CMNWork *c){ int d; for(d=0;d<c->veclen;d++) c->now.mfcc_sum[d] = 0.0; if (c->var) { for(d=0;d<c->veclen;d++) c->now.mfcc_var[d] = 0.0; } c->now.framenum = 0;}/** * Perform MAP-CMN for incoming MFCC vectors * * @param c [i/o] CMN calculation work area * @param mfcc [in] MFCC vector * */voidCMN_realtime(CMNWork *c, float *mfcc){ int d; double x, y; c->now.framenum++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -