timit.c
来自「speech signal process tools」· C语言 代码 · 共 135 行
C
135 行
#define DEBUG#include <stdio.h>#include "header.h"#include "sp.h"#include <esps/esps.h>#include <esps/fea.h>#include <esps/feasd.h>struct header *timit_to_fea(fp)FILE *fp;{char *error;struct header_t *t_h;char **fields;struct header *e_h;long size, channel_count, type, nfields;long n, i;double start_time;double record_freq;char *p, *q;char *name; spsassert(fp,"timit_to_fea: fp is NULL"); if ((t_h=sp_open_header(fp,TRUE,error)) == NULL) return NULL; nfields = sp_get_nfields(t_h); if (nfields < 1) return NULL; fields = (char **)malloc((unsigned) (nfields * sizeof(char *))); spsassert(fields,"malloc failed"); if (sp_get_fieldnames(t_h,nfields,fields) != nfields) { fprintf(stderr,"timit_to_fea: internal error.\n"); assert(0); } n = sp_get_field(t_h,"channel_count",&type,&size); if (n < 0) channel_count = 1; else { n = sp_get_data(t_h,"channel_count",&channel_count,2); spsassert(n >= 0, "sp_get_data returned error"); } n = sp_get_field(t_h,"sample_rate",&type,&size); if (n < 0) { record_freq = 10000; fprintf(stderr,"Warning: converting from timit to esps and no sample rate is in header.\n"); fprintf(stderr," Using 10000 Hz.\n"); } else { switch (type) { case T_INTEGER: { long *p; p = (long *)malloc((unsigned)size); n = sp_get_data(t_h,"sample_rate",p,&size); spsassert(n >= 0, "sp_get_data returned error"); record_freq = *p; break; } case T_REAL: { double *p; p = (double *)malloc((unsigned)size); n = sp_get_data(t_h,"sample_rate",p,&size); spsassert(n >= 0, "sp_get_data returned error"); record_freq = *p; break; } default: assert(0); } } e_h = new_header(FT_FEA); start_time = 0; n=init_feasd_hd(e_h, SHORT, channel_count, &start_time,NO,record_freq); spsassert(n == 0, "init_feasd_hd returned error"); for (i=0; i<nfields; i++) { n = sp_get_field(t_h,fields[i],&type,&size); spsassert(n >= 0, "sp_get_field returned error"); p = q = malloc((unsigned) size); spsassert(p,"malloc failed"); n = sp_get_data(t_h,name,p,&size); spsassert(n >= 0, "sp_get_data returned error");#ifdef DEBUG fprintf(stderr,"timit_to_fea: "); fprintf(stderr,"field: %s", name); fprintf(stderr," size: %d", size);#endif switch (type) { case T_STRING:#ifdef DEBUG fprintf(stderr,"data: %s\n",p);#endif (void)add_genhd_c(name,p,size,e_h); break; case T_INTEGER:#ifdef DEBUG fprintf(stderr,"data: %ld\n",(long *)p);#endif (void)add_genhd_l(name,(long *)p,size,e_h); break; case T_REAL:#ifdef DEBUG fprintf(stderr,"data: %lf\n",(double *)p);#endif (void)add_genhd_d(name,(double *)p,size,e_h); break; } free(q); } (void)sp_close_header(t_h); return e_h;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?