📄 wtrans_alloc.c
字号:
/* Documentation */ if (val == NULL) return(typeDoc); return(GetIntField(((WTRANS) val)->type,arg));}static void * SetTypeWtransV(VALUE val, void **arg){ int i; /* Documentation */ if (val == NULL) return(typeDoc); i = ((WTRANS) val)->type; if (SetIntField(&i,arg,FieldPositive)==NULL) return(NULL); if (i != W_ORTH && i != W_CONT) { SetErrorf("Bad value %d or type field",i); return(NULL); } ((WTRANS) val)->type = i; return(numType);}/* * 'amin' field */static char *aminDoc = "{[= <amin>]} {Sets/Gets the smallest scale of a wavelet transform.}";static void * GetAminWtransV(VALUE val, void **arg){ /* Documentation */ if (val == NULL) return(aminDoc); return(GetFloatField(((WTRANS) val)->aMin,arg));}static void * SetAminWtransV(VALUE val, void **arg){ /* Documentation */ if (val == NULL) return(aminDoc); return(SetFloatField(&(((WTRANS) val)->aMin),arg,FieldSPositive));}/* * 'extrep' field */static char *extrepDoc = "{} {Gets the extrema representation associated to the wavelet transform.}";static void * GetExtrepWtransV(VALUE val, void **arg){ /* Documentation */ if (val == NULL) return(extrepDoc); if (((WTRANS) val)->extrep == NULL) return(GetValueField(nullValue,arg)); return(GetValueField(((WTRANS) val)->extrep,arg));}/*********************************************************************************** * * Allocation and Desallocation * ***********************************************************************************//* * Allocation of a wtrans */WTRANS NewWtrans(void){ extern TypeStruct tsWtrans; WTRANS wtrans; int i,j;#ifdef DEBUGALLOCDebugType = "Wtrans1d";#endif wtrans = (WTRANS) Malloc(sizeof(struct wtrans)); InitValue(wtrans,&tsWtrans); for (i=0;i<NOCT;i++) for (j=0;j<NVOICE;j++) { wtrans->D[i][j] = NewSignal(); wtrans->A[i][j] = NewSignal(); }; wtrans->fg = NULL; wtrans->border = B_PERIODIC; wtrans->name = defaultName; wtrans->wName = NULL; wtrans->nOct = 0; wtrans->nVoice = 0; wtrans->type = 0; wtrans->extrep = NewExtrep(); wtrans->extrep->wtrans = wtrans; return(wtrans);}/* * Desallocation of a wtrans */void DeleteWtrans(WTRANS wtrans){ int i,j; RemoveRefValue( wtrans); if (wtrans->nRef > 0) return; for (i=0;i<NOCT;i++) { for (j=0;j<NVOICE;j++) { DeleteSignal(wtrans->D[i][j]); DeleteSignal(wtrans->A[i][j]); } } DeleteFilterGroup(wtrans->fg); if (wtrans->extrep) { wtrans->extrep->wtrans = NULL; DeleteExtrep(wtrans->extrep); } if (wtrans->wName != NULL) Free(wtrans->wName); if (wtrans->name != NULL && wtrans->name != defaultName) Free(wtrans->name);#ifdef DEBUGALLOCDebugType = "Wtrans1d";#endif Free(wtrans); }/* * Make some desallocation of the wtrans */ void ClearWtrans(WTRANS wtrans){ int i,j; if (wtrans->wName != NULL) Free(wtrans->wName); wtrans->wName = NULL; for (i=0;i<NOCT;i++) for (j=0;j<NVOICE;j++) { ClearSignal(wtrans->D[i][j]); ClearSignal(wtrans->A[i][j]); }} /*********************************************************************************** * * Misc functions on wtransforms * ***********************************************************************************//* * Copy the fields of a WTRANS into another */void CopyFieldsWtrans(WTRANS in , WTRANS out){ /* Tests*/ if (in == NULL) return; if (out == NULL) Errorf("CopyFieldsWtrans() : output wtrans is NULL"); /* Copy the filter group */ SetFGWtrans(out,in->fg); /* Copy the other fields */ out->type = in->type; out->border = in->border; out->nOct = in->nOct; out->nVoice = in->nVoice; out->dx = in->dx; out->x0 = in->x0; out->aMin = in->aMin; out->exponent = in->exponent; out->size = in->size; if (out->wName != NULL) { Free(out->wName); out->wName = NULL; } if (in->wName != NULL) out->wName = CopyStr(in->wName);}/* * Copy a WTRANS into another */WTRANS CopyWtrans(WTRANS in,WTRANS out){ int i,j; /* Tests*/ if (in == NULL) return(NULL); if (out == NULL) out = NewWtrans(); if (in == out) return(out); CopyFieldsWtrans(in,out); /* Copy all the signals */ for (i=0;i<NOCT;i++) for (j=0;j<NVOICE;j++) { if (in->D[i][j] != NULL) { if (out->D[i][j] == NULL) out->D[i][j] = NewSignal(); CopySig(in->D[i][j],out->D[i][j]); } else { DeleteSignal(out->D[i][j]); out->D[i][j] = NULL; } if (in->A[i][j] != NULL) { if (out->A[i][j] == NULL) out->A[i][j] = NewSignal(); CopySig(in->A[i][j],out->A[i][j]); } else { DeleteSignal(out->A[i][j]); out->A[i][j] = NULL; } }; return(out);}/* * Get the current wtransform * (generate an error if there is none) */ WTRANS GetWtransCur(void){ WTRANS wtrans; if (!ParseTypedValLevel_(levelCur, "objCur", NULL, (VALUE *) &wtrans, wtransType)) Errorf1(""); AddRefValue( wtrans); TempValue( wtrans); return(wtrans);}/* * Check that there is a decomposition in the wtrans */void CheckWtrans(WTRANS wtrans){ if (wtrans->nOct == 0) Errorf("You must run a wavelet decomposition first");}/* * JUST FOR COMPATIBILITY * Not to be used anymore. */ void C_SetWtrans(char **argv){ WTRANS wtrans; int ival,o,v; LWFLOAT fval; char *field,*name1; argv = ParseArgv(argv,tSTR,&field,tWTRANS,&wtrans,-1); if (!strcmp(field,"noct")) { if (*argv == NULL) SetResultInt(wtrans->nOct); else { argv = ParseArgv(argv,tINT,&ival,0); if (ival < 0 || ival > NOCT-1) Errorf("Bad 'noct' value '%d'",ival); wtrans->nOct = ival; } } else if (!strcmp(field,"nvoice")) { if (*argv == NULL) SetResultInt(wtrans->nVoice); else { argv = ParseArgv(argv,tINT,&ival,0); if (ival < 0 || ival > NVOICE-1) Errorf("Bad 'nvoice' value '%d'",ival); wtrans->nVoice = ival; } } else if (!strcmp(field,"name")) { NoMoreArgs(argv); SetResultStr(wtrans->name); } else if (!strcmp(field,"type")) { if (*argv == NULL) SetResultInt(wtrans->type); else { argv = ParseArgv(argv,tINT,&ival,0); if (ival < 0) Errorf("Bad 'type' value '%d'",ival); wtrans->type = ival; } } else if (!strcmp(field,"size")) { if (*argv == NULL) SetResultInt(wtrans->size); else { argv = ParseArgv(argv,tINT,&ival,0); if (ival < 0) Errorf("Bad 'size' value '%d'",ival); wtrans->size = ival; } } else if (!strcmp(field,"amin")) { if (*argv == NULL) SetResultFloat(wtrans->aMin); else { argv = ParseArgv(argv,tFLOAT,&fval,0); if (fval <= 0) Errorf("Bad 'amin' value '%d'",fval); wtrans->aMin = fval; } } else if (!strcmp(field,"x0")) { if (*argv == NULL) SetResultFloat(wtrans->x0); else { argv = ParseArgv(argv,tFLOAT,&fval,0); wtrans->x0 = fval; } } else if (!strcmp(field,"dx")) { if (*argv == NULL) SetResultFloat(wtrans->dx); else { argv = ParseArgv(argv,tFLOAT,&fval,0); if (fval <= 0) Errorf("Bad 'dx' value '%d'",fval); wtrans->dx = fval; } } else if (!strcmp(field,"wname")) { if (*argv == NULL) SetResultStr(wtrans->wName); else { argv = ParseArgv(argv,tSTR,&name1,0); if (wtrans->wName != NULL) Free(wtrans->wName); wtrans->wName = CopyStr(name1); } } else if (!strcmp(field,"*extrep")) { ParseArgv(argv,tVNAME_,NULL,&name1,0); if (name1 == NULL) SetResultInt((int) (wtrans->extrep != NULL)); else if (wtrans->extrep == NULL) { DeleteVariableIfExist(name1); SetResultInt(0); } else { SetVariable(name1,(VALUE) (wtrans->extrep)); SetResultInt(1); } } else if (!strcmp(field,"*signalD")) { ParseArgv(argv,tVNAME,&name1,tINT,&o,tINT,&v,0); if (o >=NOCT || o <0 ) Errorf("Bad octave number '%d'",o); if (v >=NVOICE || v <0 ) Errorf("Bad voice number '%d'",v); SetVariable(name1,(VALUE) (wtrans->D[o][v])); } else if (!strcmp(field,"*signalA")) { ParseArgv(argv,tVNAME,&name1,tINT,&o,tINT,&v,0); if (o >=NOCT || o <0 ) Errorf("Bad octave number '%d'",o); if (v >=NVOICE || v <0 ) Errorf("Bad voice number '%d'",v); SetVariable(name1,(VALUE) (wtrans->A[o][v])); } else Errorf("Unknow wtrans field '%s'",field); }/* * The field list */struct field fieldsWtrans[] = { "A", GetExtractWtransV, SetExtractWtransV, GetExtractOptionsWtransV, GetExtractInfoWtransV, "D", GetExtractWtransV, SetExtractWtransV, GetExtractOptionsWtransV, GetExtractInfoWtransV, "name", GetNameWtransV, SetNameWtransV, NULL, NULL, "dx", GetDxWtransV, SetDxWtransV, NULL, NULL, "x0", GetX0WtransV, SetX0WtransV, NULL, NULL, "nvoice", GetNVoiceWtransV, SetNVoiceWtransV, NULL, NULL, "noct", GetNOctWtransV, SetNOctWtransV, NULL, NULL, "size", GetSizeWtransV, SetSizeWtransV, NULL, NULL, "type", GetTypeWtransV, SetTypeWtransV, NULL, NULL, "amin", GetAminWtransV, SetAminWtransV, NULL, NULL, "wavelet", GetWaveletWtransV, SetWaveletWtransV, NULL, NULL, "extrep", GetExtrepWtransV, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};/* * The type structure for WTRANS */TypeStruct tsWtrans = { "{{{&wtrans} {This type is the basic type for 1d wavelet transforms (both continuous, dyadic or orthogonal). \It is organized as two 2d arrays of signals referred to as A (the approximation signals) and D (the detail signals). \Both of them are indexed first by the octave number and then by the voice number. The signal to be analyzed is in A[0,0].}}}", /* Documentation */ &wtransType, /* The basic (unique) type name */ NULL, /* The GetType function */ DeleteWtrans, /* The Delete function */ NewWtrans, /* The Delete function */ CopyWtrans, /* The copy function */ ClearWtrans, /* The clear function */ ToStrWtrans, /* String conversion */ PrintWtrans, /* The Print function : print the object when 'print' is called */ PrintInfoWtrans, /* The PrintInfo function : called by 'info' */ NumExtractWtrans, /* The NumExtract function : used to deal with syntax like 10a */ fieldsWtrans, /* The list of fields */};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -