feasdsupp.c

来自「speech signal process tools」· C语言 代码 · 共 706 行 · 第 1/2 页

C
706 行
字号
	 case FLOAT_CPLX:	    CASE(float_cplx)	 case DOUBLE_CPLX:	    CASE(double_cplx)	 }#undef	    CASE      }      free_fea_rec(fea_rec);   }   if (encoding) {      short          *conv_buffer;      if (0 /* source_type != BYTE */) {	 Warning(1, "header item encoding indicates mu-law but file is not BYTE");	 Warning(0, "the data will not be converted.");      } else if (dest_type == BYTE) {	 Warning(1, "cannot decode mu-law data into BYTE format");	 Warning(0, "the data will not be converted.");      } else {	 if (dest_type == SHORT)	    conv_buffer = (short *) sd_data;	 else {	    conv_buffer = (short *) calloc((unsigned) num_records, sizeof(short) * num_channels);	    spsassert(conv_buffer, "calloc failed!");	 }	 switch (encoding) {	 case 1:		/* normal esps mu-law encoded */	    mu_to_linear(buffer, conv_buffer, (long) num_read*num_channels);	    source_type = SHORT;	    rec_size = sizeof(short) * num_channels;	    free(buffer);	    buffer = (char *) conv_buffer;	    break;	 case 2:		/* bit reverse esps mu-law encoded */	    bit_reverse(buffer, num_read);	    mu_to_linear(buffer, conv_buffer, (long) num_read*num_channels);	    source_type = SHORT;	    rec_size = sizeof(short) * num_channels;	    free(buffer);	    buffer = (char *) conv_buffer;	    break;	    /*	     * the following two methods were provides by Terri Kamm at DoD.	     * The reason that the no bit reverse case calls the reverse	     * routine is that the reverse is already in the algorithm	     */	 case 3:		/* Terri Kamm mu_law, bit reverse */	    mu2_to_linear(buffer, conv_buffer, (long) num_read*num_channels);	    source_type = SHORT;	    rec_size = sizeof(short) * num_channels;	    free(buffer);	    buffer = (char *) conv_buffer;	    break;	 case 4:		/* Terri Kamm Sun mu_law, no bit reverse */	    bit_reverse(buffer, num_read);	    mu2_to_linear(buffer, conv_buffer, (long) num_read*num_channels);	    source_type = SHORT;	    rec_size = sizeof(short) * num_channels;	    free(buffer);	    buffer = (char *) conv_buffer;	    break;	    /*	     * these are the two A-law versions that we have	     */	 case 5:		/* standard alaw */	    (void) a_to_linear(buffer, conv_buffer,(long)num_read*num_channels);	    source_type = SHORT;	    rec_size = sizeof(short) * num_channels;	    free(buffer);	    buffer = (char *) conv_buffer;	    break;	 case 6:		/* CCITT */	    (void) a_to_linear_2(buffer, conv_buffer, (long)num_read*num_channels);	    source_type = SHORT;	    rec_size = sizeof(short) * num_channels;	    free(buffer);	    buffer = (char *) conv_buffer;	    break;	 default:	    Warning(1, "unknown value for header item encoding ignored");	    break;	 }      }   }   (void) zero_fill((num_records - num_read) * num_channels,		    source_type, buffer + num_read * rec_size);   if (source_type != dest_type) {      (void) type_convert(num_records * num_channels, buffer, source_type,			  sd_data, dest_type, (void (*) ()) NULL);      free(buffer);   }   return num_read;}/* * This routine reads possibly overlapping or noncontiguous records of the * FEA file subtype FEA_SD. */longget_feasd_orecs(data, start, framelen, step, hd, file)   struct feasd   *data;   long            start, framelen, step;   struct header  *hd;   FILE           *file;{   int             i;   long            numoldsamples, numnewsamples;   spsassert(hd, "get_feasd_orecs: hd is NULL");   spsassert(data, "get_feasd_orecs: sd record struct is NULL");   spsassert(file, "get_feasd_orecs: file is NULL");   spsassert(hd->common.type == FT_FEA	     && hd->hd.fea->fea_type == FEA_SD,	     "get_feasd_orecs: file not FEA or not FEA_SD");   spsassert(step >= 0,	     "get_feasd_orecs: negative step.");   spsassert(start >= 0,	     "get_feasd_orecs: negative starting record.");   spsassert(framelen >= 0,	     "get_feasd_orecs: negative frame length.");   spsassert(start + framelen <= data->num_records,	     "get_feasd_orecs: frame overruns end of data array.");   if (step == 0)      return framelen;   if (step >= framelen) {      fea_skiprec(file, step - framelen, hd);      return get_feasd_recs(data, start, framelen, hd, file);   }   numoldsamples = (framelen - step) * data->num_channels;   numnewsamples = step * data->num_channels;#define CASE(type) \	{ \	    type	*buf; \	    \	    buf = (type *) data->data + start * data->num_channels; \	    for (i = 0; i < numoldsamples; i++) \		buf[i] = buf[i + numnewsamples]; \	    break; \	}   switch (data->data_type) {   case BYTE:      CASE(char)   case SHORT:      CASE(short)   case LONG:      CASE(long)   case FLOAT:      CASE(float)   case DOUBLE:      CASE(double)   case BYTE_CPLX:      CASE(byte_cplx)   case SHORT_CPLX:      CASE(short_cplx)   case LONG_CPLX:      CASE(long_cplx)   case FLOAT_CPLX:      CASE(float_cplx)   case DOUBLE_CPLX:      CASE(double_cplx)   }#undef CASE   return framelen - step      + get_feasd_recs(data, start + framelen - step, step, hd, file);}/* * This routine writes records of the FEA file subtype FEA_SD. */intput_feasd_recs(data, start, num_records, hd, file)   struct feasd   *data;   long            start, num_records;   struct header  *hd;   FILE           *file;{   long            num_channels;   int             source_type, dest_type;   int             rec_size;   char           *sd_data, *buffer;   int             rtn;   spsassert(hd, "put_feasd_recs: header is NULL.");   spsassert(data, "put_feasd_recs: sd record struct is NULL.");   spsassert(file, "put_feasd_recs: file is NULL.");   spsassert(hd->common.type == FT_FEA	     && hd->hd.fea->fea_type == FEA_SD,	     "put_feasd_recs: file not FEA or not FEA_SD");   spsassert(start >= 0,	     "put_feasd_recs: negative starting record.");   spsassert(num_records >= 0,	     "put_feasd_recs: can't write negative number of records.");   spsassert(start + num_records <= data->num_records,	"put_feasd_recs: records to be written overrun end of data array.");   num_channels = get_fea_siz("samples", hd, (short *) NULL, (long **) NULL);   spsassert(num_channels == data->num_channels,       "put_feasd_recs: data array num_channels inconsistent with header.");   spsassert(hd->hd.fea->field_count == 1,	     "put_feasd_recs: extraneous fields defined in header.");   if (num_records == 0)      return 0;   dest_type = get_fea_type("samples", hd);   source_type = data->data_type;   rec_size = typesiz(dest_type) * num_channels;   sd_data = data->data + start * typesiz(source_type) * num_channels;   if (source_type != dest_type) {	/* conversion required */      buffer = calloc((unsigned) num_records, (unsigned) rec_size);      spsassert(buffer,		"put_feasd_recs: couldn't allocate buffer.");      (void) type_convert(num_records * num_channels, sd_data, source_type,			  buffer, dest_type, (void (*) ()) NULL);   } else			/* write directly from data array */      buffer = sd_data;   rtn = miio_put(dest_type, buffer,		  (int) (num_records * num_channels), hd->common.edr, file)      != num_records * num_channels;   if (source_type != dest_type)      free(buffer);   return rtn;}/* * Check for numeric data type. */static intnumeric(type)   int             type;{   switch (type) {   case BYTE:   case SHORT:   case LONG:   case FLOAT:   case DOUBLE:   case BYTE_CPLX:   case SHORT_CPLX:   case LONG_CPLX:   case FLOAT_CPLX:   case DOUBLE_CPLX:      return YES;      break;   default:      return NO;      break;   }   /* NOTREACHED */}longmiio_get(type_code, ptr, n, flag, mach, fp)   int             type_code;   char           *ptr;   int             n;   int             flag;   int             mach;   FILE           *fp;{#define	CASE(type, miio_func) \	return miio_func((type *) ptr, n, flag, mach, fp);   switch (type_code) {   case CHAR:      CASE(char, miio_get_char)   case BYTE:      CASE(char, miio_get_byte)   case SHORT:      CASE(short, miio_get_short)   case LONG:      CASE(long, miio_get_long)   case FLOAT:      CASE(float, miio_get_float)   case DOUBLE:      CASE(double, miio_get_double)   case BYTE_CPLX:      CASE(byte_cplx, miio_get_bcplx)   case SHORT_CPLX:      CASE(short_cplx, miio_get_scplx)   case LONG_CPLX:      CASE(long_cplx, miio_get_lcplx)   case FLOAT_CPLX:      CASE(float_cplx, miio_get_fcplx)   case DOUBLE_CPLX:      CASE(double_cplx, miio_get_dcplx)   default:      Fprintf(stderr, "%s: unrecognized type code %d.\n",	      "miio_get", type_code);      exit(1);      /* NOTREACHED */   }#undef	CASE}longmiio_put(type_code, ptr, n, flag, fp)   int             type_code;   char           *ptr;   int             n;   int             flag;   FILE           *fp;{#define	CASE(type, miio_func) \	return miio_func((type *) ptr, n, flag, fp);   switch (type_code) {   case CHAR:      CASE(char, miio_put_char)   case BYTE:      CASE(char, miio_put_byte)   case SHORT:      CASE(short, miio_put_short)   case LONG:      CASE(long, miio_put_long)   case FLOAT:      CASE(float, miio_put_float)   case DOUBLE:      CASE(double, miio_put_double)   case BYTE_CPLX:      CASE(byte_cplx, miio_put_bcplx)   case SHORT_CPLX:      CASE(short_cplx, miio_put_scplx)   case LONG_CPLX:      CASE(long_cplx, miio_put_lcplx)   case FLOAT_CPLX:      CASE(float_cplx, miio_put_fcplx)   case DOUBLE_CPLX:      CASE(double_cplx, miio_put_dcplx)   default:      Fprintf(stderr, "%s: unrecognized type code %d.\n",	      "miio_put", type_code);      exit(1);      /* NOTREACHED */   }#undef	CASE}

⌨️ 快捷键说明

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