libcm is a C development framework with an emphasis on audio signal processing applications.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

cmProcObj.h 6.8KB

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