int relation_save(cst_relation *r, const char *filename) { cst_file fd; cst_item *item; if (cst_streq(filename, "-")) fd = stdout; else if ((fd = cst_fopen(filename, CST_OPEN_WRITE)) == 0) { cst_errmsg("relation_save: can't open file \"%s\" for writing\n", filename); return CST_ERROR_FORMAT; } for (item = relation_head(r); item; item = item_next(item)) { if (item_feat_present(item, "end")) cst_fprintf(fd, "%f ", item_feat_float(item, "end")); else cst_fprintf(fd, "%f ", 0.00); if (item_feat_present(item, "name")) cst_fprintf(fd, "%s ", item_feat_string(item, "name")); else cst_fprintf(fd, "%s ", "_"); cst_fprintf(fd, "\n"); } if (fd != stdout) cst_fclose(fd); return CST_OK_FORMAT; }
int cst_track_save_est(cst_track *t, const char *filename) { cst_file fd; int i, j; if ((fd = cst_fopen(filename, CST_OPEN_WRITE | CST_OPEN_BINARY)) == NULL) { cst_errmsg("cst_track_save_est: can't open file \"%s\"\n", filename); return -1; } cst_fprintf(fd, "EST_File Track\n"); cst_fprintf(fd, "DataType ascii\n"); cst_fprintf(fd, "NumFrames %d\n", t->num_frames); cst_fprintf(fd, "NumChannels %d\n", t->num_channels); cst_fprintf(fd, "BreaksPresent true\n"); cst_fprintf(fd, "EST_Header_End\n"); for (i = 0; i < t->num_frames; i++) { cst_fprintf(fd, "%f\t1 \t", t->times[i]); for (j = 0; j < t->num_channels; j++) cst_fprintf(fd, "%f ", t->frames[i][j]); cst_fprintf(fd, "\n"); } cst_fclose(fd); return 0; }
int feat_print(cst_file fd,const cst_features *f) { cst_featvalpair *p; for (p=f->head; p; p=p->next) { cst_fprintf(fd, "%s ",p->name); val_print(fd,p->val); cst_fprintf(fd,"\n"); } return 0; }
void val_print(cst_file fd,const cst_val *v) { const cst_val *p; if (v == NULL) cst_fprintf(fd,"[null]"); else if (CST_VAL_TYPE(v) == CST_VAL_TYPE_INT) cst_fprintf(fd,"%d",val_int(v)); else if (CST_VAL_TYPE(v) == CST_VAL_TYPE_FLOAT) cst_fprintf(fd,"%f",val_float(v)); else if (CST_VAL_TYPE(v) == CST_VAL_TYPE_STRING) cst_fprintf(fd,"%s",val_string(v)); else if (cst_val_consp(v)) { cst_fprintf(fd,"("); for (p=v; p; ) { val_print(fd,val_car(p)); p=val_cdr(p); if (p) cst_fprintf(fd," "); } cst_fprintf(fd,")"); } else cst_fprintf(fd,"[Val %s 0x%p]", cst_val_defs[CST_VAL_TYPE(v)/2].name,CST_VAL_VOID(v)); }
int cst_track_save_est_binary(cst_track *t, const char *filename) { cst_file fd; float foo; int i, j; if ((fd = cst_fopen(filename, CST_OPEN_WRITE | CST_OPEN_BINARY)) == NULL) { cst_errmsg("cst_track_save_est_binary: can't open file \"%s\"\n", filename); return -1; } cst_fprintf(fd, "EST_File Track\n"); cst_fprintf(fd, "DataType binary\n"); cst_fprintf(fd, "ByteOrder %s\n", CST_LITTLE_ENDIAN ? BYTE_ORDER_LITTLE : BYTE_ORDER_BIG); cst_fprintf(fd, "NumFrames %d\n", t->num_frames); cst_fprintf(fd, "NumChannels %d\n", t->num_channels); cst_fprintf(fd, "BreaksPresent true\n"); cst_fprintf(fd, "EST_Header_End\n"); foo = 1.0; /* put a bogus 'breaks' value in for now */ for (i = 0; i < t->num_frames; i++) { cst_fwrite(fd, t->times + i, sizeof(float), 1); cst_fwrite(fd, &foo, sizeof(float), 1); for (j = 0; j < t->num_channels; j++) cst_fwrite(fd, &(t->frames[i][j]), sizeof(float), 1); } cst_fclose(fd); return 0; }
cst_val *cst_lex_make_entry(const cst_lexicon *lex, const cst_string *entry) { /* if replace then replace entry in addenda of lex with entry */ /* else append entry to addenda of lex */ cst_tokenstream *e; cst_val *phones = NULL; cst_val *ventry; const cst_string *w, *p; cst_string *word; cst_string *pos; int i; e = ts_open_string(entry, cst_ts_default_whitespacesymbols, "","",""); w = ts_get(e); if (w[0] == '"') /* it was a quoted entry */ { /* so reparse it */ ts_close(e); e = ts_open_string(entry, cst_ts_default_whitespacesymbols, "","",""); w = ts_get_quoted_token(e,'"','\\'); } word = cst_strdup(w); p = ts_get(e); if (!cst_streq(":",p)) /* there is a real pos */ { pos = cst_strdup(p); p = ts_get(e); if (!cst_streq(":",p)) /* there is a real pos */ { cst_fprintf(stdout,"add_addenda: lex %s: expected \":\" in %s\n", lex->name, word); cst_free(word); cst_free(pos); ts_close(e); return NULL; } } else pos = cst_strdup("nil"); while (!ts_eof(e)) { p = ts_get(e); /* Check its a legal phone */ for (i=0; lex->phone_table[i]; i++) { if (cst_streq(p,lex->phone_table[i])) break; } if (cst_streq("#",p)) /* comment to end of line */ break; else if (cst_streq("",p)) /* trailing ws at eoln causes this */ break; else if (lex->phone_table[i]) /* Only add it if its a valid phone */ phones = cons_val(string_val(p),phones); else { cst_fprintf(stdout,"add_addenda: lex: %s word %s phone %s not in lexicon phoneset\n", lex->name, word, p); } } ventry = cons_val(string_val(word),cons_val(string_val(pos), val_reverse(phones))); cst_free(word); cst_free(pos); ts_close(e); #if 0 printf("entry: "); val_print(stdout,ventry); printf("\n"); #endif return ventry; }