⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sphere.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * This material contains unpublished, proprietary software of  * Entropic Research Laboratory, Inc. Any reproduction, distribution,  * or publication of this work must be authorized in writing by Entropic  * Research Laboratory, Inc., and must bear the notice:  * *    "Copyright (c) 1996 Entropic Research Laboratory, Inc.  *                   All rights reserved" * * The copyright notice above does not evidence any actual or intended  * publication of this source code.      * * Written by:  Alan Parker * Checked by: * Revised by: * * Brief description: Routine to convert NIST Sphere header to FEASD * */static char *sccs_id = "@(#)sphere.c	1.15	28 Oct 1999	ERL";#include <stdio.h>#include <sp/sphere.h>#undef BYTE#undef SHORT#undef ROUND#include <esps/esps.h>#include <esps/fea.h>#include <esps/feasd.h>#define ESPS_BYTE  8#define ESPS_SHORT  4extern int      errno;extern int      EspsDebug;	/* set in headers.c for header debugging */extern int      debug_level;	/* standard debug_level */SP_FILE        *sp_fp_open();static long     findlim();static int      copy_gens();int             sphere_to_sd_ctrl = 0;	/* shared with headers.c */struct header  *sphere_to_feasd(fp)   FILE           *fp;{   char            line[10];   char           *error;   struct header_t *t_h;   SP_FILE        *tsp;   char          **fields;   struct header  *e_h;   int             size, type, nfields;   long            channel_count;   long            sample_min = 0, sample_max = 0;   long            n, i;   double          start_time = 0;   double          record_freq;   char           *p, *q;   char           *name;   char            byte_order[3];   char            sample_coding[4];   time_t          tloc, time();   char           *ctime();   char            I[4];   int             data_type;   int             samp_size = 0;   extern int      called_by_waves;   if (EspsDebug)      fprintf(stderr, "Inside of sphere_to_feasd()\n");   spsassert(fp, "sphere_to_fea: fp is NULL");   called_by_waves = 1;   strcpy(byte_order, "10");   /* check for SPHERE magic numbers */   (void) fgets(line, 8, fp);   if (strcmp(line, "NIST_1A") != 0)      return NULL;   else      fseek(fp, 0L, 0);   /* open Sphere header */#ifdef OLD_WAY   if ((t_h = sp_open_header(fp, TRUE, &error)) == NULL) {      if (EspsDebug)	 fprintf(stderr, "%s\n", error);      return NULL;   }#else   if ((tsp = sp_fp_open(fp)) == SPNULL) {      if (EspsDebug)	 fprintf(stderr, "sp_fp_open failed\n");      return NULL;   }   t_h = tsp->read_spifr->header;#endif   if (EspsDebug)      fprintf(stderr, "Read sphere header\n");   nfields = sp_get_nfields(t_h);   if (nfields < 1)      return NULL;   if (EspsDebug)      fprintf(stderr, "nfields: %d\n", nfields);   fields = (char **) malloc((unsigned) (nfields * sizeof(char *)));   spsassert(fields, "malloc failed");   if (sp_get_fieldnames(t_h, nfields, fields) != nfields) {      fprintf(stderr, "sphere_to_fea: internal error.\n");      assert(0);   }   n = sp_get_field(t_h, "channel_count", &type, &size);   if (n < 0)      channel_count = 1;	/* if no channel count default to 1 */   else {      n = sp_get_data(t_h, "channel_count", (char *) &channel_count, &size);      spsassert(n >= 0, "sp_get_data returned error");   }   if (EspsDebug)      fprintf(stderr, "channels: %d\n", channel_count);   n = sp_get_field(t_h, "sample_byte_format", &type, &size);   if (n >= 0) {      if (size > 2) {	 size = 2;      }      n = sp_get_data(t_h, "sample_byte_format", byte_order, &size);      spsassert(n >= 0, "sp_get_data returned error");      byte_order[size] = '\0';   }   n = sp_get_field(t_h, "sample_n_bytes", &type, &size);   if (n >= 0) {      n = sp_get_data(t_h, "sample_n_bytes", (char *) &samp_size, &size);      spsassert(n >= 0, "sp_get_data returned error");   }   n = sp_get_field(t_h, "sample_min", &type, &size);   if (n >= 0) {      n = sp_get_data(t_h, "sample_min", (char *) &sample_min, &size);      spsassert(n >= 0, "sp_get_data returned error");   }   n = sp_get_field(t_h, "sample_max", &type, &size);   if (n >= 0) {      n = sp_get_data(t_h, "sample_max", (char *) &sample_max, &size);      spsassert(n >= 0, "sp_get_data returned error");   }   n = sp_get_field(t_h, "sample_coding", &type, &size);   if (n >= 0) {      n = sp_get_data(t_h, "sample_coding", sample_coding, &size);      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;	    n = sp_get_data(t_h, "sample_rate", (char *)&p, &size);	    spsassert(n >= 0, "sp_get_data returned error");	    record_freq = p;	    break;	 }      case T_REAL:	 {	    double         p;	    n = sp_get_data(t_h, "sample_rate", (char *)&p, &size);	    spsassert(n >= 0, "sp_get_data returned error");	    record_freq = p;	    break;	 }      default:	 assert(0);      }   }   e_h = new_header(FT_FEA);   if (byte_order[0] == '0' && byte_order[1] == '1') {      e_h->common.machine_code = DS3100_CODE;      e_h->common.edr = NO;      if (EspsDebug)	 fprintf(stderr, "ds3100 byte order\n");   } else if (byte_order[0] == '1' && byte_order[1] == '0') {      e_h->common.machine_code = SUN4_CODE;      e_h->common.edr = YES;      if (EspsDebug)	 fprintf(stderr, "sun4 byte order\n");   }   data_type = ESPS_SHORT;   start_time = 0;   n = init_feasd_hd(e_h, data_type, channel_count, &start_time, NO, record_freq);   spsassert(n == 0, "init_feasd_hd returned error");   if (sample_min || sample_max)      *add_genhd_d("max_value", NULL, 1, e_h) =	 MAX(abs(sample_min), sample_max);   /* set the date */   tloc = time(0);   (void) strcpy(e_h->common.date, ctime(&tloc));   e_h->common.date[24] = ' ';   /* add header version */   I[0] = '\0';			/* dirty trick to keep sccs from */   (void) strcpy(I, "%");	/* killing the % I % , symbol */   (void) strcat(I, "I%");   /*    * if the header version define (from header.h) is equal to    * percentIpercent then that means that header.h is an sccs edit version.    * Substitute a large sccs version instead of putting the sccs keyword    * into the header    */   if (strcmp(I, HD_VERSION) != 0)      (void) strcpy(e_h->common.hdvers, HD_VERSION);   else      (void) strcpy(e_h->common.hdvers, "999");   /*    * fix up the program and version fields    */   strcpy(e_h->common.prog, "sphere_to_esps");   /* add a comment */   add_comment(e_h, "Converted from Sphere header");   /* add pointer to sphere header */   *add_genhd_l("sphere_hd_ptr", (long *) NULL, 1, e_h) = (long) tsp;   for (i = 0; i < nfields; i++) {      name = fields[i];#ifdef DEBUG      fprintf(stderr, "timit: name: %s\n", name);#endif      n = sp_get_field(t_h, name, &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:	 {	    char           *temp_p;#ifdef DEBUG	    fprintf(stderr, " string data: %s\n", p);#endif	    temp_p = malloc((unsigned) size + 1);	    spsassert(temp_p, "malloc failed");	    bcopy(p, temp_p, size);	    temp_p[size] = 0;	    (void) add_genhd_c(name, temp_p, size, e_h);	    break;	 }      case T_INTEGER:#ifdef DEBUG	 fprintf(stderr, " int data: %ld\n", *(long *) p);#endif	 *add_genhd_l(name, NULL, 1, e_h) = *(long *) p;	 break;      case T_REAL:#ifdef DEBUG	 fprintf(stderr, " real data: %lf\n", *(double *) p);#endif	 *add_genhd_d(name, NULL, 1, e_h) = *(double *) p;	 break;      }      free(q);   }   if (sp_set_data_mode(tsp, "SE-PCM-2") > 0) {      if (EspsDebug)	 sp_print_return_status(stderr);      return NULL;   }   free(fields);   return e_h;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -