/*---------------------------------------------------------------------------*\ FILE........: dump.c AUTHOR......: David Rowe DATE CREATED: 25/8/09 Routines to dump data to text files for Octave analysis. \*---------------------------------------------------------------------------*/ /* All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, see . */ #include "defines.h" #include "comp.h" #include "dump.h" #include #include #include #include #include #ifdef DUMP static int dumpon = 0; static FILE *fsn = NULL; static FILE *fsw = NULL; static FILE *few = NULL; static FILE *fsw_ = NULL; static FILE *fsoftdec = NULL; static FILE *fmodel = NULL; static FILE *fqmodel = NULL; static FILE *fpwb = NULL; static FILE *fpw = NULL; static FILE *frw = NULL; static FILE *flsp = NULL; static FILE *fweights = NULL; static FILE *flsp_ = NULL; static FILE *fmel = NULL; static FILE *fmel_indexes = NULL; static FILE *fphase = NULL; static FILE *fphase_ = NULL; static FILE *ffw = NULL; static FILE *fe = NULL; static FILE *fsq = NULL; static FILE *fdec = NULL; static FILE *fsnr = NULL; static FILE *flpcsnr = NULL; static FILE *fak = NULL; static FILE *fak_ = NULL; static FILE *fbg = NULL; static FILE *fE = NULL; static FILE *frk = NULL; static FILE *fhephase = NULL; static char prefix[MAX_STR]; void dump_on(char p[]) { dumpon = 1; strcpy(prefix, p); } void dump_off(){ if (fsn != NULL) fclose(fsn); if (fsw != NULL) fclose(fsw); if (fsw_ != NULL) fclose(fsw_); if (few != NULL) fclose(few); if (fmodel != NULL) fclose(fmodel); if (fsoftdec != NULL) fclose(fsoftdec); if (fqmodel != NULL) fclose(fqmodel); if (fpwb != NULL) fclose(fpwb); if (fpw != NULL) fclose(fpw); if (frw != NULL) fclose(frw); if (flsp != NULL) fclose(flsp); if (fweights != NULL) fclose(fweights); if (flsp_ != NULL) fclose(flsp_); if (fmel != NULL) fclose(fmel); if (fmel_indexes != NULL) fclose(fmel_indexes); if (fphase != NULL) fclose(fphase); if (fphase_ != NULL) fclose(fphase_); if (ffw != NULL) fclose(ffw); if (fe != NULL) fclose(fe); if (fsq != NULL) fclose(fsq); if (fdec != NULL) fclose(fdec); if (fsnr != NULL) fclose(fsnr); if (flpcsnr != NULL) fclose(flpcsnr); if (fak != NULL) fclose(fak); if (fak_ != NULL) fclose(fak_); if (fbg != NULL) fclose(fbg); if (fE != NULL) fclose(fE); if (frk != NULL) fclose(frk); if (fhephase != NULL) fclose(fhephase); } void dump_Sn(int m_pitch, float Sn[]) { int i; char s[MAX_STR + 7]; if (!dumpon) return; if (fsn == NULL) { sprintf(s,"%s_sn.txt", prefix); fsn = fopen(s, "wt"); assert(fsn != NULL); } /* split across two lines to avoid max line length problems */ /* reconstruct in Octave */ for(i=0; iWo, model->L); for(l=1; l<=model->L; l++) { sprintf(s,"%12f ",model->A[l]); strcat(line, s); assert(strlen(line) < MAX_STR*10); } for(l=model->L+1; l<=MAX_AMP; l++) { sprintf(s,"%12f ", 0.0); strcat(line,s); assert(strlen(line) < MAX_STR*10); } sprintf(s,"%d\n",model->voiced); strcat(line,s); fprintf(fmodel,"%s",line); } void dump_quantised_model(MODEL *model) { int l; char s[MAX_STR + 11]; char line[4096]; if (!dumpon) return; if (fqmodel == NULL) { sprintf(s,"%s_qmodel.txt", prefix); fqmodel = fopen(s, "wt"); assert(fqmodel != NULL); } sprintf(line,"%12f %12d ", model->Wo, model->L); for(l=1; l<=model->L; l++) { sprintf(s,"%12f ",model->A[l]); strcat(line, s); assert(strlen(line) < 4096); } for(l=model->L+1; l<=MAX_AMP; l++) { sprintf(s,"%12f ", 0.0); strcat(line, s); assert(strlen(line) < 4096); } sprintf(s,"%d\n",model->voiced); strcat(line, s); fprintf(fqmodel, "%s", line); } void dump_phase(float phase[], int L) { int l; char s[MAX_STR + 10]; if (!dumpon) return; if (fphase == NULL) { sprintf(s,"%s_phase.txt", prefix); fphase = fopen(s, "wt"); assert(fphase != NULL); } for(l=1; l<=L; l++) fprintf(fphase,"%f\t",phase[l]); for(l=L+1; l<=MAX_AMP; l++) fprintf(fphase,"%f\t",0.0); fprintf(fphase,"\n"); } void dump_phase_(float phase_[], int L) { int l; char s[MAX_STR + 11]; if (!dumpon) return; if (fphase_ == NULL) { sprintf(s,"%s_phase_.txt", prefix); fphase_ = fopen(s, "wt"); assert(fphase_ != NULL); } for(l=1; l<=L; l++) fprintf(fphase_,"%f\t",phase_[l]); for(l=L+1; l