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 16KB

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