wtrans_file.c
来自「LastWave」· C语言 代码 · 共 234 行
C
234 行
/*..........................................................................*//* *//* L a s t W a v e P a c k a g e 'wtrans1d' 2.1 *//* *//* Copyright (C) 1998-2002 Emmanuel Bacry. *//* email : lastwave@polytechnique.fr *//* *//*..........................................................................*//* *//* This program is a free software, you can redistribute it and/or *//* modify it under the terms of the GNU General Public License as *//* published by the Free Software Foundation; either version 2 of the *//* License, or (at your option) any later version *//* *//* 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 General Public License *//* along with this program (in a file named COPYRIGHT); *//* if not, write to the Free Software Foundation, Inc., *//* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//* *//*..........................................................................*//****************************************************************************//* *//* wtrans_file.c write/read a wtrans *//* *//****************************************************************************/#include "lastwave.h"#include "wtrans1d.h"/**************************************************** * * Write a wtrans * ****************************************************/void WriteBinWtransStream (WTRANS wtrans,STREAM s){ int o,v; FILE *stream; /* Some basic tests on the stream */ if (s->mode != StreamWrite) Errorf("WriteBinWtransStream() :The stream should be an output stream and not an input stream"); if (s->stream == NULL) Errorf("WriteBinWtransStream() : You cannot write a signal to standard output"); stream = s->stream; /* Write header */ fprintf(stream,"Number octaves %d\n",wtrans->nOct); fprintf(stream,"Number voices %d\n",wtrans->nVoice); fprintf(stream,"size %d\n",wtrans->size);#ifdef NUMDOUBLE fprintf(stream,"x0 %.16g\n",wtrans->x0); fprintf(stream,"dx %.16g\n",wtrans->dx);#else fprintf(stream,"x0 %.8g\n",wtrans->x0); fprintf(stream,"dx %.8g\n",wtrans->dx);#endif fprintf(stream,"Type %d\n",wtrans->type);#ifdef NUMDOUBLE fprintf(stream,"Smallest scale %.16g\n",wtrans->aMin);#else fprintf(stream,"Smallest scale %.8g\n",wtrans->aMin);#endif fprintf(stream,"Wavelet name : %s\n",wtrans->wName); for(o=1;o<=wtrans->nOct;o++) for(v=0;v<wtrans->nVoice;v++) WriteSigStream(wtrans->D[o][v],s,YES,"y",YES,"",""); if (wtrans->type == W_ORTH) WriteSigStream(wtrans->A[o-1][0],s,YES,"y",YES,"",""); }void WriteBinWtransFile (WTRANS wtrans,char *filename){ STREAM stream; CheckWtrans(wtrans); /* Open file */ stream = OpenFileStream(filename,"w"); if (stream == NULL) Errorf("WriteBinWtrans() : Error while opening the file %s",filename); /* read */ WriteBinWtransStream(wtrans,stream); /* Close */ CloseStream(stream);} /* The command */ void C_WWrite (char **argv){ WTRANS wtrans; char *filename; STREAM stream; argv = ParseArgv(argv,tWTRANS_,NULL,&wtrans,-1); if (wtrans == NULL) wtrans = GetWtransCur(); argv = ParseArgv(argv,tSTREAM_,NULL,&stream,-1); if (stream == NULL) argv = ParseArgv(argv,tSTR,&filename,-1); else filename = NULL; NoMoreArgs(argv); CheckWtrans(wtrans); if (filename == NULL) WriteBinWtransStream(wtrans,stream); else WriteBinWtransFile(wtrans,filename);}/**************************************************** * * Read a wtrans * ****************************************************/void ReadBinWtransStream (WTRANS wtrans,STREAM s){ int n,o,v,size; LWFLOAT aMin,x0,dx; int nOct,nVoice,type; char wName[20]; FILE *stream; /* Some basic tests on the stream */ if (s->mode != StreamRead) Errorf("ReadBinWtransStream() :The stream should be an input stream and not an output stream"); if (s->stream == NULL) Errorf("ReadBinWtransStream() : You cannot write a signal to standard input"); stream = s->stream; /* Let's read the header */ n = 0; x0 = 0; dx = 1; size = -1; n += fscanf(stream,"Number octaves %d ",&nOct); n += fscanf(stream,"Number voices %d ",&nVoice); n += fscanf(stream,"size %d ",&size);#ifdef NUMDOUBLE n += fscanf(stream,"x0 %lf ",&x0); n += fscanf(stream,"dx %lf ",&dx);#else n += fscanf(stream,"x0 %f ",&x0); n += fscanf(stream,"dx %f ",&dx);#endif n += fscanf(stream,"Type %d ",&type);#ifdef NUMDOUBLE n += fscanf(stream,"Smallest scale %lf ",&aMin);#else n += fscanf(stream,"Smallest scale %f ",&aMin);#endif n += fscanf(stream,"Wavelet name : %s ",wName); if (n < 5) Errorf("Error in the header of the file"); wtrans->nOct = nOct; wtrans->nVoice = nVoice; wtrans->size = size; wtrans->type = type; wtrans->aMin = aMin; wtrans->dx = dx; wtrans->x0 = x0; if (wtrans->wName != NULL) Free(wtrans->wName); wtrans->wName = CopyStr(wName); for(o=1;o<=wtrans->nOct;o++) for(v=0;v<wtrans->nVoice;v++) ReadSigStream(wtrans->D[o][v],s,0,-1,0,0); if (wtrans->type == W_ORTH) ReadSigStream(wtrans->A[o-1][0],s,0,-1,0,0); if (wtrans->size <= 0) wtrans->size = wtrans->D[1][0]->size; }void ReadBinWtransFile (WTRANS wtrans,char *filename){ STREAM stream; /* Open file */ stream = OpenFileStream(filename,"r"); if (stream == NULL) Errorf("ReadBinWtrans() : Error while opening the file %s",filename); /* read */ ReadBinWtransStream(wtrans,stream); /* Close */ CloseStream(stream);} /* The command */ void C_WRead (char **argv){ WTRANS wtrans; char *filename; STREAM stream; argv = ParseArgv(argv,tWTRANS_,NULL,&wtrans,-1); if (wtrans == NULL) wtrans = GetWtransCur(); argv = ParseArgv(argv,tSTREAM_,NULL,&stream,-1); if (stream == NULL) argv = ParseArgv(argv,tSTR,&filename,-1); else filename = NULL; NoMoreArgs(argv); if (filename == NULL) ReadBinWtransStream(wtrans,stream); else ReadBinWtransFile(wtrans,filename);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?