libcm is a C development framework with an emphasis on audio signal processing applications.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

cmProcObj.h 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #ifndef cmProcObj_h
  2. #define cmProcObj_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /*( { file_desc:"Base class for all 'proc' objects." kw:[proclib] }
  7. The first field in all objects must be an cmObj record.
  8. p* cmProcAlloc(c, p*, initParam0, initParam1, .... )
  9. 1) All processors must be generated by a call to cmProcAlloc().
  10. 2) If p is non-NULL then it is a pointer to a statically allocated proc which is processed by the call and returned as the result.
  11. 3) The primary job of this function is to zero the body of the object and setup the proc's cmObj field.
  12. 4) All arguments other than the cmContext and static pointer are init. params. and should be optional.
  13. 5) If the first init param is non-NULL then cmProcInit() is called internally. Therefore if the first init param
  14. is valid so must all the others.
  15. 6) All embedded objects must be alloc'd in this function by an explicity call to their cmXXXAlloc() function.
  16. 7) The first call in cmProcAlloc() is to cmObjAlloc().
  17. 8) There is no way to know the state of the static object passed to cmProcAlloc() and so the object is
  18. always assumed to be uninitialized.
  19. cmProcFree( c, p** )
  20. 1) All processors must be eventually freed with a call to cmProcFree().
  21. 2) This function begins by calling cmProcFinal().
  22. 3) All embedded objects must be free'd in this function by an explicit call to their cmXXXFree() function.
  23. 4) All dynamically allocated memory must be freed in this function().
  24. 5) The cmObj field indicates if the memory held by the object body needs to be freed or not (if it was statically alloc'd).
  25. 6) The last call in cmProcFree() is to cmObjFree().
  26. cmProcInit( c, p*, ... )
  27. 1) Setup a previously alloc'd or init'd processor.
  28. 2) This function always begins by calling cmProcFinal().
  29. 3) Any dynamically allocated memory should be allocated with a call to cmMemResize().
  30. 4) Any embedded objects must be init'd by an explic call to their cmXXXInit().
  31. cmProcFinal(c, p* );
  32. 1) This function is intended as a place to restore an object to its pre-init state.
  33. 2) This function is called automatically at the beginning of cmProcInit() and cmProcFree().
  34. 3) Dynamically allocated memory does NOT need to freed in final if the cmMemResize() function is used in init.
  35. 4) Embedded objects do NOT need to be finalized here since they will be finalized by calls to there own init functions in cmProcInit().
  36. 5) In general there should be very little to do in this function.
  37. */
  38. // constants
  39. enum
  40. {
  41. // semitones per octave (length of the chroma feature vector)
  42. kStPerOctave = 12,
  43. // count of bands in the equal loudness contour table
  44. // used for sone calc. (length of the sones feature vector)
  45. kEqualLoudBandCnt = 15,
  46. kTonalSpaceDimCnt = 6
  47. };
  48. //------------------------------------------------------------------------------------------------------------
  49. struct cmCtx_str;
  50. enum
  51. {
  52. kDynObjFl = 0x01
  53. };
  54. typedef struct
  55. {
  56. unsigned flags;
  57. cmErr_t err;
  58. struct cmCtx_str* ctx;
  59. } cmObj;
  60. void* _cmObjAlloc( void* p, const char* label, struct cmCtx_str* c, unsigned objByteCnt );
  61. void _cmObjFree( void** pp, cmObj* op );
  62. // Allocate, zero, and setup the embedded cmObj field for an empty object.
  63. #define cmObjAlloc( type, ctx, p ) (type*)(_cmObjAlloc(p,#type,ctx,sizeof(type)))
  64. // if pp is non-NULL then *pp is NULL on return
  65. //#define cmObjFree( pp ) _cmObjFree((void**)pp, pp==NULL ? NULL : (cmObj*)(*pp) )
  66. #define cmObjFree( pp ) _cmObjFree( (void**)(pp), (cmObj*)(*(pp)) )
  67. #define cmArgAssertRC (0x80000001)
  68. #define cmSystemErrorRC (0x80000002) // use strerror() to get the system error
  69. #define cmEofRC (0x80000003)
  70. #define cmSingularMtxRC (0x80000004)
  71. #define cmSubSysFailRC (0x80000005)
  72. #define cmInvalidArgRC (0x80000006)
  73. //------------------------------------------------------------------------------------------------------------
  74. // Macro to allow embedded objects to be freed without having to explicitely
  75. // define a pointer.
  76. #define cmObjFreeStatic( func, type, ref ) do{ type* __p=&(ref); func(&__p); }while(0)
  77. //------------------------------------------------------------------------------------------------------------
  78. typedef struct cmCtx_str
  79. {
  80. cmObj obj;
  81. cmLHeapH_t lhH;
  82. cmSymTblH_t stH;
  83. } cmCtx;
  84. struct cmFeatFile;
  85. // set p to NULL to dynamically allocate the object
  86. cmCtx* cmCtxAlloc( cmCtx* p, cmRpt_t* rpt, cmLHeapH_t lhH, cmSymTblH_t stH );
  87. cmRC_t cmCtxFree( cmCtx** pp );
  88. cmRC_t cmCtxInit( cmCtx* c, cmRpt_t* rpt, cmLHeapH_t lhH, cmSymTblH_t stH );
  89. cmRC_t cmCtxFinal( cmCtx* c );
  90. cmRC_t cmCtxPrint( cmCtx* c, const char* fmt, ... );
  91. // a runtime resource aquisition failed (e.g. file open failed, read failed, ... )
  92. cmRC_t cmCtxRtCondition( cmObj* p, unsigned code, const char* fmt, ... );
  93. // a
  94. cmRC_t cmCtxRtAssertFailed( cmObj* p, unsigned code, const char* fmt, ... );
  95. //------------------------------------------------------------------------------------------------------------
  96. typedef struct cmMtxFile
  97. {
  98. cmObj obj;
  99. cmChar_t* fn;
  100. FILE* fp;
  101. } cmMtxFile;
  102. // Create a text file and write a row of values on each call to cmMtxFileXXXExec().
  103. cmMtxFile* cmMtxFileAlloc(cmCtx* c, cmMtxFile* p, const char* fn );
  104. cmRC_t cmMtxFileFree( cmMtxFile** p );
  105. cmRC_t cmMtxFileCreate( cmMtxFile* p, const char* fn );
  106. cmRC_t cmMtxFileClose( cmMtxFile* p );
  107. cmRC_t cmMtxFileFloatExec( cmMtxFile* p, const float* inPtr, unsigned inCnt, unsigned inStride );
  108. cmRC_t cmMtxFileDoubleExec( cmMtxFile* p, const double* inPtr, unsigned inCnt, unsigned inStride );
  109. cmRC_t cmMtxFileComplexExec( cmMtxFile* p, const cmComplexR_t* inPtr, unsigned inCnt, unsigned inStride );
  110. #if CM_FLOAT_SMP==1
  111. #define cmMtxFileSmpExec(f,p,n) cmMtxFileFloatExec((f),(p),(n),1)
  112. #define cmMtxFileSmpExecN(f,p,n,s) cmMtxFileFloatExec((f),(p),(n),(s))
  113. #else
  114. #define cmMtxFileSmpExec(f,p,n) cmMtxFileDoubleExec((f),(p),(n),1)
  115. #define cmMtxFileSmpExecN(f,p,n,s) cmMtxFileDoubleExec((f),(p),(n),(s))
  116. #endif
  117. #if CM_FLOAT_REAL==1
  118. #define cmMtxFileRealExec(f,p,n) cmMtxFileFloatExec((f),(p),(n),1)
  119. #define cmMtxFileRealExecN(f,p,n,s) cmMtxFileFloatExec((f),(p),(n),(s))
  120. #else
  121. #define cmMtxFileRealExec(f,p,n) cmMtxFileDoubleExec((f),(p),(n),1)
  122. #define cmMtxFileRealExecN(f,p,n,s) cmMtxFileDoubleExec((f),(p),(n),(s))
  123. #endif
  124. //)
  125. #ifdef __cplusplus
  126. }
  127. #endif
  128. #endif