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

📄 sphere.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
#define BUFSIZE 8192static struct feasd *sd_rec;	/* record for input data */static short   *sdata;		/* pointer to data in fea_sd record */struct header_t *sd_to_sphere(ifile, ofile, byte_format)   FILE           *ifile;   FILE           *ofile;   char           *byte_format;{   struct header  *hd, *ehd;   struct header_t *shd;   long            sample_rate;   long            nrecords = 0;   int             i;   double          max_value = -DBL_MAX;   double          min_value = DBL_MAX;   long            max;   long            min;   long            ival;   long            hbytes, dbytes;   struct header                  *ohd_esps;	/* dummy output ESPS header */   int             num_read = 0;/* number samples read  */   int             breverse;   struct header  *sdtofea();   int             j;   if (ifile == NULL) {      Fprintf(stderr, "sd_to_sphere: NULL input; returning NULL.\n");      return (NULL);   }   if (!((strcmp(byte_format, "10") == 0)	 || (strcmp(byte_format, "01") == 0))) {      Fprintf(stderr, "sd_to_sphere: byte_format must be '01' or '10'.\n");      return (NULL);   }   if (strcmp(byte_format, "01") == 0)      breverse = 1;   else      breverse = 0;   sphere_to_sd_ctrl = 123;   hd = read_header(ifile);   if (hd == NULL) {      Fprintf(stderr,	   "sd_to_sphere: ESPS header not SD or FEA_SD; returning NULL.\n");      return (NULL);   }   sphere_to_sd_ctrl = 0;   if (hd->common.type == FT_SD)      ehd = sdtofea(hd);   else if ((hd->common.type == FT_FEA) && (hd->hd.fea->fea_type == FEA_SD))      ehd = hd;   else {      Fprintf(stderr,	   "sd_to_sphere: ESPS header not SD or FEA_SD; returning NULL.\n");      return (NULL);   }   shd = sp_create_header();   sample_rate = get_genhd_val("record_freq", ehd, 1);   sp_add_field(shd, "sample_rate", T_INTEGER, (char *) &sample_rate);   /* copy generics over */   copy_gens(shd, ehd);   if (ofile == NULL)      return (shd);   /* Allocate buffer */   sd_rec = allo_feasd_recs(ehd, ESPS_SHORT, BUFSIZE, (char *) NULL, NO);   sdata = (short *) sd_rec->data;   if ((nrecords = findlim(&ifile, ehd, &max_value, &min_value)) == 0) {      Fprintf(stderr, "sd_to_sphere: no input records or error reading it.\n");      return (shd);   }   if (debug_level) {      Fprintf(stderr, "sd_to_sphere: max_value = %lg\n", max_value);      Fprintf(stderr, "sd_to_sphere: min_value = %lg\n", min_value);   }   max = max_value;   min = min_value;   sp_add_field(shd, "sample_min", T_INTEGER, (char *) &min);   sp_add_field(shd, "sample_max", T_INTEGER, (char *) &max);   sp_add_field(shd, "sample_count", T_INTEGER, (char *) &nrecords);   ival = 1;   sp_add_field(shd, "channel_count", T_INTEGER, (char *) &ival);   ival = 2;   sp_add_field(shd, "sample_n_bytes", T_INTEGER, (char *) &ival);   sp_add_field(shd, "sample_byte_format", T_STRING, byte_format);   ival = 16;   sp_add_field(shd, "sample_sig_bits", T_INTEGER, (char *) &ival);   j = sp_write_header(ofile, shd, &hbytes, &dbytes);   /* create dummy output ESPS header for use by put_feasd_recs */   ohd_esps = new_header(FT_FEA);   init_feasd_hd(ohd_esps, ESPS_SHORT, 1, get_genhd_d("start_time", ehd),		 0, get_genhd_val("record_freq", ehd, 1));   do {      num_read = get_feasd_recs(sd_rec, 0L, BUFSIZE, ehd, ifile);      if (num_read != 0) {	 if (breverse) {	    for (i = 0; i < BUFSIZE; i++)	       sdata[i] = short_reverse(sdata[i]);	 }	 put_feasd_recs(sd_rec, 0L, num_read, ohd_esps, ofile);      }   } while (num_read == BUFSIZE);   return (shd);}static intcopy_gens(dest, src)   struct header_t *dest;   struct header  *src;{   int             i, count = 0, k;   char           *ptr;   struct gen_hd  *np, *lookup();   long            intval;   double          dblval;   /* check arguments */   spsassert(dest && src, "Bad args in copy_gens");   /* check for no items in src */   if (src->variable.ngen == 0)      return 0;   /* find entries */   for (i = 0; i < GENTABSIZ; i++) {      np = src->variable.gentab[i];      while (np != NULL) {	 /* create new item and copy data */	 switch (np->type) {	 case ESPS_SHORT:	 case CODED:	    intval = *(short *) np->d_ptr;	    sp_add_field(dest, np->name, T_INTEGER, (char *) &intval);	 case LONG:	    intval = *(long *) np->d_ptr;	    sp_add_field(dest, np->name, T_INTEGER, (char *) &intval);	    break;	 case FLOAT:	    dblval = *(float *) np->d_ptr;	    sp_add_field(dest, np->name, T_REAL, (char *) &dblval);	    break;	 case DOUBLE:	    dblval = *(double *) np->d_ptr;	    sp_add_field(dest, np->name, T_REAL, (char *) &dblval);	    break;	 case CHAR:	    sp_add_field(dest, np->name, T_STRING, np->d_ptr);	    break;	 }	 np = np->next;	 count++;      }   }   return count;}static longfindlim(file, hd, max, min)   FILE          **file;   struct header  *hd;   double         *max, *min;/* * find max and min of data in file; if input is a pipe, then write data to * temporary file and change the corresponding file pointer; this is so the * data can be read again in order to copy it from input to output in the * main program */{   FILE           *tmpstrm;	/* temp file; might be return to main */   int             first = 1;	/* flag for first time read from file */   long            tot_read = 0;   int             i;   int             num_read = 0;   if (hd->common.ndrec == -1) {      tmpstrm = tmpfile();      if (debug_level)	 Fprintf(stderr, "sd_to_sphere: input is pipe; creating temp file\n");   }   do {      num_read = get_feasd_recs(sd_rec, 0L, BUFSIZE, hd, *file);      tot_read += num_read;      if (debug_level > 1)	 Fprintf(stderr, "sd_to_sphere: num_read = %d\n", num_read);      if (first) {	 if (num_read == 0)	    return 0;	 first = 0;      }      for (i = 0; i < num_read; i++) {	 if (sdata[i] < *min)	    *min = sdata[i];	 if (sdata[i] > *max)	    *max = sdata[i];      }      if (num_read != 0 && hd->common.ndrec == -1) {	 put_feasd_recs(sd_rec, 0L, num_read, hd, tmpstrm);	 if (debug_level > 1)	    Fprintf(stderr, "sd_to_sphere: wrote %d samples to temp file\n",		    num_read);      }   } while (num_read == BUFSIZE);   if (hd->common.ndrec == -1) {/* Input was a pipe */      (void) rewind(tmpstrm);      *file = tmpstrm;   } else {      (void) rewind(*file);      sphere_to_sd_ctrl = 123;      (void) read_header(*file);      sphere_to_sd_ctrl = 0;   }   return (tot_read);}intsphere_set_file(sp, stream)   SP_FILE        *sp;   FILE           *stream;{   SPWAVEFORM     *wp;   SP_FILE        *tsp;   if (sp && sp->read_spifr->status->read_occured_flag) {      wp = sp->read_spifr->waveform;      if (wp->sp_fob->fp && !sp->read_spifr->status->is_temp_file) {	 wp->sp_fob->fp = stream;      } else if (wp->sp_fob->fp && sp->read_spifr->status->is_temp_file) {	 (void) rewind(wp->sp_fob->fp);      } else if (wp->sp_fob->buf) {	 return 1;      }   }   return 0;}intsphere_temp(sp)   SP_FILE        *sp;{   return (sp && sp->read_spifr->status->is_temp_file);}intsphere_been_read(sp)   SP_FILE        *sp;{   return (sp && sp->read_spifr->status->read_occured_flag);}char           *get_sphere_hdr(hdr)   struct header         *hdr;{   if (hdr)      return (char *) get_genhd_val_l("sphere_hd_ptr", hdr, 0L);   else      return NULL;}/* this is just to force this function to be linked in for later use */int DUMMY(){   SP_FILE *hd;   sp_rewind(hd);   return 1;}

⌨️ 快捷键说明

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