libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmDspValue.h 15KB

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