Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

zmean.c

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

Generated on Tue Mar 28 16:01:39 2006 for Julius by  doxygen 1.4.2