⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pf_alloc.c

📁 LastWave
💻 C
📖 第 1 页 / 共 3 页
字号:
/*..........................................................................*//*                                                                          *//*  L a s t W a v e    P a c k a g e 'wtmm1d' 2.1                           *//*                                                                          *//*      Copyright (C) 1998-2005 Benjamin Audit                              *//*      email : Benjamin.Audit@ens-lyon.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             *//*                                                                          *//*..........................................................................*/#include "wtmm1d.h"char *partitionFunctionType = "&PF";/* A simple fonction that returns the FILE * associated to a STREAM */static FILE *stream2File(STREAM stream){  /* If there is a FILE * defined just return it */  if(stream->stream != NULL)    return stream->stream;  /* We compare the stream->id to see if it correspond to standard STREAM */  /*  if(stream->id == _StdinStream->id)      return stdin;      if(stream->id == _StdoutStream->id)      return stdout;      if(stream->id == _StderrStream->id)      return stderr;      */    /* Otherwise an error occurs */  Errorf("stream2File() : Sorry no FILE* associated to that STREAM.");  return NULL;}/* * Answers to the different print messages */ void PrintPartitionFunction(LWPARTFUNC lwpf){  char method[PFMETHODSIZE+1];  PFGetMethod(lwpf->pf,method);  Printf("<'%s';&PF[%d,%d];%p>\n",	 method,	 PFGetOctaveNumber(lwpf->pf),	 PFGetVoiceNumber(lwpf->pf),	 lwpf	 );}char *ToStrPartitionFunction(LWPARTFUNC lwpf, char flagShort){  static char str[PFMETHODSIZE+1+6];  char method[PFMETHODSIZE+1];    PFGetMethod(lwpf->pf,method);    sprintf(str,"<&PF;%s>",method);    return(str);}void PrintInfoPartitionFunction(LWPARTFUNC lwpf){  char method[PFMETHODSIZE+1];  int number,i;  PFGetMethod(lwpf->pf,method);      Printf("  method           : %10s\n",method);  Printf("  minimum scale    : %10.2f\n",PFGetAMin(lwpf->pf));  Printf("  number of octave : %10d\n",PFGetOctaveNumber(lwpf->pf));  Printf("  number of voice  : %10d\n",PFGetVoiceNumber(lwpf->pf));  Printf("  list of q values : ");    number = PFGetQNumber(lwpf->pf);  if(number <= 0)    Printf("\n");  else    {      Printf("%10.2f", PFGetQ(lwpf->pf,0) );      for(i=1;i<number;i++)	Printf(", %.2f", PFGetQ(lwpf->pf,i) );    }  Printf("\n");}/**************************************************************************** * *  Some useful internal functions to deal with partition functions * ****************************************************************************//* Return a temporary pointer to double with all the numerical values in the   LISTV (supposed to contain only numerical values).   On errors set the error string and returns NULL.*/static double *PFListv2QArray(LISTV lv){  double *qArray;  int qNumber = lv->length;  int iq;  if (qNumber < 1) {      SetErrorf("PFListv2QArray : listv is empty");      return(NULL);  }  /* TMalloc() : generates an error if allocation fails     -> can't return NULL is that case  */  qArray = (double *) TMalloc(qNumber*sizeof(double));  for(iq=0;iq<qNumber;iq++) {    if (lv->values[iq] == NULL) {      qArray[iq] = lv->f[iq];      continue;    }        if (GetTypeValue(lv->values[iq]) != numType) {      SetErrorf("PFListv2QArray() : Bad element of type '%s'",		GetTypeValue(lv->values[iq]));      return(NULL);    }    qArray[iq] = CastValue(lv->values[iq],NUMVALUE)->f;  }  return(qArray);}/* Return a temporary pointer to double with all the numerical values in the   signal (supposed to contain only numerical values).   On errors set the error string and returns NULL.*/static double *PFSignal2QArray(SIGNAL sig){  double *qArray;  int qNumber = sig->size;  int iq;  if (qNumber < 1) {      SetErrorf("PFSignal2QArray : signal is empty");      return(NULL);  }  /* TMalloc() : generates an error if allocation fails     -> can't return NULL is that case  */  qArray = (double *) TMalloc(qNumber*sizeof(double));  for(iq=0;iq<qNumber;iq++) {    qArray[iq] = sig->Y[iq];  }      return(qArray);}/* Return a temporary pointer to int with all the numerical values in the   LISTV (supposed to contain only numerical values) rounded to integer values.   On errors set the error string and returns NULL.*/static int *PFListv2IndArray(LISTV lv){  int *indArray;  int indNumber = lv->length;  int i;  if (indNumber < 1) {      SetErrorf("PFListv2IndArray : listv is empty");      return(NULL);  }  /* TMalloc() : generates an error if allocation fails     -> can't return NULL is that case  */  indArray = (int *) TMalloc(indNumber*sizeof(int));  for(i=0;i<indNumber;i++) {    if (lv->values[i] == NULL) {      indArray[i] = (int) (lv->f[i]+0.5); /* values should be >=0 */      continue;    }        if (GetTypeValue(lv->values[i]) != numType) {      SetErrorf("PFListv2IndArray() : Bad element of type '%s'",		GetTypeValue(lv->values[i]));      return(NULL);    }    indArray[i] = (int) (CastValue(lv->values[i],NUMVALUE)->f+0.5 );  }  return(indArray);}/* Return a temporary pointer to signal with the corresponding partition    function (determined by type and indQ).   On errors set the error string and returns NULL.*/static SIGNAL PFIndQ2Signal(LWPARTFUNC lwpf,char *type,int indQ,int mode){  SIGNAL signal = TNewSignal();  int size,res,i;  LWFLOAT sln2;  size = PFAccessSize(lwpf->pf);  if(size == -1) {    SetErrorf("PFIndQ2Signal() : pf is not valid");    return(NULL);  } else if (size == 0) {    SetErrorf("PFIndQ2Signal() : pf's qList is empty");    return(NULL);  }  SizeSignal(signal,size,YSIG);  signal->x0 = (LWFLOAT) (log(PFGetAMin(lwpf->pf))/log(2.));  signal->dx = 1./((LWFLOAT) PFGetVoiceNumber(lwpf->pf));  signal->lastp = PFGetIndexMax(lwpf->pf);        if (!strcmp(type,"t"))    res = PFAccessTQFLOAT(lwpf->pf,indQ,mode,signal->Y);    else if (!strcmp(type,"h"))    res = PFAccessHQFLOAT(lwpf->pf,indQ,mode,signal->Y);    else if (!strcmp(type,"d"))    res = PFAccessDQFLOAT(lwpf->pf,indQ,mode,signal->Y);    else if (!strcmp(type,"st"))    res = PFAccessVarTQFLOAT(lwpf->pf,indQ,signal->Y);    else if (!strcmp(type,"sh"))    res = PFAccessVarHQFLOAT(lwpf->pf,indQ,signal->Y);    else if (!strcmp(type,"sd"))    res = PFAccessVarDQFLOAT(lwpf->pf,indQ,signal->Y);    else {    SetErrorf("PFIndQ2Signal() : type must be t, h, d, st, sh or sd");    return(NULL);  }    /* covert variance to stddev if necessary */  if (type[0] == 's') {    for(i=0;i < size; i++)      signal->Y[i] = sqrt(signal->Y[i]);  }  /* pf_lib uses the natural log so we divide by ln2 */  sln2 = 1/log(2.0);  for(i=0;i < size; i++)    signal->Y[i] *= sln2;        switch(res)    {    case PFYes:      return(signal);      break;    case PFNotValid:      SetErrorf("PFIndQ2Signal() : "		"one of the arguments passed to PFAccess%sQFloat was not valid",		type);      return(NULL);      break;    default:      SetErrorf("PFIndQ2Signal() : "		"serious error. (maybe the pointer lwpf->pf was NULL)");      return(NULL);    }    /* We should never reach this point */  return(signal);}/* Return a temporary pointer to a signal with the corresponding partition    function (determined by type and q).   On errors set the error string and returns NULL.*/static SIGNAL PFQ2Signal(LWPARTFUNC lwpf,char *type,double q,int mode){  int indQ;  /* Is this q in the qList */  indQ = PFAccessIndQ(lwpf->pf, q);  if(indQ == -1) {    SetErrorf("PFQ2Signal() : %g is not in the qList",q);    return(NULL);  }  return( PFIndQ2Signal(lwpf,type,indQ,mode) );}/* Return a temporary pointer to a LISTV with the corresponding partition    function (determined by type and numerical values in LISTV).   On errors set the error string and returns NULL.*/static LISTV PFListvQ2ListvSig(LWPARTFUNC lwpf,LISTV lvq,char *type,int mode){  int i;  double *qArray;  LISTV lvsig = TNewListv();  SIGNAL signal;  if( (qArray = PFListv2QArray(lvq)) == NULL ) {    return(NULL);  }  SetLengthListv(lvsig, lvq->length);  for(i=0;i<lvq->length;i++) {    if( (signal = PFQ2Signal(lwpf,type,qArray[i],mode)) == NULL )      return(NULL);    SetListvNthValue(lvsig,i,(VALUE) signal);  }  return(lvsig);}/* Return a temporary pointer to a LISTV with the corresponding partition    function (determined by type and q index values in LISTV).   On errors set the error string and returns NULL.*/static LISTV PFListvInd2ListvSig(LWPARTFUNC lwpf,LISTV lvind,char *type,int mode){  int i;  int *indArray;  LISTV lvsig = TNewListv();  SIGNAL signal;  if( (indArray = PFListv2IndArray(lvind)) == NULL ) {    return(NULL);  }  SetLengthListv(lvsig, lvind->length);  for(i=0;i<lvind->length;i++) {    if( (signal = PFIndQ2Signal(lwpf,type,indArray[i],mode)) == NULL )      return(NULL);    SetListvNthValue(lvsig,i,(VALUE) signal);  }  return(lvsig);}/* Return a temporary pointer to a LISTV with the corresponding partition    function (determined by type and numerical values in signal).   On errors set the error string and returns NULL.*/static LISTV PFSigQ2ListvSig(LWPARTFUNC lwpf,SIGNAL sigq,char *type,int mode){  int i;  LISTV lvsig = TNewListv();  SIGNAL signal;  if (sigq->size < 1) {      SetErrorf("PFSigQ2ListvSig : q value signal is empty.");      return(NULL);  }  SetLengthListv(lvsig, sigq->size);  for(i=0;i<sigq->size;i++) {    if( (signal = PFQ2Signal(lwpf,type,sigq->Y[i],mode)) == NULL )      return(NULL);    SetListvNthValue(lvsig,i,(VALUE) signal);  }  return(lvsig);}/* Return a temporary pointer to a LISTV with the corresponding partition    function (determined by type and numerical values in signal).   On errors set the error string and returns NULL.*/static LISTV PFSigInd2ListvSig(LWPARTFUNC lwpf,SIGNAL sigind,char *type,int mode){  int i;  LISTV lvsig = TNewListv();  SIGNAL signal;  if (sigind->size < 1) {      SetErrorf("PFSigInd2ListvSig : q index value signal is empty.");      return(NULL);  }  SetLengthListv(lvsig, sigind->size);  for(i=0;i<sigind->size;i++) {    if( (signal = PFIndQ2Signal(lwpf,type,(int) (sigind->Y[i]+0.5),mode)) == NULL )      return(NULL);    SetListvNthValue(lvsig,i,(VALUE) signal);  }  return(lvsig);}/* Return a temporary pointer to a LISTV with the list of q's.   On errors set the error string and returns NULL.*/static LISTV PF2ListvQ(LWPARTFUNC lwpf){  LISTV lvq = TNewListv();  int iq,qNumber;  qNumber = PFGetQNumber(lwpf->pf);  if( qNumber <= 0 ) {    SetResultf("PF2ListvQ() : Empty qlist !!");    return(NULL);  }  SetLengthListv(lvq, qNumber);  for(iq=0;iq<qNumber;iq++) {    SetListvNthFloat(lvq,iq,PFGetQFLOAT(lwpf->pf,iq));  }  return(lvq);}/* Return a temporary pointer to a LISTV with the corresponding partition    function for all q's (determined by type).   On errors set the error string and returns NULL.*/static LISTV PF2ListvSig(LWPARTFUNC lwpf,char *type,int mode){  LISTV lvsig = TNewListv();  SIGNAL signal;  int iq,qNumber;  qNumber = PFGetQNumber(lwpf->pf);  if( qNumber <= 0 ) {    SetResultf("PF2ListvSig() : Empty qlist !!");    return(NULL);  }  SetLengthListv(lvsig, qNumber);  for(iq=0;iq<qNumber;iq++) {    if( (signal = PFIndQ2Signal(lwpf,type,iq,mode)) == NULL )      return(NULL);    SetListvNthValue(lvsig,iq,(VALUE) signal);  }  return(lvsig);}/***************************************************************************** * *  Allocation and Desallocation * *****************************************************************************//*  * Allocation of a partition function */LWPARTFUNC NewPartitionFunction(void){  extern TypeStruct tsPartitionFunction;  LWPARTFUNC lwpf;#ifdef DEBUGALLOC  DebugType = "Pf";#endif  lwpf = (LWPARTFUNC) Malloc(sizeof(struct LastWavePartitionFunction));  InitValue(lwpf,&tsPartitionFunction);  lwpf->pf = PFNew();  return(lwpf);}/* * Desallocation of a partition function */void DeletePartitionFunction(LWPARTFUNC lwpf){  RemoveRefValue(lwpf);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -