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

📄 mp_maxima.c

📁 LastWave
💻 C
📖 第 1 页 / 共 3 页
字号:
/*..........................................................................*//*                                                                          *//*      L a s t W a v e    P a c k a g e 'mp' 2.1                           *//*                                                                          *//*      Copyright (C) 2000 Remi Gribonval, Emmanuel Bacry and Javier Abadia.*//*      email  : remi.gribonval@inria.fr                                    *//*      email  : lastwave@cmap.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             *//*                                                                          *//*..........................................................................*/#include "lastwave.h"#include "mp_book.h"/*************************************//* *	MAXIMADICT VARIABLES *//*************************************/char *maximaDictType = "&maximadict";/* * Answers to the different print messages */void ShortPrintMaximaDict(MAXIMADICT maximaDict){  Printf("<&maximadict;%p>\n",maximaDict);}char *ToStrMaximaDict(MAXIMADICT maximaDict, char flagShort){  static char str[30];    sprintf(str,"<&maximadict;%p>",maximaDict);  return(str);}void PrintInfoMaximaDict(MAXIMADICT maximaDict){  PrintMaximaDict(maximaDict,NO);}MAXIMADICT TNewMaximaDict(void){  MAXIMADICT maximaDict;    maximaDict = NewMaximaDict();  TempValue(maximaDict);  return(maximaDict);}/* * Get the current maximaDict * (generate an error if there is none) */MAXIMADICT GetMaximaDictCur(void){  MAXIMADICT maximaDict;    if(!ParseTypedValLevel_(levelCur,"objCur",NULL,(VALUE *)&maximaDict,maximaDictType)) Errorf1("");    if (maximaDict == NULL) Errorf1("");    AddRefValue(maximaDict);  TempValue(maximaDict);    return(maximaDict);}/*******************************************//* *	Basic data management for MAXIMADICT */				    /*******************************************/MAXIMADICT NewMaximaDict(){  MAXIMADICT maximaDict;  #ifdef DEBUGALLOC  DebugType = "MaximaDict";#endif    maximaDict = (MAXIMADICT) Malloc(sizeof(struct maximaDict));  InitValue(maximaDict,&tsMaximaDict);  maximaDict->size = 0;  maximaDict->sizeAlloc = 0;  maximaDict->books = NULL;  maximaDict->subDicts = NULL;  maximaDict->nMaximaTarget = 0;  maximaDict->nMaxima       = 0;  maximaDict->threshold     = 0.0;  maximaDict->maxMolecule       = NULL;  return(maximaDict);}MAXIMADICT DeleteMaximaDict(MAXIMADICT maximaDict){  unsigned short i;  if (maximaDict == NULL)  Errorf("DeleteMaximaDict : NULL maximaDict");  if (maximaDict->nRef==0) Errorf("*** Danger : trying to delete a temporary maximaDict\n");  RemoveRefValue(maximaDict);  if (maximaDict->nRef > 0) return(NULL);    if(maximaDict->books) {    for(i=0; i<= maximaDict->size; i++) {if(maximaDict->books[i]) 	maximaDict->books[i] = DeleteBook(maximaDict->books[i]);    }    Free(maximaDict->books);    maximaDict->books = NULL;  }    // We do not delete the subDicts because we did not add a reference to them  if(maximaDict->subDicts) {    Free(maximaDict->subDicts);    maximaDict->subDicts = NULL;  }    maximaDict->size = 0;  maximaDict->sizeAlloc = 0;  maximaDict->nMaximaTarget = 0;  maximaDict->nMaxima       = 0;  maximaDict->threshold     = 0.0;  if(maximaDict->maxMolecule) maximaDict->maxMolecule = DeleteMolecule(maximaDict->maxMolecule);#ifdef DEBUGALLOC  DebugType = "MaximaDict";#endif    Free(maximaDict);  return(NULL);}void ClearMaximaDict(MAXIMADICT maximaDict){  unsigned short i;  if (maximaDict == NULL)  Errorf("ClearMaximaDict : NULL maximaDict");    if(maximaDict->books) {    for(i=0; i<= maximaDict->size; i++) {if(maximaDict->books[i]) 	maximaDict->books[i] = DeleteBook(maximaDict->books[i]);    }    // Note : we do not delete the array, we keep it for a later use  }    if(maximaDict->subDicts) {    for(i=0; i<= maximaDict->size; i++) {      // We do not delete subDicts because they were not allocated here and were not added a reference.      maximaDict->subDicts[i] = NULL;    }    // Note : we do not delete the array, we keep it for a later use  }    maximaDict->size = 0;  maximaDict->nMaximaTarget = 0;  maximaDict->nMaxima       = 0;  maximaDict->threshold     = 0.0;  if(maximaDict->maxMolecule) maximaDict->maxMolecule = DeleteMolecule(maximaDict->maxMolecule);}// Prints the content of a maximaDictionary, in long or short form// TODO : improve thatvoid PrintMaximaDict(const MAXIMADICT maximaDict,char flagShort){  unsigned short i;  BOOK book;  Printf("size      = %d (sizeAlloc = %d)\n",maximaDict->size,maximaDict->sizeAlloc);  Printf("nMaxima   = %d (target = %d)\n",maximaDict->nMaxima,maximaDict->nMaximaTarget);  Printf("threshold = %g\n",maximaDict->threshold);  Printf("maxmolecule :\n");  if(maximaDict->maxMolecule) PrintMolecule(maximaDict->maxMolecule,YES);  else Printf("NULL\n");  for(i = 0; i < maximaDict->size; i++) {    book = maximaDict->books[i];    Printf("book[%d] size=%d\n",i,book->size);  }}// Function that generates an error if the maximaDictionary does not contain any sub-dictionaryvoid CheckMaximaDictNotEmpty(const MAXIMADICT maximaDict){  if(maximaDict == NULL)    Errorf("CheckMaximaDictNotEmpty : NULL maximaDict");  if(maximaDict->size == 0) Errorf("CheckMaximaDictNotEmpty : empty maximaDict");}// If 'sizeAlloc' is smaller than maximaDict->size, an error is generated.// Else the allocation size of the arrays of books/sub-dictionaries are adjusted :// -the newly allocated part of the array is initialized to NULL books/sub-dictionaries;// -the previously allocated part is kept (maximaDict->size is not changed)void SizeMaximaDict(MAXIMADICT maximaDict,unsigned short sizeAlloc){  unsigned short i;  if(sizeAlloc<maximaDict->size) Errorf("SizeMaximaDict : cannot (re)allocate less than the number of books/sub-dictionaries");  if(sizeAlloc==maximaDict->size) return;  // Case of an first allocation  if(maximaDict->sizeAlloc == 0) {    maximaDict->books     =(BOOK *)    Calloc(sizeAlloc,sizeof(BOOK));    maximaDict->subDicts  =(SUBDICT *) Calloc(sizeAlloc,sizeof(SUBDICT));    maximaDict->sizeAlloc = sizeAlloc;  }  // Case of a resize  else {    maximaDict->books    =(BOOK *)    Realloc(maximaDict->books,sizeAlloc*sizeof(BOOK));    maximaDict->subDicts =(SUBDICT *) Realloc(maximaDict->subDicts,sizeAlloc*sizeof(SUBDICT));    // Initialize the newly allocated data, if necessary    for(i = maximaDict->sizeAlloc; i < sizeAlloc; i++) {      maximaDict->books[i]   =NULL;      maximaDict->subDicts[i]=NULL;    }    maximaDict->sizeAlloc = sizeAlloc;  }}// Add a sub-dictionary and creates the corresponding book for storing its local maxima.// If the sub-dictionary is not a 'main' one an error is generated.// The sub-dictionary becomes an 'auxiliary' one.// WARNING : should only be used with subDicts that already belong to a dictionary!void AddSubDict2MaximaDict(MAXIMADICT maximaDict,SUBDICT subDict) {  if(subDict->dict==NULL)   Errorf("AddSubDict2MaximaDict : (Weired) the sub-dictionary does not belong to any dictionary!");  if(subDict->flagMain==NO) Errorf("AddSubDict2MaximaDict : (Weired) the sub-dictionary is not a 'main' one");  if(maximaDict->threshold!= 0.0 || maximaDict->nMaxima!=0 || maximaDict->maxMolecule!=NULL)    Errorf("AddSubDict2MaximaDict : (Weired) maximaDict content has already been initialized %g %d %p",	   maximaDict->threshold,maximaDict->nMaxima,maximaDict->maxMolecule);  // In case we need to allocate more room  if(maximaDict->size==maximaDict->sizeAlloc) {    if(maximaDict->sizeAlloc==0) SizeMaximaDict(maximaDict,MP_DEFAULT_DICT_SIZE);    else                         SizeMaximaDict(maximaDict,2*maximaDict->sizeAlloc);  }  maximaDict->books[maximaDict->size] = NewBook();  maximaDict->subDicts[maximaDict->size]=subDict; // We do not add a reference because subDicts don't have ValueFields!  subDict->flagMain = NO;  maximaDict->size++;}/**************************************//*  * MANAGEMENT OF A LIST OF COEFF2S  *//**************************************/#define MAXCOEFFS_SIZEMIN 1<<13typedef struct maxCoeffs {  unsigned long size;  unsigned long sizeAlloc;  LWFLOAT *coeff2s;  LWFLOAT coeff2Min;  LWFLOAT coeff2Max;} *MAXCOEFFS;static MAXCOEFFS NewMaxCoeffs(void){  MAXCOEFFS maxCoeffs = NULL;  #ifdef DEBUGALLOC  DebugType = "MaxCoeffs";#endif    maxCoeffs = (MAXCOEFFS) Malloc(sizeof(struct maxCoeffs));  maxCoeffs->size = maxCoeffs->sizeAlloc = 0;  maxCoeffs->coeff2s = NULL;  maxCoeffs->coeff2Min = 0.0;  maxCoeffs->coeff2Max = 0.0;  return(maxCoeffs);}static MAXCOEFFS DeleteMaxCoeffs(MAXCOEFFS maxCoeffs){  if(maxCoeffs == NULL) Errorf("DeleteMaxCoeffs : NULL input");  if(maxCoeffs->coeff2s) {    Free(maxCoeffs->coeff2s);    maxCoeffs->coeff2s = NULL;    maxCoeffs->size = maxCoeffs->sizeAlloc = 0;  }  #ifdef DEBUGALLOC  DebugType = "MaxCoeffs";#endif

⌨️ 快捷键说明

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