libcm is a C development framework with an emphasis on audio signal processing applications.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

cmDspValue.h 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. #ifndef cmDspValue_h
  2. #define cmDspValue_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. typedef unsigned cmDsvRC_t;
  7. enum
  8. {
  9. kOkDsvRC = cmOkRC,
  10. kNotMtxDsvRC,
  11. kRetTooSmallDsvRC,
  12. kUnknownTypeDsvRC,
  13. kJsonDeserialFailDsvRC,
  14. kConstViolationDsvRC
  15. };
  16. enum
  17. {
  18. kNullDsvFl = 0x00000000,
  19. kBoolDsvFl = 0x00000001,
  20. kCharDsvFl = 0x00000002,
  21. kUCharDsvFl = 0x00000004,
  22. kShortDsvFl = 0x00000008,
  23. kUShortDsvFl = 0x00000010,
  24. kLongDsvFl = 0x00000020,
  25. kULongDsvFl = 0x00000040,
  26. kIntDsvFl = 0x00000080,
  27. kUIntDsvFl = 0x00000100,
  28. kFloatDsvFl = 0x00000200,
  29. kDoubleDsvFl = 0x00000400,
  30. kSampleDsvFl = 0x00000800,
  31. kRealDsvFl = 0x00001000,
  32. kPtrDsvFl = 0x00002000,
  33. kStrzDsvFl = 0x00004000,
  34. kSymDsvFl = 0x00008000,
  35. kJsonDsvFl = 0x00010000,
  36. kMtxDsvFl = 0x00020000,
  37. kTypeDsvMask = 0x0003ffff,
  38. kProxyDsvFl = 0x00040000,
  39. // Auxilliary Flags
  40. kInDsvFl = 0x00100000, // parameter which is input to the instance (represented by an input port)
  41. kOutDsvFl = 0x00200000, // output value (represented by an output port)
  42. kReqArgDsvFl = 0x00400000, // marks DSP variables which are must be given initial values in cmDspInstAllocate() va_list argument.
  43. kOptArgDsvFl = 0x00800000, // marks DSP variables which may optionally be given initial values
  44. kNoArgDsvFl = 0x01000000, // marks DSP variable which may NOT be initialized from in cmDspInstAllocate() va_list argument.
  45. kAudioBufDsvFl = 0x02000000, // marks DSP variables which represent audio input or outputs
  46. kUiDsvFl = 0x04000000, // marks DSP variables whose values should be echoed to the UI
  47. kDynDsvFl = 0x08000000, // Set if the value was dynamically allocated
  48. kConstDsvFl = 0x10000000, // Set if this value is const.
  49. kDfltSetDsvFl = 0x20000000, // Set if the default variable in a DSP instance variable has a valid value.
  50. kSendDfltDsvFl = 0x40000000 // By default default values are not transmitted - setting this flag causes the default values to be sent.
  51. };
  52. typedef struct
  53. {
  54. unsigned rn;
  55. unsigned cn;
  56. union
  57. {
  58. bool* bp;
  59. char* cp;
  60. unsigned char* ucp;
  61. short* sp;
  62. unsigned short* usp;
  63. long* lp;
  64. unsigned long* ulp;
  65. int* ip;
  66. unsigned* up;
  67. float* fp;
  68. double* dp;
  69. cmSample_t* ap;
  70. cmReal_t* rp;
  71. cmJsonNode_t** jp;
  72. cmChar_t** zp;
  73. const cmChar_t** czp;
  74. void* vp;
  75. } u;
  76. } cmDspMtx_t;
  77. typedef struct cmDspValue_str
  78. {
  79. unsigned flags;
  80. union
  81. {
  82. bool b;
  83. char c;
  84. unsigned char uc;
  85. short s;
  86. unsigned short us;
  87. long l;
  88. unsigned long ul;
  89. int i;
  90. unsigned u;
  91. float f;
  92. double d;
  93. cmSample_t a;
  94. cmReal_t r;
  95. cmJsonNode_t* j;
  96. cmChar_t* z;
  97. const cmChar_t* cz;
  98. cmDspMtx_t m;
  99. struct cmDspValue_str* vp;
  100. } u;
  101. } cmDspValue_t;
  102. extern cmDspValue_t cmDspNullValue;
  103. bool cmDsvIsNull( const cmDspValue_t* vp );
  104. bool cmDsvIsBool( const cmDspValue_t* vp );
  105. bool cmDsvIsChar( const cmDspValue_t* vp );
  106. bool cmDsvIsUChar( const cmDspValue_t* vp );
  107. bool cmDsvIsShort( const cmDspValue_t* vp );
  108. bool cmDsvIsUShort( const cmDspValue_t* vp );
  109. bool cmDsvIsLong( const cmDspValue_t* vp );
  110. bool cmDsvIsULong( const cmDspValue_t* vp );
  111. bool cmDsvIsInt( const cmDspValue_t* vp );
  112. bool cmDsvIsUInt( const cmDspValue_t* vp );
  113. bool cmDsvIsFloat( const cmDspValue_t* vp );
  114. bool cmDsvIsDouble( const cmDspValue_t* vp );
  115. bool cmDsvIsSample( const cmDspValue_t* vp );
  116. bool cmDsvIsReal( const cmDspValue_t* vp );
  117. bool cmDsvIsStrz( const cmDspValue_t* vp );
  118. bool cmDsvIsSymbol( const cmDspValue_t* vp );
  119. bool cmDsvIsJson( const cmDspValue_t* vp );
  120. bool cmDsvIsBoolMtx( const cmDspValue_t* vp );
  121. bool cmDsvIsCharMtx( const cmDspValue_t* vp );
  122. bool cmDsvIsUCharMtx( const cmDspValue_t* vp );
  123. bool cmDsvIsShortMtx( const cmDspValue_t* vp );
  124. bool cmDsvIsUShortMtx( const cmDspValue_t* vp );
  125. bool cmDsvIsLongMtx( const cmDspValue_t* vp );
  126. bool cmDsvIsULongMtx( const cmDspValue_t* vp );
  127. bool cmDsvIsIntMtx( const cmDspValue_t* vp );
  128. bool cmDsvIsUIntMtx( const cmDspValue_t* vp );
  129. bool cmDsvIsFloatMtx( const cmDspValue_t* vp );
  130. bool cmDsvIsDoubleMtx( const cmDspValue_t* vp );
  131. bool cmDsvIsSampleMtx( const cmDspValue_t* vp );
  132. bool cmDsvIsRealMtx( const cmDspValue_t* vp );
  133. bool cmDsvIsJsonMtx( const cmDspValue_t* vp );
  134. bool cmDsvIsStrzMtx( const cmDspValue_t* vp );
  135. // Set scalar types from a va_list. Returns false if 'flags' does not
  136. // identify a scalar type. Note that this function cannot convert
  137. // scalar JSON nodes but can accept scalar Strz's.
  138. bool cmDsvSetFromValist( cmDspValue_t* vp, unsigned flags, va_list vl );
  139. // Return true if the source type can be converted to the dest type.
  140. bool cmDsvCanConvertFlags( unsigned destFlags, unsigned srcFlags );
  141. // Return true if svp can be assigned to dvp.
  142. bool cmDsvCanConvert( const cmDspValue_t* dvp, const cmDspValue_t* svp );
  143. // WARNING: All of the setter functions clear all existing flags
  144. // in the target cmDspValue_t object and then set the type flags
  145. // associated with the RHS value. This means that any auxilliary
  146. // flags will be cleared and therefore must be reset by the calling
  147. // function if they are to be preserved past the call to the setter.
  148. // Assign a scalar value to the cmDspValue_t and setup the type information.
  149. void cmDsvSetNull( cmDspValue_t* vp );
  150. void cmDsvSetBool( cmDspValue_t* vp, bool v );
  151. void cmDsvSetChar( cmDspValue_t* vp, char v );
  152. void cmDsvSetUChar( cmDspValue_t* vp, unsigned char v );
  153. void cmDsvSetShort( cmDspValue_t* vp, short v );
  154. void cmDsvSetUShort( cmDspValue_t* vp, unsigned short v );
  155. void cmDsvSetLong( cmDspValue_t* vp, long v );
  156. void cmDsvSetULong( cmDspValue_t* vp, unsigned long v );
  157. void cmDsvSetInt( cmDspValue_t* vp, int v );
  158. void cmDsvSetUInt( cmDspValue_t* vp, unsigned int v );
  159. void cmDsvSetFloat( cmDspValue_t* vp, float v );
  160. void cmDsvSetDouble( cmDspValue_t* vp, double v );
  161. void cmDsvSetSample( cmDspValue_t* vp, cmSample_t v );
  162. void cmDsvSetReal( cmDspValue_t* vp, cmReal_t v );
  163. void cmDsvSetPtr( cmDspValue_t* vp, void* v );
  164. void cmDsvSetSymbol( cmDspValue_t* vp, unsigned int v );
  165. void cmDsvSetStrz( cmDspValue_t* vp, cmChar_t* v );
  166. void cmDsvSetStrcz( cmDspValue_t* vp, const cmChar_t* v );
  167. void cmDsvSetJson( cmDspValue_t* vp, cmJsonNode_t* v);
  168. // Assign a matrix to the cmDspValue_t.
  169. void cmDsvSetBoolMtx( cmDspValue_t* vp, bool* v, unsigned rn, unsigned cn );
  170. void cmDsvSetCharMtx( cmDspValue_t* vp, char* v, unsigned rn, unsigned cn );
  171. void cmDsvSetUCharMtx( cmDspValue_t* vp, unsigned char* v, unsigned rn, unsigned cn );
  172. void cmDsvSetShortMtx( cmDspValue_t* vp, short* v, unsigned rn, unsigned cn );
  173. void cmDsvSetUShortMtx( cmDspValue_t* vp, unsigned short* v, unsigned rn, unsigned cn );
  174. void cmDsvSetLongMtx( cmDspValue_t* vp, long* v, unsigned rn, unsigned cn );
  175. void cmDsvSetULongMtx( cmDspValue_t* vp, unsigned long* v, unsigned rn, unsigned cn );
  176. void cmDsvSetIntMtx( cmDspValue_t* vp, int* v, unsigned rn, unsigned cn );
  177. void cmDsvSetUIntMtx( cmDspValue_t* vp, unsigned int* v, unsigned rn, unsigned cn );
  178. void cmDsvSetFloatMtx( cmDspValue_t* vp, float* v, unsigned rn, unsigned cn );
  179. void cmDsvSetDoubleMtx( cmDspValue_t* vp, double* v, unsigned rn, unsigned cn );
  180. void cmDsvSetSampleMtx( cmDspValue_t* vp, cmSample_t* v, unsigned rn, unsigned cn );
  181. void cmDsvSetRealMtx( cmDspValue_t* vp, cmReal_t* v, unsigned rn, unsigned cn );
  182. void cmDsvSetJsonMtx( cmDspValue_t* vp, cmJsonNode_t** v, unsigned rn, unsigned cn );
  183. void cmDsvSetStrzMtx( cmDspValue_t* vp, cmChar_t** v, unsigned rn, unsigned cn );
  184. void cmDsvSetStrczMtx( cmDspValue_t* vp, const cmChar_t** v, unsigned rn, unsigned cn );
  185. void cmDsvSetMtx( cmDspValue_t* vp, unsigned flags, void* v, unsigned rn, unsigned cn );
  186. void cmDsvSetProxy( cmDspValue_t* vp, cmDspValue_t* pp );
  187. // Get the value of a char cmDspValue_t.
  188. // Returns 0 if the cmDspValue_t does not exactly match the return type.
  189. bool cmDsvBool( const cmDspValue_t* vp );
  190. char cmDsvChar( const cmDspValue_t* vp );
  191. unsigned char cmDsvUChar( const cmDspValue_t* vp );
  192. short cmDsvShort( const cmDspValue_t* vp );
  193. unsigned short cmDsvUShort( const cmDspValue_t* vp );
  194. long cmDsvLong( const cmDspValue_t* vp );
  195. unsigned long cmDsvULong( const cmDspValue_t* vp );
  196. int cmDsvInt( const cmDspValue_t* vp );
  197. unsigned int cmDsvUInt( const cmDspValue_t* vp );
  198. float cmDsvFloat( const cmDspValue_t* vp );
  199. double cmDsvDouble( const cmDspValue_t* vp );
  200. cmSample_t cmDsvSample( const cmDspValue_t* vp );
  201. cmReal_t cmDsvReal( const cmDspValue_t* vp );
  202. void* cmDsvPtr( const cmDspValue_t* vp );
  203. unsigned int cmDsvSymbol( const cmDspValue_t* vp );
  204. cmChar_t* cmDsvStrz( const cmDspValue_t* vp );
  205. const cmChar_t*cmDsvStrcz( const cmDspValue_t* vp );
  206. cmJsonNode_t* cmDsvJson( const cmDspValue_t* vp );
  207. const cmDspValue_t* cmDsvValueCPtr( const cmDspValue_t* vp );
  208. cmDspValue_t* cmDsvValuePtr( cmDspValue_t* vp );
  209. // Return a pointer to the base of a matrix.
  210. // Returns NULL if the cmDspValue_t is does not exactly match the return type.
  211. const bool* cmDsvBoolCMtx( const cmDspValue_t* vp );
  212. const char* cmDsvCharCMtx( const cmDspValue_t* vp );
  213. const unsigned char* cmDsvUCharCMtx( const cmDspValue_t* vp );
  214. const short* cmDsvShortCMtx( const cmDspValue_t* vp );
  215. const unsigned short* cmDsvUShortCMtx( const cmDspValue_t* vp );
  216. const long* cmDsvLongCMtx( const cmDspValue_t* vp );
  217. const unsigned long* cmDsvULongCMtx( const cmDspValue_t* vp );
  218. const int* cmDsvIntCMtx( const cmDspValue_t* vp );
  219. const unsigned int* cmDsvUIntCMtx( const cmDspValue_t* vp );
  220. const float* cmDsvFloatCMtx( const cmDspValue_t* vp );
  221. const double* cmDsvDoubleCMtx( const cmDspValue_t* vp );
  222. const cmSample_t* cmDsvSampleCMtx( const cmDspValue_t* vp );
  223. const cmReal_t* cmDsvRealCMtx( const cmDspValue_t* vp );
  224. const cmChar_t** cmDsvStrzCMtx( const cmDspValue_t* vp );
  225. const cmChar_t** cmDsvStrczCMtx( const cmDspValue_t* vp );
  226. bool* cmDsvBoolMtx( cmDspValue_t* vp );
  227. char* cmDsvCharMtx( cmDspValue_t* vp );
  228. unsigned char* cmDsvUCharMtx( cmDspValue_t* vp );
  229. short* cmDsvShortMtx( cmDspValue_t* vp );
  230. unsigned short* cmDsvUShortMtx( cmDspValue_t* vp );
  231. long* cmDsvLongMtx( cmDspValue_t* vp );
  232. unsigned long* cmDsvULongMtx( cmDspValue_t* vp );
  233. int* cmDsvIntMtx( cmDspValue_t* vp );
  234. unsigned int* cmDsvUIntMtx( cmDspValue_t* vp );
  235. float* cmDsvFloatMtx( cmDspValue_t* vp );
  236. double* cmDsvDoubleMtx( cmDspValue_t* vp );
  237. cmSample_t* cmDsvSampleMtx( cmDspValue_t* vp );
  238. cmReal_t* cmDsvRealMtx( cmDspValue_t* vp );
  239. cmJsonNode_t** cmDsvJsonMtx( cmDspValue_t* vp );
  240. cmChar_t** cmDsvStrzMtx( cmDspValue_t* vp );
  241. const cmChar_t**cmDsvStrczMtx( cmDspValue_t* vp );
  242. // Get the value of a cmDspValue_t.
  243. // Conversion is performed if the return type does not exactly match the cmDspValue_t type.
  244. bool cmDsvGetBool( const cmDspValue_t* vp );
  245. char cmDsvGetChar( const cmDspValue_t* vp );
  246. unsigned char cmDsvGetUChar( const cmDspValue_t* vp );
  247. short cmDsvGetShort( const cmDspValue_t* vp );
  248. unsigned short cmDsvGetUShort( const cmDspValue_t* vp );
  249. long cmDsvGetLong( const cmDspValue_t* vp );
  250. unsigned long cmDsvGetULong( const cmDspValue_t* vp );
  251. int cmDsvGetInt( const cmDspValue_t* vp );
  252. unsigned int cmDsvGetUInt( const cmDspValue_t* vp );
  253. float cmDsvGetFloat( const cmDspValue_t* vp );
  254. double cmDsvGetDouble( const cmDspValue_t* vp );
  255. cmSample_t cmDsvGetSample( const cmDspValue_t* vp );
  256. cmReal_t cmDsvGetReal( const cmDspValue_t* vp );
  257. void* cmDsvGetPtr( const cmDspValue_t* vp );
  258. unsigned cmDsvGetSymbol( const cmDspValue_t* vp );
  259. cmChar_t* cmDsvGetStrz( const cmDspValue_t* vp );
  260. const cmChar_t*cmDsvGetStrcz( const cmDspValue_t* vp );
  261. cmJsonNode_t* cmDsvGetJson( const cmDspValue_t* vp );
  262. cmDsvRC_t cmDsvGetBoolMtx( cmDspValue_t* vp, bool* v, unsigned vn );
  263. cmDsvRC_t cmDsvGetCharMtx( cmDspValue_t* vp, char* v, unsigned vn );
  264. cmDsvRC_t cmDsvGetUCharMtx( cmDspValue_t* vp, unsigned char* v, unsigned vn );
  265. cmDsvRC_t cmDsvGetShortMtx( cmDspValue_t* vp, short* v, unsigned vn );
  266. cmDsvRC_t cmDsvGetUShortMtx( cmDspValue_t* vp, unsigned short* v, unsigned vn );
  267. cmDsvRC_t cmDsvGetLongMtx( cmDspValue_t* vp, long* v, unsigned vn );
  268. cmDsvRC_t cmDsvGetULongMtx( cmDspValue_t* vp, unsigned long* v, unsigned vn );
  269. cmDsvRC_t cmDsvGetIntMtx( cmDspValue_t* vp, int* v, unsigned vn );
  270. cmDsvRC_t cmDsvGetUIntMtx( cmDspValue_t* vp, unsigned int* v, unsigned vn );
  271. cmDsvRC_t cmDsvGetFloatMtx( cmDspValue_t* vp, float* v, unsigned vn );
  272. cmDsvRC_t cmDsvGetDoubleMtx( cmDspValue_t* vp, double* v, unsigned vn );
  273. cmDsvRC_t cmDsvGetSampleMtx( cmDspValue_t* vp, cmSample_t* v, unsigned vn );
  274. cmDsvRC_t cmDsvGetRealMtx( cmDspValue_t* vp, cmReal_t* v, unsigned vn );
  275. cmDsvRC_t cmDsvGetStrzMtx( cmDspValue_t* vp, cmChar_t* v, unsigned vn );
  276. bool cmDsvIsType( const cmDspValue_t* vp, unsigned flags );
  277. bool cmDsvIsMtx( const cmDspValue_t* vp );
  278. unsigned cmDsvEleCount( const cmDspValue_t* vp );
  279. unsigned cmDsvRows( const cmDspValue_t* vp );
  280. unsigned cmDsvCols( const cmDspValue_t* vp );
  281. // Basic type flag with kMtxDsvFl and any other flags cleared.
  282. unsigned cmDsvBasicType( const cmDspValue_t* vp );
  283. // Size of each data element in bytes.
  284. unsigned cmDsvEleByteCount( const cmDspValue_t* vp );
  285. // Count of data bytes given a matrix size. Note that 'rn' and 'cn' are
  286. // not used if the kMtxDsvFl is not set in flags.
  287. unsigned cmDsvByteCount( unsigned flags, unsigned rn, unsigned cn );
  288. // Return the number of bytes required to serialize the value.
  289. unsigned cmDsvSerialByteCount( const cmDspValue_t* vp );
  290. // Returns the number of bytes required to serialize the data alone not including
  291. // the cmDspValue_t record. This is just cmDsvSerialByteCount(vp) - sizeof(cmDspValue_t)
  292. unsigned cmDsvSerialDataByteCount( const cmDspValue_t* vp );
  293. cmDsvRC_t cmDsvSerialize( const cmDspValue_t* vp, void* buf, unsigned bufByteCnt );
  294. cmDsvRC_t cmDsvDeserializeInPlace( cmDspValue_t* vp, unsigned dataBufByteCnt );
  295. cmDsvRC_t cmDsvDeserializeJson( cmDspValue_t* vp, cmJsonH_t jsH );
  296. void cmDsvPrint( const cmDspValue_t* vp, const cmChar_t* label, cmRpt_t* rpt );
  297. #define cmDsvCopy( d, s ) (*(d)) = (*(s))
  298. #ifdef __cplusplus
  299. }
  300. #endif
  301. #endif