sdsupport.c
来自「speech signal process tools」· C语言 代码 · 共 704 行 · 第 1/2 页
C
704 行
/* * 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) 1986-1990 Entropic Speech, Inc. * "Copyright (c) 1990-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: * sampled data file support routines */static char *sccs_id = "@(#)sdsupport.c 1.25 12/18/96 ESI/ERL";#include <stdio.h>#include <esps/esps.h>#include <esps/sd.h>#include <esps/fea.h>#include <esps/feasd.h>#include <esps/unix.h>short get_fea_type();long get_fea_siz();long get_feasd_recs();int put_feasd_recs();char *type_convert();/* * get_sd_type returns the type of the data in a sampled data file this * routine assumes that SD files consist of a one element record of uniform * type */intget_sd_type(hd) struct header *hd;{ spsassert(hd != NULL, "get_sd_type: hd is NULL"); spsassert(hd->common.type == FT_SD || hd->common.type == FT_FEA && hd->hd.fea->fea_type == FEA_SD, "get_sd_type: file not SD or FEA_SD"); switch (hd->common.type) { case FT_SD: if (hd->common.ndouble == 1) return (DOUBLE); if (hd->common.nfloat == 1) return (FLOAT); if (hd->common.nlong == 1) return (LONG); if (hd->common.nshort == 1) return (SHORT); if (hd->common.nchar == 1) return (CHAR); break; case FT_FEA: return get_fea_type("samples", hd); break; } return (NONE); /* unknown */}/* * set_sd_type sets the type codes in a sampled data file. it makes the same * assumptions as get_sd_type */voidset_sd_type(hd, type)struct header *hd;int type;{ spsassert(hd != NULL, "set_sd_type: hd is NULL"); spsassert(hd->common.type == FT_SD, "set_sd_type: file not SD"); hd->common.ndouble = 0; hd->common.nfloat = 0; hd->common.nlong = 0; hd->common.nshort = 0; hd->common.nchar = 0; switch (type) { case DOUBLE: hd->common.ndouble = 1; return; case FLOAT: hd->common.nfloat = 1; return; case LONG: hd->common.nlong = 1; return; case SHORT: hd->common.nshort = 1; return; case CHAR: case BYTE: hd->common.nchar = 1; return; } Fprintf(stderr, "set_sd_type: called with unknown type %d, type\n"); exit(1);}/* * return the sizeof the sampled data file record. This assumes that the * record consists of one datum of one of the below types. */intget_sd_recsize(hd)struct header *hd;{ spsassert(hd != NULL, "get_sd_recsize: hd is NULL"); spsassert(hd->common.type == FT_SD, "get_sd_recsize: file not SD"); if (hd->common.ndouble == 1) return (sizeof(double)); if (hd->common.nfloat == 1) return (sizeof(float)); if (hd->common.nlong == 1) return (sizeof(long)); if (hd->common.nshort == 1) return (sizeof(short)); if (hd->common.nchar == 1) return (sizeof(char)); Fprintf(stderr, "get_sd_recsize: called with unknown type %d, type\n"); exit(1); return (0);}/* * read records from a sampled data file. The header is checked for the type * of the data in the file. The data is returned in floating format. There * is one of these for returning the data as floats, shorts, and doubles. * Others are easily added. */intget_sd_recf(fbuf, nsmpls, hd, stream) float *fbuf; int nsmpls; struct header *hd; FILE *stream;{ int n, k; int type, edr_flag, machine; char *data; static struct feasd rec = {FLOAT, 0, 1L, NULL, NULL}; spsassert(hd != NULL, "get_sd_recf: hd is NULL"); spsassert(hd->common.type == FT_SD || (hd->common.type == FT_FEA && hd->hd.fea->fea_type == FEA_SD && 1 == get_fea_siz("samples", hd, (short *) NULL, (long **) NULL)), "get_sd_recf: file not SD or single_channel FEA_SD"); spsassert(fbuf != NULL, "get_sd_recf: fbuf is NULL"); spsassert(nsmpls >= 0, "get_sd_recf: nsmpls < 0"); spsassert(stream != NULL, "get_sd_recf: stream is NULL"); if (nsmpls == 0) return 0; switch (hd->common.type) { case FT_SD: type = get_sd_type(hd); edr_flag = hd->common.edr; machine = hd->common.machine_code; switch (type) { case CHAR: case BYTE: case SHORT: case LONG: case DOUBLE: data = calloc((unsigned) nsmpls, (unsigned) typesiz(type)); spsassert(data, "calloc failed!"); n = miio_get(type, data, nsmpls, edr_flag, machine, stream); (void) type_convert((long) nsmpls, data, type, (char *) fbuf, FLOAT, (void (*)()) NULL); free(data); break; case FLOAT: /* No conversion is needed. */ for (k = 0; k < nsmpls; k++) fbuf[k] = 0; n = miio_get_float(fbuf, nsmpls, edr_flag, machine, stream); break; default: Fprintf(stderr, "get_sd_recf: unknown type code '%d'\n", type); exit(1); } break; case FT_FEA: rec.num_records = nsmpls; rec.data = (char *) fbuf; n = get_feasd_recs(&rec, 0L, (long) nsmpls, hd, stream); break; } return (n);}intget_sd_recs(sbuf, nsmpls, hd, stream) short *sbuf; int nsmpls; struct header *hd; FILE *stream;{ int n, k; int type, edr_flag, machine; char *data; static struct feasd rec = {SHORT, 0, 1L, NULL, NULL}; spsassert(hd != NULL, "get_sd_recs: hd is NULL"); spsassert(hd->common.type == FT_SD || (hd->common.type == FT_FEA && hd->hd.fea->fea_type == FEA_SD && 1 == get_fea_siz("samples", hd, (short *) NULL, (long **) NULL)), "get_sd_recs: file not SD or single_channel FEA_SD"); spsassert(sbuf != NULL, "get_sd_recs: sbuf is NULL"); spsassert(nsmpls >= 0, "get_sd_recs: nsmpls < 0"); spsassert(stream != NULL, "get_sd_recs: stream is NULL"); if (nsmpls == 0) return 0; switch (hd->common.type) { case FT_SD: type = get_sd_type(hd); edr_flag = hd->common.edr; machine = hd->common.machine_code; switch (type) { case CHAR: case BYTE: case LONG: case DOUBLE: case FLOAT: data = calloc((unsigned) nsmpls, (unsigned) typesiz(type)); spsassert(data, "calloc failed!"); n = miio_get(type, data, nsmpls, edr_flag, machine, stream); (void) type_convert((long) nsmpls, data, type, (char *) sbuf, SHORT, (void (*)()) NULL); free(data); break; case SHORT: /* No conversion is needed. */ for (k = 0; k < nsmpls; k++) sbuf[k] = 0; n = miio_get_short(sbuf, nsmpls, edr_flag, machine, stream); break; default: Fprintf(stderr, "get_sd_recf: unknown type code '%d'\n", type); exit(1); } break; case FT_FEA: rec.num_records = nsmpls; rec.data = (char *) sbuf; n = get_feasd_recs(&rec, 0L, (long) nsmpls, hd, stream); break; } return (n);}intget_sd_recd(dbuf, nsmpls, hd, stream) double *dbuf; int nsmpls; struct header *hd; FILE *stream;{ int n, k, edr_flag, machine; int type; char *data; static struct feasd rec = {DOUBLE, 0, 1L, NULL, NULL}; spsassert(hd != NULL, "get_sd_recd: hd is NULL"); spsassert(hd->common.type == FT_SD || (hd->common.type == FT_FEA && hd->hd.fea->fea_type == FEA_SD && 1 == get_fea_siz("samples", hd, (short *) NULL, (long **) NULL)), "get_sd_recd: file not SD or single_channel FEA_SD"); spsassert(dbuf != NULL, "get_sd_recd: dbuf is NULL"); spsassert(nsmpls >= 0, "get_sd_recd: nsmpls < 0"); spsassert(stream != NULL, "get_sd_recd: stream is NULL"); if (nsmpls == 0) return 0; switch (hd->common.type) { case FT_SD: type = get_sd_type(hd); edr_flag = hd->common.edr; machine = hd->common.machine_code; switch (type) { case CHAR: case BYTE: case SHORT: case LONG: case FLOAT: data = calloc((unsigned) nsmpls, (unsigned) typesiz(type)); spsassert(data, "calloc failed!"); n = miio_get(type, data, nsmpls, edr_flag, machine, stream); (void) type_convert((long) nsmpls, data, type, (char *) dbuf, DOUBLE, (void (*)()) NULL); free(data); break; case DOUBLE: /* No conversion is required. */ for (k = 0; k < nsmpls; k++) dbuf[k] = 0; n = miio_get_double(dbuf, nsmpls, edr_flag, machine, stream); break; default: Fprintf(stderr, "get_sd_recd: unknown type code '%d'\n", type); exit(1); } break; case FT_FEA: rec.num_records = nsmpls; rec.data = (char *) dbuf; n = get_feasd_recs(&rec, 0L, (long) nsmpls, hd, stream); break; } return (n);}/* * writes records into a sampled data file. The header is checked for the * type of the data in the file. The data is taken in floating format. */voidput_sd_recf(fbuf, nsmpls, hd, stream) float *fbuf; int nsmpls; struct header *hd; FILE *stream;{ int n, type;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?