📄 zmean.c
字号:
/** * @file zmean.c * @author Akinobu LEE * @date Sun Feb 13 20:31:23 2005 * * <JA> * @brief 掐蜗不兰の木萎喇尸の近殿 * * HTK の ZMEANSOURCE にあたる·木萎喇尸の近殿を乖ないますˉ * * 木萎喇尸の夸年は掐蜗デバイスごとに佰なりますˉ * ファイル掐蜗では·デ〖タ链挛の慷升の士堆が脱いられますˉ * マイク掐蜗やネットワ〖ク掐蜗の眷圭·掐蜗ストリ〖ムの * 呵介の @a ZMEANSAMPLES 改のサンプルの士堆から纷换され· * その猛がその稿の掐蜗に脱いられますˉ * </JA> * <EN> * @brief Remove DC offset from input speech * * These function removes DC offset from input speech, like the ZMEANSOURCE * feature in HTK. * * The estimation method of DC offset depends on the type of input device. * On file input, the mean of entire samples is used as estimated offset. * On microphone input and network input, The first @a * ZMEANSAMPLES samples in the input stream are used to estimate the offset, * and the value will be used for the rest of the input. * </EN> * * $Revision: 1.3 $ * *//* * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology * All rights reserved */#include <sent/adin.h>static int zlen = 0; ///< Current recorded length for DC offset estimationstatic float zmean = 0.0; ///< Current mean/** * Reset status. * */voidzmean_reset(){ zlen = 0; zmean = 0.0;}/** * @brief Remove DC offset. * * The DC offset is estimated by the first samples after zmean_reset() was * called. If the first input segment is longer than ZMEANSAMPLES, the * whole input is used to estimate the zero mean. Otherwise, the zero mean * will continue to be updated until the read length exceed ZMEANSAMPLES. * * @param speech [I/O] input speech data, will be subtracted by DC offset. * @param samplenum [in] length of above. * */voidsub_zmean(SP16 *speech, int samplenum){ int i; float d, sum; if (zlen < ZMEANSAMPLES) { /* update zmean */ sum = zmean * zlen; for (i=0;i<samplenum;i++) { sum += speech[i]; } zlen += samplenum; zmean = sum / (float)zlen; } for (i=0;i<samplenum;i++) { d = (float)speech[i] - zmean; /* clip overflow */ if (d < -32768.0) d = -32768.0; if (d > 32767.0) d = 32767.0; /* round to SP16 (normally short) */ if (d > 0) speech[i] = (SP16)(d + 0.5); else speech[i] = (SP16)(d - 0.5); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -