📄 ext_alloc.c
字号:
/* Desallocate an extrep */void DeleteExtrep(EXTREP extrep){ int i,j; RemoveRefValue(extrep); if (extrep->nRef > 0) return; DeleteSignal(extrep->coarse); DeleteFilterGroup(extrep->fg); for(i=0;i<NOCT;i++) for(j=0;j<NVOICE;j++) DeleteExtlis(extrep->D[i][j]); if (extrep->name != NULL && extrep->name != defaultName) Free(extrep->name); if (extrep->wName != NULL) Free(extrep->wName); if (extrep->wtrans != NULL) extrep->wtrans->extrep = NULL;#ifdef DEBUGALLOCDebugType = "Extrep1d";#endif Free(extrep); }/* Initialization of an extrema representation */void ClearExtrep (EXTREP extrep){ int i,j; extrep->size = 0; extrep->dx = 0.; extrep->x0 = 0.; extrep->nOct = 0; extrep->nVoice = 0; if (extrep->wName != NULL) Free(extrep->wName); extrep->wName = NULL; ClearSignal(extrep->coarse); for(i=0;i<NOCT;i++) for(j=0;j<NVOICE;j++) ClearExtlis(extrep->D[i][j]); }/* Allocate an extrema representation */EXTREP NewExtrep(void){ extern TypeStruct tsExtrep; EXTREP extrep; int i,j;#ifdef DEBUGALLOCDebugType = "Extrep1d";#endif extrep = (EXTREP) (Malloc(sizeof(struct extrep))); InitValue(extrep,&tsExtrep); for(i=0;i<NOCT;i++) for(j=0;j<NVOICE;j++) { extrep->D[i][j] = NewExtlis(); extrep->D[i][j]->extrep = extrep; } extrep->name = defaultName; extrep->coarse = NewSignal(); extrep->size = 0; extrep->dx = 0.; extrep->x0 = 0.; extrep->nOct = 0; extrep->nVoice = 0; extrep->fg = NULL; extrep->wtrans = NULL; extrep->wName = NULL; return(extrep);}/* * Answers to the different print messages */ void PrintExtrep(EXTREP extrep){ if (extrep->name == NULL) Printf("<&extrep[%d,%d];%p>\n",extrep->nOct,extrep->nVoice,extrep); else Printf("<'%s';&extrep[%d,%d];%p>\n",extrep->name,extrep->nOct,extrep->nVoice,extrep);}char *ToStrExtrep(EXTREP extrep, char flagShort){ static char str[30]; if (extrep->name == defaultName) { sprintf(str,"<&extrep;%p>",extrep); } else { sprintf(str,"<&extrep;%s>",extrep->name); } return(str);}void PrintInfoExtrep(EXTREP extrep){ Printf(" number of octave : %2d\n",extrep->nOct); Printf(" number of voice : %2d\n\n",extrep->nVoice);}/* * Extract an ext from a extrep : wtrans->D[i1,i2] */static EXT ExtractExt(EXTREP extrep, char *field, FSIList *fsiList){ int i1,i2; /* There must be [] */ if (fsiList == NULL) { SetErrorf("Field D needs extraction : D[]"); return(NULL); } /* 1 or 2 integers in between the [] */ if (fsiList->nx == 0 || fsiList->nx > 2) { SetErrorf("D[] expects 1 or 2 indexes"); return(NULL); } /* Get the integers */ i1 = (int) FSI_FIRST(fsiList); if (fsiList->nx == 1) i2 = 0; else i2 = (int) FSI_SECOND(fsiList); /* Test wether they are in the right range */ if (i1 < 0 || i1 >= extrep->nOct) { SetErrorf("Octave index '%d' out of range : should be in [0,%d]",i1,extrep->nOct-1); return(NULL); } if (i2 < 0 || i2 >= extrep->nVoice) { SetErrorf("Voice index '%d' out of range : should be in [0,%d]",i2,extrep->nVoice-1); return(NULL); } return(extrep->D[i1][i2]->first);}/* * Get of field D */static char *Ddoc = "{[o,v]} {Get the first extrema at octave 'o' and voice 'v'}"; static void *GetExtractExtrepV(VALUE val, void **arg){ EXTREP extrep; char *field; FSIList *fsiList; EXT ext; /* doc */ if (val == NULL) { if (!strcmp(ARG_G_GetField(arg),"D")) return(Ddoc); } extrep = (EXTREP) val; field = ARG_G_GetField(arg); fsiList = ARG_G_GetFsiList(arg); ext = ExtractExt(extrep,field,fsiList); if (ext == NULL) return(NULL); ARG_G_SetResValue(arg,ext); return(GetTypeValue(ext));} /* * Get the options for extraction (called for field D only) : There is none !! */static void *GetExtractOptionsExtrepV(VALUE val, void **arg){ static char *extractOptionsExtrep[] = {NULL}; return(extractOptionsExtrep);}/* * Function to get the ExtractInfo for field D */static void *GetExtractInfoExtrepV(VALUE val, void **arg){ static ExtractInfo extractInfo; static char flagInit = YES; /* Init of the extraction info */ if (flagInit) { extractInfo.nSignals = 1; extractInfo.xmax = MAX(NOCT-1,NVOICE-1); extractInfo.dx = 1; extractInfo.xmin = 0; extractInfo.flags = EIIntIndex | EIErrorBound; flagInit = NO; } return(&extractInfo);}/* * 'name' field */static char *nameDoc = "{[= <name>]} {Sets/Gets the name of an extrep}";static void * GetNameExtrepV(VALUE val, void **arg){ /* Documentation */ if (val == NULL) return(nameDoc); return(GetStrField(((EXTREP) val)->name,arg));}static void * SetNameExtrepV(VALUE val, void **arg){ EXTREP extrep = (EXTREP) val; /* doc */ if (val == NULL) return(nameDoc); if (extrep->name==defaultName) { extrep->name=CharAlloc(1); extrep->name[0] = '\0'; } return(SetStrField(&(extrep->name),arg));}/* * 'dx' field */static char *dxDoc = "{[= <dx>]} {Sets/Gets the abscissa step of the original signal of the extrema representation.}";static void * GetDxExtrepV(VALUE val, void **arg){ /* Documentation */ if (val == NULL) return(dxDoc); return(GetFloatField(((EXTREP) val)->dx,arg));}static void * SetDxExtrepV(VALUE val, void **arg){ /* Documentation */ if (val == NULL) return(dxDoc); return(SetFloatField(&(((EXTREP) val)->dx),arg,FieldSPositive));}/* * 'x0' field */static char *x0Doc = "{[= <x0>]} {Sets/Gets the first abscissa of the original signal of the extrep.}";static void * GetX0ExtrepV(VALUE val, void **arg){ /* Documentation */ if (val == NULL) return(x0Doc); return(GetFloatField(((EXTREP) val)->x0,arg));}static void * SetX0ExtrepV(VALUE val, void **arg){ /* Documentation */ if (val == NULL) return(x0Doc); return(SetFloatField(&(((EXTREP) val)->x0),arg,0));}/* * 'size' field */static char *sizeDoc = "{[= <size>]} {Sets/Gets the size of the original signal of the extrema representation.}";static void * GetSizeExtrepV(VALUE val, void **arg){ /* Documentation */ if (val == NULL) return(sizeDoc); return(GetIntField(((EXTREP) val)->size,arg));}static void * SetSizeExtrepV(VALUE val, void **arg){ /* Documentation */ if (val == NULL) return(sizeDoc); return(SetIntField(&(((EXTREP) val)->size),arg,FieldPositive));}/* * 'wavelet' field */static char *waveletDoc = "{[= <name>]} {Gets/Sets the name of the analyzing wavelet used for the extrema representation.}";static void * GetWaveletExtrepV(VALUE val, void **arg){ /* Documentation */ if (val == NULL) return(waveletDoc); if (((EXTREP) val)->wName == NULL) return(GetStrField("",arg)); return(GetStrField(((EXTREP) val)->wName,arg));}static void * SetWaveletExtrepV(VALUE val, void **arg){ /* Documentation */ if (val == NULL) return(waveletDoc); if (((EXTREP) val)->wName == NULL) { ((EXTREP) val)->wName = CharAlloc(1); ((EXTREP) val)->wName[0] = '\0'; } return(SetStrField(&(((EXTREP) val)->wName),arg));}/* * 'wtrans' field */static char *wtransDoc = "{} {Gets the wavelet transform associated to the extrema representation.}";static void * GetWtransExtrepV(VALUE val, void **arg){ /* Documentation */ if (val == NULL) return(wtransDoc); if (((EXTREP) val)->wtrans == NULL) return(GetValueField(nullValue,arg)); return(GetValueField(((EXTREP) val)->wtrans,arg));}/* * 'nvoice' field */ static char *nvoiceDoc = "{} {Gets the number of voices per octave of the extrema representation.}"; static void * GetNVoiceExtrepV(VALUE val, void **arg){ /* Documentation */ if (val == NULL) return(nvoiceDoc); return(GetIntField(((EXTREP) val)->nVoice,arg));}/* * 'noct' field */static char *noctDoc = "{} {Gets the number of octave of the extrema representation.}";static void * GetNOctExtrepV(VALUE val, void **arg){ /* Documentation */ if (val == NULL) return(noctDoc); return(GetIntField(((EXTREP) val)->nOct,arg));}/* * The field list */ struct field fieldsExtrep[] = { "D", GetExtractExtrepV, NULL, GetExtractOptionsExtrepV, GetExtractInfoExtrepV, "name", GetNameExtrepV, SetNameExtrepV, NULL, NULL, "dx", GetDxExtrepV, SetDxExtrepV, NULL, NULL, "x0", GetX0ExtrepV, SetX0ExtrepV, NULL, NULL, "nvoice", GetNVoiceExtrepV, NULL, NULL, NULL, "noct", GetNOctExtrepV, NULL, NULL, NULL, "size", GetSizeExtrepV, SetSizeExtrepV, NULL, NULL, "wavelet", GetWaveletExtrepV, SetWaveletExtrepV, NULL, NULL, "wtrans", GetWtransExtrepV, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};/* * The type structure for EXTREP */ char *extrepType = "&extrep";TypeStruct tsExtrep = { "{{{&extrep} {This type is used to store the local extrema of a 1d wavelet transform.}}}", /* Documentation */ &extrepType, /* The basic (unique) type name */ NULL, /* The GetType function */ DeleteExtrep, /* The Delete function */ NewExtrep, /* The Delete function */ CopyExtrep1, /* The copy function */ ClearExtrep, /* The clear function */ ToStrExtrep, /* String conversion */ PrintExtrep, /* The Print function : print the object when 'print' is called */ PrintInfoExtrep, /* The PrintInfo function : called by 'info' */ NULL, /* The NumExtract function : used to deal with syntax like 10a */ fieldsExtrep, /* The list of fields */};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -