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.

cmDspTl.c 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #include "cmPrefix.h"
  2. #include "cmGlobal.h"
  3. #include "cmFloatTypes.h"
  4. #include "cmComplexTypes.h"
  5. #include "cmRpt.h"
  6. #include "cmErr.h"
  7. #include "cmCtx.h"
  8. #include "cmMem.h"
  9. #include "cmMallocDebug.h"
  10. #include "cmLinkedHeap.h"
  11. #include "cmMath.h"
  12. #include "cmFile.h"
  13. #include "cmFileSys.h"
  14. #include "cmSymTbl.h"
  15. #include "cmJson.h"
  16. #include "cmPrefs.h"
  17. #include "cmProcObj.h"
  18. #include "cmDspValue.h"
  19. #include "cmDspClass.h"
  20. #include "cmDspFx.h"
  21. #include "cmMsgProtocol.h"
  22. #include "cmThread.h"
  23. #include "cmUdpPort.h"
  24. #include "cmUdpNet.h"
  25. #include "cmAudioSys.h"
  26. #include "cmDspSys.h"
  27. //==========================================================================================================================================
  28. enum
  29. {
  30. kFnTlId,
  31. kAudOutTlId,
  32. kMidOutTlId,
  33. kEvtOutTlId
  34. };
  35. cmDspClass_t _cmTimeLineDC;
  36. typedef struct
  37. {
  38. cmDspInst_t inst;
  39. cmTlH_t tlH;
  40. } cmDspTimeLine_t;
  41. cmDspInst_t* _cmDspTimeLineAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
  42. {
  43. unsigned chs = 1;
  44. cmDspVarArg_t args[] =
  45. {
  46. { "fn", kFnTlId, 0, 0, kInDsvFl | kStrzDsvFl, "Time line file" },
  47. { "a-out", kAudOutTlId, 0, chs, kOutDsvFl | kAudioBufDsvFl, "Audio output." },
  48. { "m-out", kMidOutTlId, 0, 0, kOutDsvFl | k
  49. { NULL, 0, 0, 0, 0 }
  50. };
  51. // allocate the instance
  52. cmDspTimeLine_t* p = cmDspInstAlloc(cmDspTimeLine_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
  53. // assign default values to any of the the optional arg's which may not have been set from vl.
  54. cmDspSetDefaultDouble(ctx, &p->inst, kMaxTlId, 0.0, DBL_MAX);
  55. cmDspSetDefaultDouble(ctx, &p->inst, kMultTlId, 0.0, 1.0);
  56. cmDspSetDefaultDouble(ctx, &p->inst, kPhsTlId, 0.0, 0.0);
  57. return &p->inst;
  58. }
  59. cmDspRC_t _cmDspTimeLineReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
  60. {
  61. cmDspApplyAllDefaults(ctx,inst);
  62. cmDspZeroAudioBuf( ctx, inst, kOutTlId );
  63. return kOkDspRC;
  64. }
  65. cmDspRC_t _cmDspTimeLineExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
  66. {
  67. cmSample_t* bp = cmDspAudioBuf(ctx,inst,kOutTlId,0);
  68. const cmSample_t* ep = bp + cmDspAudioBufSmpCount(ctx,inst,kOutTlId,0);
  69. double mult = cmDspDouble(inst,kMultTlId);
  70. double max = cmDspDouble(inst,kMaxTlId);
  71. double phs = cmDspDouble(inst,kPhsTlId);
  72. double inc = mult;
  73. for(; bp<ep; ++bp)
  74. {
  75. while( phs >= max )
  76. phs -= max;
  77. *bp = phs;
  78. phs += inc;
  79. }
  80. cmDspSetDouble(ctx,inst,kPhsTlId,phs);
  81. return kOkDspRC;
  82. }
  83. cmDspRC_t _cmDspTimeLineRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
  84. {
  85. switch( evt->dstVarId )
  86. {
  87. case kMultTlId:
  88. case kMaxTlId:
  89. case kPhsTlId:
  90. cmDspSetEvent(ctx, inst, evt );;
  91. break;
  92. default:
  93. { assert(0); }
  94. }
  95. return kOkDspRC;
  96. }
  97. struct cmDspClass_str* cmTimeLineClassCons( cmDspCtx_t* ctx )
  98. {
  99. cmDspClassSetup(&_cmTimeLineDC,ctx,"TimeLine",
  100. NULL,
  101. _cmDspTimeLineAlloc,
  102. NULL,
  103. _cmDspTimeLineReset,
  104. _cmDspTimeLineExec,
  105. _cmDspTimeLineRecv,
  106. NULL,
  107. NULL,
  108. "Ramp wave signal generator.");
  109. return &_cmTimeLineDC;
  110. }
  111. typedef struct
  112. typedef struct cmPerfEvt_str
  113. {
  114. unsigned pitch;
  115. unsigned dyn;
  116. unsigned ioiTicks;
  117. } cmPerfEvt_t;