Julius 4.2
libsent/src/adin/zmean.c
説明を見る。
00001 
00034 /*
00035  * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University
00036  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00037  * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology
00038  * All rights reserved
00039  */
00040 
00041 #include <sent/adin.h>
00042 
00043 static int zlen = 0;            
00044 static float zmean = 0.0;       
00045 
00050 void
00051 zmean_reset()
00052 {
00053   zlen = 0;
00054   zmean = 0.0;
00055 }
00056 
00069 void
00070 sub_zmean(SP16 *speech, int samplenum)
00071 {
00072   int i;
00073   float d, sum;
00074 
00075   if (zlen < ZMEANSAMPLES) {
00076     /* update zmean */
00077     sum = zmean * zlen;
00078     for (i=0;i<samplenum;i++) {
00079       sum += speech[i];
00080     }
00081     zlen += samplenum;
00082     zmean = sum / (float)zlen;
00083   }
00084   for (i=0;i<samplenum;i++) {
00085     d = (float)speech[i] - zmean;
00086     /* clip overflow */
00087     if (d < -32768.0) d = -32768.0;
00088     if (d > 32767.0) d = 32767.0;
00089     /* round to SP16 (normally short) */
00090     if (d > 0) speech[i] = (SP16)(d + 0.5);
00091     else speech[i] = (SP16)(d - 0.5);
00092   }
00093 }