struct header * pc_wav_to_feasd(char *prefix, int num_read, FILE *file) { pc_wav_hd *wav_hd; double start_time; double sf; struct header *ohd; wav_hd = get_hd(prefix, num_read, file); if (wav_hd == NULL) { error_msg("pc_wav_to_feasd", "read header failed."); return NULL; } switch (wav_hd->FormatTag) { case WAVE_FORMAT_PCM: if (wav_hd->spec.pcm.BitsPerSample != 16) { error_msg("pc_wav_to_feasd", "only 16-bit audio supported."); return NULL; } break; default: error_msg("pc_wav_to_feasd", "only WAVE_FORMAT_PCM supported."); return NULL; } ohd = new_header(FT_FEA); if (ohd == NULL) { error_msg("pc_wav_to_feasd", "couldn't create FEA header."); return NULL; } strcpy(ohd->common.prog, "pc_wav_to_feasd"); add_comment(ohd, "Converted from PC WAVE header\n"); ohd->common.tag = NO; ohd->common.edr = NO; start_time = 0.0; sf = (double) wav_hd->SamplesPerSec; init_feasd_hd(ohd, SHORT, (int) wav_hd->Channels, &start_time, NO, sf); *add_genhd_l("FormatTag", (long *) NULL, 1, ohd) = (long) wav_hd->FormatTag; *add_genhd_l("Channels", (long *) NULL, 1, ohd) = (long) wav_hd->Channels; *add_genhd_l("SamplesPerSec", (long *) NULL, 1, ohd) = (long) wav_hd->SamplesPerSec; *add_genhd_l("AvgBytesPerSec", (long *) NULL, 1, ohd) = (long) wav_hd->AvgBytesPerSec; *add_genhd_l("BlockAlign", (long *) NULL, 1, ohd) = (long) wav_hd->BlockAlign; *add_genhd_l("BitsPerSample", (long *) NULL, 1, ohd) = (long) wav_hd->spec.pcm.BitsPerSample; *add_genhd_l("pc_wav_hd_ptr", (long *) NULL, 1, ohd) = (long) wav_hd; return ohd; }
static struct header * FieldList_to_fea(FieldList list, struct fea_data **rec, char **fnames, int copy_sources) { struct header *hdr; int i, j; FieldSpec *fld; char **codes; FieldList subfields; FieldSpec *subf; char *name; void *ptr; int spstype; long *dim; struct fea_header *fea; struct header *source; if (list == NULL) return NULL; hdr = new_header(FT_FEA); for (i = 0; (fld = list[i]) != NULL; i++) { codes = NULL; if (fld->occurrence != VIRTUAL && (subfields = fld->subfields) != NULL) { for (j = 0; (subf = subfields[j]) != NULL; j++) { if (strcmp(subf->name, "enumStrings") != 0) { if (debug_level) fprintf(stderr, "FieldList_to_fea: subfields " "not supported in ESPS FEA files.\n"); } else if (fld->type != SHORT) { if (debug_level) fprintf(stderr, "FieldList_to_fea: Non-SHORT field " "has subfield enumStrings.\n"); } else if (subf->type != CHAR) { if (debug_level) fprintf(stderr, "FieldList_to_fea: enumStrings not CHAR.\n"); } else if (subf->rank != 2) { if (debug_level) fprintf(stderr, "FieldList_to_fea: enumStrings " "not of rank 2.\n"); } else codes = StrArrayFromRect(subf->dim, subf->data); } } if (FieldIsTag(fld) && FindStr(ESPS_TAG, fnames)) hdr->common.tag = TRUE; else if (FieldIsFeaSubtype(fld)) hdr->hd.fea->fea_type = *(short *) fld->data; else { name = fld->name; switch(fld->occurrence) { case GLOBAL: { int size = (int) FieldLength(fld); ptr = fld->data; if (debug_level >= 2) fprintf(stderr, "FieldList_to_fea: " "global field[%d]: \"%s\".\n", i, name); if (fld->rank > 1) { if (debug_level) fprintf(stderr, "FieldList_to_fea: rank %d globals " "not supported in ESPS FEA files.\n", fld->rank); } if (size == 0) { if (debug_level) fprintf(stderr, "FieldList_to_fea: empty globals " "not supported in ESPS FEA files.\n"); } else if (codes != NULL) (void) add_genhd_e(name, (short *) ptr, size, codes, hdr); else switch (fld->type) { case DOUBLE: (void) add_genhd_d(name, (double *) ptr, size, hdr); break; case FLOAT: (void) add_genhd_f(name, (float *) ptr, size, hdr); break; case LONG: (void) add_genhd_l(name, (long *) ptr, size, hdr); break; case SHORT: (void) add_genhd_s(name, (short *) ptr, size, hdr); break; case SCHAR: case UCHAR: case CHAR: (void) add_genhd_c(name, (char *) ptr, size, hdr); break; default: if (debug_level) fprintf(stderr, "FieldList_to_fea: global type %d " "not supported in ESPS FEA files.\n", fld->type); } } break; case REQUIRED: { long size = FieldLength(fld); if (debug_level >= 2) fprintf(stderr, "FieldList_to_fea: " "required field[%d]: \"%s\".\n", i, name); if (FindStr(name, fnames)) { spstype = (codes != NULL) ? CODED : ElibTypeToEsps(fld->type); if (spstype != UNDEF) { dim = (long *) malloc(fld->rank * sizeof(long)); for (j = 0; j < fld->rank; j++) dim[j] = fld->dim[j]; add_fea_fld(name, size, fld->rank, dim, spstype, codes, hdr); } } } break; case OPTIONAL: if (debug_level) fprintf(stderr, "FieldList_to_fea: optional fields " "not supported in ESPS FEA files.\n"); break; case VIRTUAL: if (copy_sources) { if (strncmp(name, "source_", 7) != 0) { if (debug_level) fprintf(stderr, "Field_List_to_fea: VIRTUAL " "field other than source_<n>.\n"); } else if ((subfields = fld->subfields) != NULL || fld->type == CHAR) { size_t len; char *data; source = FieldList_to_fea(subfields, NULL, NULL, TRUE); len = FieldLength(fld); data = (char *) malloc(len + 1); strncpy(data, fld->data, len); data[len] = '\0'; add_source_file(hdr, data, source); } } break; case INCLUDED: if (debug_level) fprintf(stderr, "FieldList_to_fea: included fields " "not supported in ESPS FEA files.\n"); break; default: spsassert(0, "FieldList_to_fea: " "unrecognized occurrence code.\n"); break; } } } if (rec != NULL) { *rec = allo_fea_rec(hdr); fea = hdr->hd.fea; if (hdr->common.tag) { fld = FindField(list, ESPS_TAG); fld->data = &(*rec)->tag; } for (i = 0; i < (int) fea->field_count; i++) { name = fea->names[i]; fld = FindField(list, name); fld->data = get_fea_ptr(*rec, name, hdr); } } return hdr; }