2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SC_PlugIn.h"
24 #include <algorithm> /* for std::min and std::max */
26 #include "simd_peakmeter.hpp"
29 #include "simd_memory.hpp"
31 #if defined(__GNUC__) && !defined(__clang__)
32 #define inline_functions __attribute__ ((flatten))
34 #define inline_functions
39 static InterfaceTable
*ft
;
41 //////////////////////////////////////////////////////////////////////////////////////////////////
43 struct Trig1
: public Unit
49 struct Trig
: public Unit
56 struct SendTrig
: public Unit
61 struct SendReply
: public Unit
72 struct Poll
: public Unit
74 int m_samplesRemain
, m_intervalSamples
;
76 float m_lastPoll
, m_id
;
82 struct ToggleFF
: public Unit
88 struct SetResetFF
: public Unit
91 float m_prevtrig
, m_prevreset
;
94 struct Latch
: public Unit
100 struct Gate
: public Unit
105 struct Schmidt
: public Unit
110 struct PulseDivider
: public Unit
117 struct PulseCount
: public Unit
120 float m_prevtrig
, m_prevreset
;
123 struct Stepper
: public Unit
126 float m_prevtrig
, m_prevreset
;
129 struct TDelay
: public Unit
135 struct ZeroCrossing
: public Unit
137 float mLevel
, m_prevfrac
, m_previn
;
141 struct Timer
: public Unit
143 float mLevel
, m_prevfrac
, m_previn
;
147 struct Sweep
: public Unit
153 struct Phasor
: public Unit
159 struct Peak
: public Unit
165 struct RunningMin
: public Unit
171 struct RunningMax
: public Unit
177 struct PeakFollower
: public Unit
183 struct MostChange
: public Unit
185 float mPrevA
, mPrevB
;
189 struct LeastChange
: public Unit
191 float mPrevA
, mPrevB
;
195 struct LastValue
: public Unit
203 struct Done
: public Unit
208 struct FreeSelf
: public Unit
213 struct PauseSelf
: public Unit
218 struct Pause
: public Unit
223 struct Free
: public Unit
228 struct FreeSelfWhenDone
: public Unit
233 struct PauseSelfWhenDone
: public Unit
240 void Trig1_Ctor(Trig1
*unit
);
241 void Trig1_next(Trig1
*unit
, int inNumSamples
);
242 void Trig1_next_k(Trig1
*unit
, int inNumSamples
);
244 void Trig_Ctor(Trig
*unit
);
245 void Trig_next(Trig
*unit
, int inNumSamples
);
246 void Trig_next_k(Trig
*unit
, int inNumSamples
);
248 void SendTrig_Ctor(SendTrig
*unit
);
249 void SendTrig_next(SendTrig
*unit
, int inNumSamples
);
250 void SendTrig_next_aka(SendTrig
*unit
, int inNumSamples
);
252 void SendReply_Ctor(SendReply
*unit
);
253 void SendReply_next(SendReply
*unit
, int inNumSamples
);
254 void SendReply_next_aka(SendReply
*unit
, int inNumSamples
);
256 void Poll_Ctor(Poll
* unit
);
257 void Poll_next_aa(Poll
*unit
, int inNumSamples
);
258 void Poll_next_ak(Poll
*unit
, int inNumSamples
);
259 void Poll_next_kk(Poll
*unit
, int inNumSamples
);
261 void SetResetFF_Ctor(SetResetFF
*unit
);
262 void SetResetFF_next_a(SetResetFF
*unit
, int inNumSamples
);
263 void SetResetFF_next_k(SetResetFF
*unit
, int inNumSamples
);
265 void ToggleFF_Ctor(ToggleFF
*unit
);
266 void ToggleFF_next(ToggleFF
*unit
, int inNumSamples
);
268 void Latch_Ctor(Latch
*unit
);
269 void Latch_next_ak(Latch
*unit
, int inNumSamples
);
270 void Latch_next_aa(Latch
*unit
, int inNumSamples
);
272 void Gate_Ctor(Gate
*unit
);
273 void Gate_next_ak(Gate
*unit
, int inNumSamples
);
274 void Gate_next_aa(Gate
*unit
, int inNumSamples
);
276 void Schmidt_Ctor(Schmidt
*unit
);
277 void Schmidt_next(Schmidt
*unit
, int inNumSamples
);
279 void PulseDivider_Ctor(PulseDivider
*unit
);
280 void PulseDivider_next(PulseDivider
*unit
, int inNumSamples
);
282 void PulseCount_Ctor(PulseCount
*unit
);
283 void PulseCount_next_a(PulseCount
*unit
, int inNumSamples
);
284 void PulseCount_next_k(PulseCount
*unit
, int inNumSamples
);
285 void PulseCount_next_0(PulseCount
*unit
, int inNumSamples
);
287 void Stepper_Ctor(Stepper
*unit
);
288 void Stepper_next_aa(Stepper
*unit
, int inNumSamples
);
289 void Stepper_next_ak(Stepper
*unit
, int inNumSamples
);
290 void Stepper_next_a0(Stepper
*unit
, int inNumSamples
);
292 void TDelay_Ctor(TDelay
*unit
);
293 void TDelay_next(TDelay
*unit
, int inNumSamples
);
295 void ZeroCrossing_Ctor(ZeroCrossing
*unit
);
296 void ZeroCrossing_next_a(ZeroCrossing
*unit
, int inNumSamples
);
298 void Timer_Ctor(Timer
*unit
);
299 void Timer_next_a(Timer
*unit
, int inNumSamples
);
301 void Sweep_Ctor(Sweep
*unit
);
302 void Sweep_next_0k(Sweep
*unit
, int inNumSamples
);
303 void Sweep_next_0a(Sweep
*unit
, int inNumSamples
);
304 void Sweep_next_kk(Sweep
*unit
, int inNumSamples
);
305 void Sweep_next_ka(Sweep
*unit
, int inNumSamples
);
306 void Sweep_next_ak(Sweep
*unit
, int inNumSamples
);
307 void Sweep_next_aa(Sweep
*unit
, int inNumSamples
);
309 void Phasor_Ctor(Phasor
*unit
);
310 void Phasor_next_kk(Phasor
*unit
, int inNumSamples
);
311 void Phasor_next_ak(Phasor
*unit
, int inNumSamples
);
312 void Phasor_next_aa(Phasor
*unit
, int inNumSamples
);
314 void Peak_Ctor(Peak
*unit
);
315 void Peak_next_ak(Peak
*unit
, int inNumSamples
);
316 void Peak_next_ai(Peak
*unit
, int inNumSamples
);
317 void Peak_next_aa(Peak
*unit
, int inNumSamples
);
318 void Peak_next_ak_k(Peak
*unit
, int inNumSamples
);
319 void Peak_next_ai_k(Peak
*unit
, int inNumSamples
);
320 void Peak_next_aa_k(Peak
*unit
, int inNumSamples
);
322 void RunningMin_Ctor(RunningMin
*unit
);
323 void RunningMin_next_ak(RunningMin
*unit
, int inNumSamples
);
324 void RunningMin_next_ai(RunningMin
*unit
, int inNumSamples
);
325 void RunningMin_next_aa(RunningMin
*unit
, int inNumSamples
);
327 void RunningMax_Ctor(RunningMax
*unit
);
328 void RunningMax_next_ak(RunningMax
*unit
, int inNumSamples
);
329 void RunningMax_next_ai(RunningMax
*unit
, int inNumSamples
);
330 void RunningMax_next_aa(RunningMax
*unit
, int inNumSamples
);
333 void PeakFollower_Ctor(PeakFollower
*unit
);
334 void PeakFollower_next(PeakFollower
*unit
, int inNumSamples
);
335 void PeakFollower_next_ai(PeakFollower
*unit
, int inNumSamples
);
337 void MostChange_Ctor(MostChange
*unit
);
338 void MostChange_next_ak(MostChange
*unit
, int inNumSamples
);
339 void MostChange_next_ka(MostChange
*unit
, int inNumSamples
);
340 void MostChange_next_aa(MostChange
*unit
, int inNumSamples
);
342 void LeastChange_Ctor(LeastChange
*unit
);
343 void LeastChange_next_ak(LeastChange
*unit
, int inNumSamples
);
344 void LeastChange_next_ka(LeastChange
*unit
, int inNumSamples
);
345 void LeastChange_next_aa(LeastChange
*unit
, int inNumSamples
);
347 void LastValue_Ctor(LastValue
*unit
);
348 void LastValue_next_ak(LastValue
*unit
, int inNumSamples
);
349 void LastValue_next_kk(LastValue
*unit
, int inNumSamples
);
351 void Done_Ctor(Done
*unit
);
352 void Done_next(Done
*unit
, int inNumSamples
);
354 void FreeSelf_Ctor(FreeSelf
*unit
);
355 void FreeSelf_next(FreeSelf
*unit
, int inNumSamples
);
357 void FreeSelfWhenDone_Ctor(FreeSelfWhenDone
*unit
);
358 void FreeSelfWhenDone_next(FreeSelfWhenDone
*unit
, int inNumSamples
);
360 void PauseSelf_Ctor(PauseSelf
*unit
);
361 void PauseSelf_next(PauseSelf
*unit
, int inNumSamples
);
363 void Pause_Ctor(Pause
*unit
);
364 void Pause_next(Pause
*unit
, int inNumSamples
);
366 void Free_Ctor(Free
*unit
);
367 void Free_next(Free
*unit
, int inNumSamples
);
369 void PauseSelfWhenDone_Ctor(PauseSelfWhenDone
*unit
);
370 void PauseSelfWhenDone_next(PauseSelfWhenDone
*unit
, int inNumSamples
);
374 ////////////////////////////////////////////////////////////////////////////////////////////////////////
377 inline_functions
void Trig1_next_nova(Trig1
*unit
, int inNumSamples
);
378 inline_functions
void Trig1_next_k_nova(Trig1
*unit
, int inNumSamples
);
381 void Trig1_Ctor(Trig1
*unit
)
383 if (unit
->mCalcRate
== calc_FullRate
&& INRATE(0) != calc_FullRate
) {
385 if (!(BUFLENGTH
& 15))
386 SETCALC(Trig1_next_k_nova
);
389 SETCALC(Trig1_next_k
);
392 if (!(BUFLENGTH
& 15))
393 SETCALC(Trig1_next_nova
);
399 unit
->m_prevtrig
= 0.f
;
404 void Trig1_next(Trig1
*unit
, int inNumSamples
)
406 float *out
= ZOUT(0);
407 float *trig
= ZIN(0);
409 float sr
= unit
->mRate
->mSampleRate
;
410 float prevtrig
= unit
->m_prevtrig
;
411 unsigned long counter
= unit
->mCounter
;
414 float curtrig
= ZXP(trig
);
417 zout
= --counter
? 1.f
: 0.f
;
419 if (curtrig
> 0.f
&& prevtrig
<= 0.f
) {
420 counter
= (long)(dur
* sr
+ .5f
);
421 if (counter
< 1) counter
= 1;
430 unit
->m_prevtrig
= prevtrig
;
431 unit
->mCounter
= counter
;
434 void Trig1_next_k(Trig1
*unit
, int inNumSamples
)
436 float *out
= ZOUT(0);
437 float curtrig
= ZIN0(0);
439 float sr
= unit
->mRate
->mSampleRate
;
440 float prevtrig
= unit
->m_prevtrig
;
441 unsigned long counter
= unit
->mCounter
;
446 zout
= --counter
? 1.f
: 0.f
;
448 if (curtrig
> 0.f
&& prevtrig
<= 0.f
) {
449 counter
= (long)(dur
* sr
+ .5f
);
450 if (counter
< 1) counter
= 1;
459 unit
->m_prevtrig
= prevtrig
;
460 unit
->mCounter
= counter
;
464 void Trig1_next_nova(Trig1
*unit
, int inNumSamples
)
466 float *out
= ZOUT(0);
467 float *trig
= ZIN(0);
469 float sr
= unit
->mRate
->mSampleRate
;
470 float prevtrig
= unit
->m_prevtrig
;
471 unsigned long counter
= unit
->mCounter
;
473 if (counter
> inNumSamples
)
475 nova::setvec_simd(OUT(0), 1.f
, inNumSamples
);
476 counter
-= inNumSamples
;
478 prevtrig
= IN(0)[inNumSamples
-1];
483 float curtrig
= ZXP(trig
);
486 zout
= --counter
? 1.f
: 0.f
;
488 if (curtrig
> 0.f
&& prevtrig
<= 0.f
) {
489 counter
= (long)(dur
* sr
+ .5f
);
490 if (counter
< 1) counter
= 1;
500 unit
->m_prevtrig
= prevtrig
;
501 unit
->mCounter
= counter
;
505 void Trig1_next_k_nova(Trig1
*unit
, int inNumSamples
)
507 float *out
= ZOUT(0);
508 float curtrig
= ZIN0(0);
510 float sr
= unit
->mRate
->mSampleRate
;
511 float prevtrig
= unit
->m_prevtrig
;
512 unsigned long counter
= unit
->mCounter
;
514 if (counter
> inNumSamples
)
516 nova::setvec_simd(OUT(0), 1.f
, inNumSamples
);
517 counter
-= inNumSamples
;
521 else if (counter
== 0 && (curtrig
<= 0.f
|| prevtrig
> 0.f
))
523 nova::zerovec_simd(OUT(0), inNumSamples
);
531 zout
= --counter
? 1.f
: 0.f
;
533 if (curtrig
> 0.f
&& prevtrig
<= 0.f
) {
534 counter
= (long)(dur
* sr
+ .5f
);
535 if (counter
< 1) counter
= 1;
546 unit
->m_prevtrig
= prevtrig
;
547 unit
->mCounter
= counter
;
552 ////////////////////////////////////////////////////////////////////////////////////////////////////////
555 void Trig_next_nova(Trig
*unit
, int inNumSamples
);
556 void Trig_next_k_nova(Trig
*unit
, int inNumSamples
);
559 void Trig_Ctor(Trig
*unit
)
561 if (unit
->mCalcRate
== calc_FullRate
&& INRATE(0) != calc_FullRate
) {
563 if (!(BUFLENGTH
& 15))
564 SETCALC(Trig_next_k_nova
);
567 SETCALC(Trig_next_k
);
570 if (!(BUFLENGTH
& 15))
571 SETCALC(Trig_next_nova
);
578 unit
->m_prevtrig
= 0.f
;
584 void Trig_next(Trig
*unit
, int inNumSamples
)
586 float *out
= ZOUT(0);
587 float *trig
= ZIN(0);
589 float sr
= unit
->mRate
->mSampleRate
;
590 float prevtrig
= unit
->m_prevtrig
;
591 float level
= unit
->mLevel
;
592 unsigned long counter
= unit
->mCounter
;
595 float curtrig
= ZXP(trig
);
598 zout
= --counter
? level
: 0.f
;
600 if (curtrig
> 0.f
&& prevtrig
<= 0.f
) {
601 counter
= (long)(dur
* sr
+ .5f
);
602 if (counter
< 1) counter
= 1;
612 unit
->m_prevtrig
= prevtrig
;
613 unit
->mCounter
= counter
;
614 unit
->mLevel
= level
;
617 void Trig_next_k(Trig
*unit
, int inNumSamples
)
619 float *out
= ZOUT(0);
620 float curtrig
= ZIN0(0);
622 float sr
= unit
->mRate
->mSampleRate
;
623 float prevtrig
= unit
->m_prevtrig
;
624 float level
= unit
->mLevel
;
625 unsigned long counter
= unit
->mCounter
;
630 zout
= --counter
? level
: 0.f
;
632 if (curtrig
> 0.f
&& prevtrig
<= 0.f
) {
633 counter
= (long)(dur
* sr
+ .5f
);
634 if (counter
< 1) counter
= 1;
644 unit
->m_prevtrig
= prevtrig
;
645 unit
->mCounter
= counter
;
646 unit
->mLevel
= level
;
650 void Trig_next_nova(Trig
*unit
, int inNumSamples
)
652 float *out
= ZOUT(0);
653 float *trig
= ZIN(0);
655 float sr
= unit
->mRate
->mSampleRate
;
656 float prevtrig
= unit
->m_prevtrig
;
657 float level
= unit
->mLevel
;
658 unsigned long counter
= unit
->mCounter
;
660 if (counter
> inNumSamples
)
662 nova::setvec_simd(OUT(0), level
, inNumSamples
);
663 counter
-= inNumSamples
;
665 prevtrig
= IN(0)[inNumSamples
-1];
670 float curtrig
= ZXP(trig
);
673 zout
= --counter
? level
: 0.f
;
675 if (curtrig
> 0.f
&& prevtrig
<= 0.f
) {
676 counter
= (long)(dur
* sr
+ .5f
);
677 if (counter
< 1) counter
= 1;
688 unit
->m_prevtrig
= prevtrig
;
689 unit
->mCounter
= counter
;
690 unit
->mLevel
= level
;
693 void Trig_next_k_nova(Trig
*unit
, int inNumSamples
)
695 float *out
= ZOUT(0);
696 float curtrig
= ZIN0(0);
698 float sr
= unit
->mRate
->mSampleRate
;
699 float prevtrig
= unit
->m_prevtrig
;
700 float level
= unit
->mLevel
;
701 unsigned long counter
= unit
->mCounter
;
703 if (counter
> inNumSamples
)
705 nova::setvec_simd(OUT(0), level
, inNumSamples
);
706 counter
-= inNumSamples
;
710 else if (counter
== 0 && (curtrig
<= 0.f
|| prevtrig
> 0.f
))
712 nova::zerovec_simd(OUT(0), inNumSamples
);
720 zout
= --counter
? level
: 0.f
;
722 if (curtrig
> 0.f
&& prevtrig
<= 0.f
) {
723 counter
= (long)(dur
* sr
+ .5f
);
724 if (counter
< 1) counter
= 1;
735 unit
->m_prevtrig
= prevtrig
;
736 unit
->mCounter
= counter
;
737 unit
->mLevel
= level
;
741 ////////////////////////////////////////////////////////////////////////////////////////////////////////
743 void SendTrig_Ctor(SendTrig
*unit
)
745 if (INRATE(2) == calc_FullRate
) {
746 SETCALC(SendTrig_next_aka
);
748 SETCALC(SendTrig_next
);
750 unit
->m_prevtrig
= 0.f
;
753 void SendTrig_next(SendTrig
*unit
, int inNumSamples
)
755 float *trig
= ZIN(0);
756 float prevtrig
= unit
->m_prevtrig
;
759 float curtrig
= ZXP(trig
);
760 if (curtrig
> 0.f
&& prevtrig
<= 0.f
) {
761 SendTrigger(&unit
->mParent
->mNode
, (int)ZIN0(1), ZIN0(2));
765 unit
->m_prevtrig
= prevtrig
;
768 void SendTrig_next_aka(SendTrig
*unit
, int inNumSamples
)
770 float *trig
= ZIN(0);
771 float *value
= ZIN(2);
772 float prevtrig
= unit
->m_prevtrig
;
775 float curtrig
= ZXP(trig
);
776 float curval
= ZXP(value
);
777 if (curtrig
> 0.f
&& prevtrig
<= 0.f
) {
778 SendTrigger(&unit
->mParent
->mNode
, (int)ZIN0(1), curval
);
782 unit
->m_prevtrig
= prevtrig
;
786 ////////////////////////////////////////////////////////////////////////////////////////////////////////
788 void SendReply_Ctor(SendReply
*unit
)
790 const int kVarOffset
= 3;
792 unit
->m_prevtrig
= 0.f
;
793 unit
->m_cmdNameSize
= IN0(2);
794 unit
->m_valueSize
= unit
->mNumInputs
- unit
->m_cmdNameSize
- kVarOffset
;
797 unit
->m_cmdName
= (char*)RTAlloc(unit
->mWorld
, (unit
->m_cmdNameSize
+ 1) * sizeof(char));
798 for(int i
= 0; i
< (int)unit
->m_cmdNameSize
; i
++){
799 unit
->m_cmdName
[i
] = (char)IN0(kVarOffset
+i
);
802 unit
->m_cmdName
[unit
->m_cmdNameSize
] = 0;
804 unit
->m_valueOffset
= kVarOffset
+ unit
->m_cmdNameSize
;
805 unit
->m_values
= (float*)RTAlloc(unit
->mWorld
, unit
->m_valueSize
* sizeof(float));
807 if (INRATE(0) == calc_FullRate
) {
808 SETCALC(SendReply_next_aka
);
810 SETCALC(SendReply_next
);
814 void SendReply_Dtor(SendReply
* unit
)
816 RTFree(unit
->mWorld
, unit
->m_values
);
817 RTFree(unit
->mWorld
, unit
->m_cmdName
);
821 void SendReply_next(SendReply
*unit
, int inNumSamples
)
824 float prevtrig
= unit
->m_prevtrig
;
825 float *values
= unit
->m_values
;
826 int valueSize
= unit
->m_valueSize
;
827 int valueOffset
= unit
->m_valueOffset
;
828 for(int j
= 0; j
< inNumSamples
; j
++) {
829 float curtrig
= trig
[j
];
830 if (curtrig
> 0.f
&& prevtrig
<= 0.f
) {
831 for(int i
=0; i
<valueSize
; i
++) {
832 values
[i
] = IN(i
+ valueOffset
)[0];
834 SendNodeReply(&unit
->mParent
->mNode
, (int)ZIN0(1), unit
->m_cmdName
, unit
->m_valueSize
, values
);
838 unit
->m_prevtrig
= prevtrig
;
841 void SendReply_next_aka(SendReply
*unit
, int inNumSamples
)
844 float prevtrig
= unit
->m_prevtrig
;
845 float *invalues
= IN(unit
->m_valueOffset
);
846 float *values
= unit
->m_values
;
847 int valueSize
= unit
->m_valueSize
;
848 int valueOffset
= unit
->m_valueOffset
;
849 for(int j
= 0; j
< inNumSamples
; j
++) {
850 float curtrig
= trig
[j
];
851 if (curtrig
> 0.f
&& prevtrig
<= 0.f
) {
852 for(int i
=0; i
<valueSize
; i
++) {
853 int offset
= INRATE( i
+ valueOffset
) != calc_FullRate
? 0 : j
;
854 values
[i
] = IN(i
+ valueOffset
)[offset
];
856 SendNodeReply(&unit
->mParent
->mNode
, (int)ZIN0(1), unit
->m_cmdName
, unit
->m_valueSize
, values
);
860 unit
->m_prevtrig
= prevtrig
;
864 ////////////////////////////////////////////////////////////////////////////////////////////////////////
866 void Poll_Ctor(Poll
* unit
)
868 if (INRATE(0) == calc_FullRate
){
869 if (INRATE(1) == calc_FullRate
){
870 SETCALC(Poll_next_aa
);
872 SETCALC(Poll_next_ak
);
875 SETCALC(Poll_next_kk
);
878 unit
->m_trig
= IN0(0);
879 unit
->m_id
= IN0(3); // number of chars in the id string
880 unit
->m_id_string
= (char*)RTAlloc(unit
->mWorld
, ((int)unit
->m_id
+ 1) * sizeof(char));
881 for(int i
= 0; i
< (int)unit
->m_id
; i
++){
882 unit
->m_id_string
[i
] = (char)IN0(4+i
);
884 unit
->m_id_string
[(int)unit
->m_id
] = '\0';
886 unit
->m_mayprint
= unit
->mWorld
->mVerbosity
>= 0;
888 Poll_next_kk(unit
, 1);
891 void Poll_Dtor(Poll
* unit
)
893 RTFree(unit
->mWorld
, unit
->m_id_string
);
896 void Poll_next_aa(Poll
*unit
, int inNumSamples
){
899 float lasttrig
= unit
->m_trig
;
900 for(int i
= 0; i
< inNumSamples
; i
++){
901 if((lasttrig
<= 0.0) && (trig
[i
] > 0.0)){
902 if(unit
->m_mayprint
){
903 Print("%s: %g\n", unit
->m_id_string
, in
[i
]);
905 if(IN0(2) >= 0.0) SendTrigger(&unit
->mParent
->mNode
, (int)IN0(2), in
[i
]);
909 unit
->m_trig
= lasttrig
;
912 void Poll_next_kk(Poll
*unit
, int inNumSamples
){
915 if((unit
->m_trig
<= 0.0) && (trig
> 0.0)){
916 if(unit
->m_mayprint
){
917 Print("%s: %g\n", unit
->m_id_string
, in
);
919 if(IN0(2) >= 0.0) SendTrigger(&unit
->mParent
->mNode
, (int)IN0(2), in
);
925 void Poll_next_ak(Poll
*unit
, int inNumSamples
){
928 float lasttrig
= unit
->m_trig
;
929 for(int i
= 0; i
< inNumSamples
; i
++){
930 if((lasttrig
<= 0.0) && (trig
[i
] > 0.0)){
931 if(unit
->m_mayprint
){
932 Print("%s: %g\n", unit
->m_id_string
, in
);
934 if(IN0(2) >= 0.0) SendTrigger(&unit
->mParent
->mNode
, (int)IN0(2), in
);
938 unit
->m_trig
= lasttrig
;
943 ////////////////////////////////////////////////////////////////////////////////////////////////////////
945 void SetResetFF_Ctor(SetResetFF
*unit
)
947 if (INRATE(1) == calc_FullRate
) {
948 SETCALC(SetResetFF_next_a
);
950 SETCALC(SetResetFF_next_k
);
953 unit
->m_prevtrig
= 0.f
;
954 unit
->m_prevreset
= 0.f
;
961 void SetResetFF_next_a(SetResetFF
*unit
, int inNumSamples
)
963 float *out
= ZOUT(0);
964 float *trig
= ZIN(0);
965 float *reset
= ZIN(1);
966 float prevtrig
= unit
->m_prevtrig
;
967 float prevreset
= unit
->m_prevreset
;
968 float level
= unit
->mLevel
;
971 float curtrig
= ZXP(trig
);
972 float curreset
= ZXP(reset
);
973 if (prevreset
<= 0.f
&& curreset
> 0.f
) level
= 0.f
;
974 else if (prevtrig
<= 0.f
&& curtrig
> 0.f
) level
= 1.f
;
977 prevreset
= curreset
;
979 unit
->m_prevtrig
= prevtrig
;
980 unit
->m_prevreset
= prevreset
;
981 unit
->mLevel
= level
;
984 void SetResetFF_next_k(SetResetFF
*unit
, int inNumSamples
)
986 float *out
= ZOUT(0);
987 float *trig
= ZIN(0);
988 float curreset
= ZIN0(1);
989 float prevtrig
= unit
->m_prevtrig
;
990 float prevreset
= unit
->m_prevreset
;
991 float level
= unit
->mLevel
;
993 if (prevreset
<= 0.f
&& curreset
> 0.f
) level
= 0.f
;
996 float curtrig
= ZXP(trig
);
997 if (prevtrig
<= 0.f
&& curtrig
> 0.f
) level
= 1.f
;
1001 unit
->m_prevtrig
= prevtrig
;
1002 unit
->m_prevreset
= curreset
;
1003 unit
->mLevel
= level
;
1006 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1009 void ToggleFF_Ctor(ToggleFF
*unit
)
1011 SETCALC(ToggleFF_next
);
1013 unit
->m_prevtrig
= 0.f
;
1020 void ToggleFF_next(ToggleFF
*unit
, int inNumSamples
)
1022 float *out
= ZOUT(0);
1023 float *trig
= ZIN(0);
1024 float prevtrig
= unit
->m_prevtrig
;
1025 float level
= unit
->mLevel
;
1028 float curtrig
= ZXP(trig
);
1029 if (prevtrig
<= 0.f
&& curtrig
> 0.f
) level
= 1.f
- level
;
1033 unit
->m_prevtrig
= prevtrig
;
1034 unit
->mLevel
= level
;
1037 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1041 void Latch_next_ak_nova(Latch
*unit
, int inNumSamples
)
1043 float level
= unit
->mLevel
;
1045 float curtrig
= ZIN0(1);
1046 if (unit
->m_prevtrig
<= 0.f
&& curtrig
> 0.f
) level
= ZIN0(0);
1048 nova::setvec_simd(OUT(0), level
, inNumSamples
);
1050 unit
->m_prevtrig
= curtrig
;
1051 unit
->mLevel
= level
;
1054 void Latch_next_ak_nova_64(Latch
*unit
, int inNumSamples
)
1056 float level
= unit
->mLevel
;
1058 float curtrig
= ZIN0(1);
1059 if (unit
->m_prevtrig
<= 0.f
&& curtrig
> 0.f
) level
= ZIN0(0);
1061 nova::setvec_simd
<64>(OUT(0), level
);
1063 unit
->m_prevtrig
= curtrig
;
1064 unit
->mLevel
= level
;
1068 void Latch_Ctor(Latch
*unit
)
1070 if (INRATE(1) == calc_FullRate
) {
1071 SETCALC(Latch_next_aa
);
1074 if (BUFLENGTH
== 64)
1075 SETCALC(Latch_next_ak_nova_64
);
1076 if (!(BUFLENGTH
& 15))
1077 SETCALC(Latch_next_ak_nova
);
1080 SETCALC(Latch_next_ak
);
1083 unit
->m_prevtrig
= 0.f
;
1086 ZOUT0(0) = ZIN0(1) > 0.f
? ZIN0(0) : 0.f
;
1090 void Latch_next_ak(Latch
*unit
, int inNumSamples
)
1092 float *out
= ZOUT(0);
1093 float level
= unit
->mLevel
;
1095 float curtrig
= ZIN0(1);
1096 if (unit
->m_prevtrig
<= 0.f
&& curtrig
> 0.f
) level
= ZIN0(0);
1098 LOOP1(inNumSamples
, ZXP(out
) = level
; );
1100 unit
->m_prevtrig
= curtrig
;
1101 unit
->mLevel
= level
;
1105 void Latch_next_aa(Latch
*unit
, int inNumSamples
)
1107 float *out
= ZOUT(0);
1109 float *trig
= ZIN(1);
1110 float prevtrig
= unit
->m_prevtrig
;
1111 float level
= unit
->mLevel
;
1114 float curtrig
= ZXP(trig
);
1115 if (prevtrig
<= 0.f
&& curtrig
> 0.f
) level
= ZXP(in
);
1120 unit
->m_prevtrig
= prevtrig
;
1121 unit
->mLevel
= level
;
1126 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1129 inline_functions
void Gate_next_ak_nova(Gate
*unit
, int inNumSamples
)
1131 float *trig
= ZIN(1);
1132 float level
= unit
->mLevel
;
1134 float curtrig
= ZXP(trig
);
1135 if (curtrig
> 0.f
) {
1136 nova::copyvec_simd(OUT(0), IN(0), inNumSamples
);
1137 unit
->mLevel
= IN(0)[inNumSamples
-1];
1139 nova::setvec_simd(OUT(0), level
, inNumSamples
);
1142 inline_functions
void Gate_next_ak_nova_64(Gate
*unit
, int inNumSamples
)
1144 float *trig
= ZIN(1);
1145 float level
= unit
->mLevel
;
1147 float curtrig
= ZXP(trig
);
1148 if (curtrig
> 0.f
) {
1149 nova::copyvec_simd
<64>(OUT(0), IN(0));
1150 unit
->mLevel
= IN(0)[inNumSamples
-1];
1152 nova::setvec_simd
<64>(OUT(0), level
);
1156 void Gate_Ctor(Gate
*unit
)
1158 if (INRATE(1) == calc_FullRate
) {
1159 SETCALC(Gate_next_aa
);
1162 if (BUFLENGTH
== 64)
1163 SETCALC(Gate_next_ak_nova_64
);
1164 if (!(BUFLENGTH
& 15))
1165 SETCALC(Gate_next_ak_nova
);
1168 SETCALC(Gate_next_ak
);
1178 void Gate_next_ak(Gate
*unit
, int inNumSamples
)
1180 float *out
= ZOUT(0);
1182 float *trig
= ZIN(1);
1183 float level
= unit
->mLevel
;
1185 float curtrig
= ZXP(trig
);
1186 if (curtrig
> 0.f
) {
1191 unit
->mLevel
= level
;
1199 void Gate_next_aa(Gate
*unit
, int inNumSamples
)
1201 float *out
= ZOUT(0);
1203 float *trig
= ZIN(1);
1204 float level
= unit
->mLevel
;
1207 float curtrig
= ZXP(trig
);
1208 if (curtrig
> 0.f
) level
= ZXP(in
);
1212 unit
->mLevel
= level
;
1215 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1218 void Schmidt_Ctor(Schmidt
*unit
)
1220 SETCALC(Schmidt_next
);
1227 void Schmidt_next(Schmidt
*unit
, int inNumSamples
)
1229 float *out
= ZOUT(0);
1233 float level
= unit
->mLevel
;
1235 float zin
= ZXP(in
);
1237 if (zin
< lo
) level
= 0.f
;
1239 if (zin
> hi
) level
= 1.f
;
1243 unit
->mLevel
= level
;
1246 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1248 void PulseDivider_Ctor(PulseDivider
*unit
)
1250 SETCALC(PulseDivider_next
);
1252 unit
->m_prevtrig
= 0.f
;
1254 unit
->mCounter
= (long)floor(ZIN0(2) + 0.5);
1260 void PulseDivider_next(PulseDivider
*unit
, int inNumSamples
)
1262 float *out
= ZOUT(0);
1263 float *trig
= ZIN(0);
1264 long div
= (long)ZIN0(1);
1265 float prevtrig
= unit
->m_prevtrig
;
1266 long counter
= unit
->mCounter
;
1270 float curtrig
= ZXP(trig
);
1271 if (prevtrig
<= 0.f
&& curtrig
> 0.f
) {
1273 if (counter
>= div
) {
1285 unit
->mCounter
= counter
;
1286 unit
->m_prevtrig
= prevtrig
;
1289 //////////////////////////////////////////////////////////////////////////////////////////
1292 void PulseCount_Ctor(PulseCount
*unit
)
1294 if (INRATE(1) == calc_FullRate
) {
1295 SETCALC(PulseCount_next_a
);
1296 } else if (INRATE(1) == calc_BufRate
) {
1297 SETCALC(PulseCount_next_k
);
1299 SETCALC(PulseCount_next_0
);
1301 unit
->m_prevtrig
= 0.f
;
1302 unit
->m_prevreset
= 0.f
;
1309 void PulseCount_next_a(PulseCount
*unit
, int inNumSamples
)
1311 float *out
= ZOUT(0);
1312 float *trig
= ZIN(0);
1313 float *reset
= ZIN(1);
1314 float prevtrig
= unit
->m_prevtrig
;
1315 float prevreset
= unit
->m_prevreset
;
1316 float level
= unit
->mLevel
;
1319 float curtrig
= ZXP(trig
);
1320 float curreset
= ZXP(reset
);
1321 if (prevreset
<= 0.f
&& curreset
> 0.f
) level
= 0.f
;
1322 else if (prevtrig
<= 0.f
&& curtrig
> 0.f
) {
1327 prevreset
= curreset
;
1329 unit
->mLevel
= level
;
1330 unit
->m_prevtrig
= prevtrig
;
1331 unit
->m_prevreset
= prevreset
;
1334 void PulseCount_next_k(PulseCount
*unit
, int inNumSamples
)
1336 float *out
= ZOUT(0);
1337 float *trig
= ZIN(0);
1338 float curreset
= ZIN0(1);
1339 float prevtrig
= unit
->m_prevtrig
;
1340 float prevreset
= unit
->m_prevreset
;
1341 float level
= unit
->mLevel
;
1344 float curtrig
= ZXP(trig
);
1345 if (prevreset
<= 0.f
&& curreset
> 0.f
) level
= 0.f
;
1346 else if (prevtrig
<= 0.f
&& curtrig
> 0.f
) {
1351 prevreset
= curreset
;
1353 unit
->mLevel
= level
;
1354 unit
->m_prevtrig
= prevtrig
;
1355 unit
->m_prevreset
= prevreset
;
1358 void PulseCount_next_0(PulseCount
*unit
, int inNumSamples
)
1360 float *out
= ZOUT(0);
1361 float *trig
= ZIN(0);
1362 float prevtrig
= unit
->m_prevtrig
;
1363 float level
= unit
->mLevel
;
1366 float curtrig
= ZXP(trig
);
1367 if (prevtrig
<= 0.f
&& curtrig
> 0.f
) {
1373 unit
->mLevel
= level
;
1374 unit
->m_prevtrig
= prevtrig
;
1377 //////////////////////////////////////////////////////////////////////////////////////////
1380 void Stepper_Ctor(Stepper
*unit
)
1382 if (unit
->mCalcRate
== calc_FullRate
&& INRATE(0) == calc_FullRate
&& INRATE(1) == calc_ScalarRate
) {
1383 SETCALC(Stepper_next_a0
);
1384 } else if (unit
->mCalcRate
== calc_FullRate
&& INRATE(0) == calc_FullRate
&& INRATE(1) != calc_FullRate
) {
1385 SETCALC(Stepper_next_ak
);
1387 SETCALC(Stepper_next_aa
);
1390 int32 resetval
= (int32
)ZIN0(5);
1392 unit
->m_prevtrig
= 0.f
;
1393 unit
->m_prevreset
= 0.f
;
1394 unit
->mLevel
= (float)resetval
;
1400 void Stepper_next_aa(Stepper
*unit
, int inNumSamples
)
1402 float *out
= ZOUT(0);
1403 float *trig
= ZIN(0);
1404 float *reset
= ZIN(1);
1405 int32 zmin
= (int32
)ZIN0(2);
1406 int32 zmax
= (int32
)ZIN0(3);
1407 int32 step
= (int32
)ZIN0(4);
1408 int32 resetval
= (int32
)ZIN0(5);
1409 float prevtrig
= unit
->m_prevtrig
;
1410 float prevreset
= unit
->m_prevreset
;
1411 float level
= unit
->mLevel
;
1414 float curtrig
= ZXP(trig
);
1415 float curreset
= ZXP(reset
);
1416 if (prevreset
<= 0.f
&& curreset
> 0.f
) {
1417 level
= (float)sc_wrap(resetval
, zmin
, zmax
);
1418 } else if (prevtrig
<= 0.f
&& curtrig
> 0.f
) {
1419 level
= (float)sc_wrap((int32
)level
+ step
, zmin
, zmax
);
1423 prevreset
= curreset
;
1425 unit
->mLevel
= level
;
1426 unit
->m_prevtrig
= prevtrig
;
1427 unit
->m_prevreset
= prevreset
;
1430 void Stepper_next_ak(Stepper
*unit
, int inNumSamples
)
1432 float *out
= ZOUT(0);
1433 float *trig
= ZIN(0);
1434 float curreset
= ZIN0(1);
1435 int32 zmin
= (int32
)ZIN0(2);
1436 int32 zmax
= (int32
)ZIN0(3);
1437 int32 step
= (int32
)ZIN0(4);
1438 int32 resetval
= (int32
)ZIN0(5);
1439 float prevtrig
= unit
->m_prevtrig
;
1440 float prevreset
= unit
->m_prevreset
;
1441 float level
= unit
->mLevel
;
1444 float curtrig
= ZXP(trig
);
1445 if (prevreset
<= 0.f
&& curreset
> 0.f
) {
1446 level
= (float)sc_wrap(resetval
, zmin
, zmax
);
1447 } else if (prevtrig
<= 0.f
&& curtrig
> 0.f
) {
1448 level
= (float)sc_wrap((int32
)level
+ step
, zmin
, zmax
);
1452 prevreset
= curreset
;
1454 unit
->mLevel
= level
;
1455 unit
->m_prevtrig
= prevtrig
;
1456 unit
->m_prevreset
= prevreset
;
1459 void Stepper_next_a0(Stepper
*unit
, int inNumSamples
)
1461 float *out
= ZOUT(0);
1462 float *trig
= ZIN(0);
1463 int32 zmin
= (int32
)ZIN0(2);
1464 int32 zmax
= (int32
)ZIN0(3);
1465 int32 step
= (int32
)ZIN0(4);
1466 float prevtrig
= unit
->m_prevtrig
;
1467 float level
= unit
->mLevel
;
1470 float curtrig
= ZXP(trig
);
1471 if (prevtrig
<= 0.f
&& curtrig
> 0.f
) {
1472 level
= (float)sc_wrap((int32
)level
+ step
, zmin
, zmax
);
1477 unit
->mLevel
= level
;
1478 unit
->m_prevtrig
= prevtrig
;
1481 //////////////////////////////////////////////////////////////////////////////////////////
1483 void TDelay_Ctor(TDelay
*unit
)
1485 SETCALC(TDelay_next
);
1487 unit
->m_prevtrig
= 0.f
;
1495 void TDelay_next(TDelay
*unit
, int inNumSamples
)
1497 float *out
= ZOUT(0);
1498 float *trig
= ZIN(0);
1499 float dur
= ZIN0(1);
1500 float prevtrig
= unit
->m_prevtrig
;
1501 long counter
= unit
->mCounter
;
1504 float curtrig
= ZXP(trig
);
1509 } else if (counter
<=0) {
1510 if (prevtrig
<= 0.f
&& curtrig
> 0.f
) {
1511 counter
= (long)(dur
* unit
->mRate
->mSampleRate
+ .5f
);
1512 if (counter
< 1) counter
= 1;
1522 unit
->m_prevtrig
= prevtrig
;
1523 unit
->mCounter
= counter
;
1527 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1530 void ZeroCrossing_Ctor(ZeroCrossing
*unit
)
1532 SETCALC(ZeroCrossing_next_a
);
1534 unit
->m_prevfrac
= 0.f
;
1535 unit
->m_previn
= ZIN0(0);
1536 ZOUT0(0) = unit
->mLevel
= 0.f
;
1540 void ZeroCrossing_next_a(ZeroCrossing
*unit
, int inNumSamples
)
1542 float *out
= ZOUT(0);
1544 float previn
= unit
->m_previn
;
1545 float prevfrac
= unit
->m_prevfrac
;
1546 float level
= unit
->mLevel
;
1547 long counter
= unit
->mCounter
;
1551 float curin
= ZXP(in
);
1552 if (counter
> 4 && previn
<= 0.f
&& curin
> 0.f
) {
1553 float frac
= -previn
/(curin
-previn
);
1554 level
= unit
->mRate
->mSampleRate
/ (frac
+ counter
- prevfrac
);
1562 unit
->m_previn
= previn
;
1563 unit
->m_prevfrac
= prevfrac
;
1564 unit
->mLevel
= level
;
1565 unit
->mCounter
= counter
;
1568 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1570 void Timer_Ctor(Timer
*unit
)
1572 SETCALC(Timer_next_a
);
1574 unit
->m_prevfrac
= 0.f
;
1575 unit
->m_previn
= ZIN0(0);
1576 ZOUT0(0) = unit
->mLevel
= 0.f
;
1580 void Timer_next_a(Timer
*unit
, int inNumSamples
)
1582 float *out
= ZOUT(0);
1584 float previn
= unit
->m_previn
;
1585 float prevfrac
= unit
->m_prevfrac
;
1586 float level
= unit
->mLevel
;
1587 long counter
= unit
->mCounter
;
1591 float curin
= ZXP(in
);
1592 if (previn
<= 0.f
&& curin
> 0.f
) {
1593 float frac
= -previn
/(curin
-previn
);
1594 level
= unit
->mRate
->mSampleDur
* (frac
+ counter
- prevfrac
);
1602 unit
->m_previn
= previn
;
1603 unit
->m_prevfrac
= prevfrac
;
1604 unit
->mLevel
= level
;
1605 unit
->mCounter
= counter
;
1609 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1611 void Sweep_Ctor(Sweep
*unit
)
1613 if (INRATE(0) == calc_ScalarRate
) {
1614 if (INRATE(1) == calc_FullRate
) {
1615 SETCALC(Sweep_next_0a
);
1617 SETCALC(Sweep_next_0k
);
1619 } else if (INRATE(0) == calc_BufRate
) {
1620 if (INRATE(1) == calc_FullRate
) {
1621 SETCALC(Sweep_next_ka
);
1623 SETCALC(Sweep_next_kk
);
1626 if (INRATE(1) == calc_FullRate
) {
1627 SETCALC(Sweep_next_aa
);
1629 SETCALC(Sweep_next_ak
);
1633 unit
->m_previn
= ZIN0(0);
1634 ZOUT0(0) = unit
->mLevel
= 0.f
;
1637 void Sweep_next_0k(Sweep
*unit
, int inNumSamples
)
1639 float *out
= ZOUT(0);
1640 double rate
= ZIN0(1) * SAMPLEDUR
;
1641 double level
= unit
->mLevel
;
1648 unit
->mLevel
= level
;
1651 void Sweep_next_0a(Sweep
*unit
, int inNumSamples
)
1653 float *out
= ZOUT(0);
1654 float *rate
= ZIN(1);
1655 double level
= unit
->mLevel
;
1656 float sampledur
= SAMPLEDUR
;
1659 float zrate
= ZXP(rate
) * sampledur
;
1664 unit
->mLevel
= level
;
1667 void Sweep_next_kk(Sweep
*unit
, int inNumSamples
)
1669 float *out
= ZOUT(0);
1670 float curin
= ZIN0(0);
1671 double rate
= ZIN0(1) * SAMPLEDUR
;
1672 float previn
= unit
->m_previn
;
1673 double level
= unit
->mLevel
;
1675 if (previn
<= 0.f
&& curin
> 0.f
) {
1676 float frac
= -previn
/(curin
-previn
);
1677 level
= frac
* rate
;
1685 unit
->m_previn
= curin
;
1686 unit
->mLevel
= level
;
1689 void Sweep_next_ka(Sweep
*unit
, int inNumSamples
)
1691 float *out
= ZOUT(0);
1692 float curin
= ZIN0(0);
1693 float *rate
= ZIN(1);
1694 float previn
= unit
->m_previn
;
1695 double level
= unit
->mLevel
;
1696 float sampledur
= SAMPLEDUR
;
1698 if (previn
<= 0.f
&& curin
> 0.f
) {
1699 float frac
= -previn
/(curin
-previn
);
1700 level
= frac
* rate
[ZOFF
] * sampledur
;
1704 float zrate
= ZXP(rate
) * sampledur
;
1709 unit
->m_previn
= curin
;
1710 unit
->mLevel
= level
;
1713 void Sweep_next_ak(Sweep
*unit
, int inNumSamples
)
1715 float *out
= ZOUT(0);
1717 double rate
= ZIN0(1) * SAMPLEDUR
;
1718 float previn
= unit
->m_previn
;
1719 double level
= unit
->mLevel
;
1722 float curin
= ZXP(in
);
1723 if (previn
<= 0.f
&& curin
> 0.f
) {
1724 float frac
= -previn
/(curin
-previn
);
1725 level
= frac
* rate
;
1733 unit
->m_previn
= previn
;
1734 unit
->mLevel
= level
;
1737 void Sweep_next_aa(Sweep
*unit
, int inNumSamples
)
1739 float *out
= ZOUT(0);
1741 float *rate
= ZIN(1);
1742 float previn
= unit
->m_previn
;
1743 double level
= unit
->mLevel
;
1744 float sampledur
= SAMPLEDUR
;
1747 float curin
= ZXP(in
);
1748 float zrate
= ZXP(rate
) * sampledur
;
1749 if (previn
<= 0.f
&& curin
> 0.f
) {
1750 float frac
= -previn
/(curin
-previn
);
1751 level
= frac
* zrate
;
1759 unit
->m_previn
= previn
;
1760 unit
->mLevel
= level
;
1763 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1765 void Phasor_Ctor(Phasor
*unit
)
1767 if (unit
->mCalcRate
== calc_FullRate
) {
1768 if (INRATE(0) == calc_FullRate
) {
1769 if (INRATE(1) == calc_FullRate
) {
1770 SETCALC(Phasor_next_aa
);
1772 SETCALC(Phasor_next_ak
);
1775 SETCALC(Phasor_next_kk
);
1778 SETCALC(Phasor_next_ak
);
1781 unit
->m_previn
= ZIN0(0);
1782 ZOUT0(0) = unit
->mLevel
= ZIN0(2);
1785 void Phasor_next_kk(Phasor
*unit
, int inNumSamples
)
1787 float *out
= ZOUT(0);
1790 double rate
= ZIN0(1);
1791 double start
= ZIN0(2);
1792 double end
= ZIN0(3);
1793 float resetPos
= ZIN0(4);
1795 float previn
= unit
->m_previn
;
1796 double level
= unit
->mLevel
;
1798 if (previn
<= 0.f
&& in
> 0.f
) {
1802 level
= sc_wrap(level
, start
, end
);
1807 unit
->m_previn
= in
;
1808 unit
->mLevel
= level
;
1811 void Phasor_next_ak(Phasor
*unit
, int inNumSamples
)
1813 float *out
= ZOUT(0);
1816 double rate
= ZIN0(1);
1817 double start
= ZIN0(2);
1818 double end
= ZIN0(3);
1819 float resetPos
= ZIN0(4);
1821 float previn
= unit
->m_previn
;
1822 double level
= unit
->mLevel
;
1825 float curin
= ZXP(in
);
1826 if (previn
<= 0.f
&& curin
> 0.f
) {
1827 float frac
= 1.f
- previn
/(curin
-previn
);
1828 level
= resetPos
+ frac
* rate
;
1832 level
= sc_wrap(level
, start
, end
);
1837 unit
->m_previn
= previn
;
1838 unit
->mLevel
= level
;
1841 void Phasor_next_aa(Phasor
*unit
, int inNumSamples
)
1843 float *out
= ZOUT(0);
1845 float *rate
= ZIN(1);
1846 double start
= ZIN0(2);
1847 double end
= ZIN0(3);
1848 float resetPos
= ZIN0(4);
1850 float previn
= unit
->m_previn
;
1851 double level
= unit
->mLevel
;
1854 float curin
= ZXP(in
);
1855 double zrate
= ZXP(rate
);
1856 if (previn
<= 0.f
&& curin
> 0.f
) {
1857 float frac
= 1.f
- previn
/(curin
-previn
);
1858 level
= resetPos
+ frac
* zrate
;
1862 level
= sc_wrap(level
, start
, end
);
1866 unit
->m_previn
= previn
;
1867 unit
->mLevel
= level
;
1870 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1873 void Peak_next_ak_unroll(Peak
*unit
, int inNumSamples
);
1874 void Peak_next_ai_unroll(Peak
*unit
, int inNumSamples
);
1877 inline_functions
void Peak_next_ak_k_nova(Peak
*unit
, int inNumSamples
);
1878 inline_functions
void Peak_next_ai_k_nova(Peak
*unit
, int inNumSamples
);
1881 void Peak_Ctor(Peak
*unit
)
1883 if (BUFLENGTH
== 1 &&
1884 INRATE(0) == calc_FullRate
) {
1885 /* audio-rate input with control-rate output */
1886 if (INRATE(1) == calc_FullRate
) {
1887 SETCALC(Peak_next_aa_k
);
1888 } else if (INRATE(1) == calc_ScalarRate
) {
1890 if (INBUFLENGTH(0) & 7)
1891 SETCALC(Peak_next_ai_k
);
1893 SETCALC(Peak_next_ai_k_nova
);
1895 SETCALC(Peak_next_ai_k
);
1899 if (INBUFLENGTH(0) & 7)
1900 SETCALC(Peak_next_ak_k
);
1902 SETCALC(Peak_next_ak_k_nova
);
1904 SETCALC(Peak_next_ak_k
);
1908 if (INRATE(1) == calc_FullRate
) {
1909 SETCALC(Peak_next_aa
);
1910 } else if (INRATE(1) == calc_ScalarRate
) {
1912 SETCALC(Peak_next_ai
);
1914 SETCALC(Peak_next_ai_unroll
);
1917 SETCALC(Peak_next_ak
);
1919 SETCALC(Peak_next_ak_unroll
);
1922 unit
->m_prevtrig
= 0.f
;
1923 ZOUT0(0) = unit
->mLevel
= ZIN0(0);
1926 void Peak_next_ak(Peak
*unit
, int inNumSamples
)
1928 float *out
= ZOUT(0);
1930 float curtrig
= ZIN0(1);
1931 float level
= unit
->mLevel
;
1934 inlevel
= std::abs(ZXP(in
));
1935 level
= std::max(inlevel
, level
);
1938 if (unit
->m_prevtrig
<= 0.f
&& curtrig
> 0.f
) level
= inlevel
;
1939 unit
->m_prevtrig
= curtrig
;
1940 unit
->mLevel
= level
;
1943 void Peak_next_ai(Peak
*unit
, int inNumSamples
)
1945 float *out
= ZOUT(0);
1947 float level
= unit
->mLevel
;
1950 inlevel
= std::abs(ZXP(in
));
1951 level
= std::max(inlevel
, level
);
1954 unit
->mLevel
= level
;
1957 void Peak_next_aa(Peak
*unit
, int inNumSamples
)
1959 float *out
= ZOUT(0);
1961 float *trig
= ZIN(1);
1962 float prevtrig
= unit
->m_prevtrig
;
1963 float level
= unit
->mLevel
;
1966 float curtrig
= ZXP(trig
);
1967 float inlevel
= std::abs(ZXP(in
));
1968 level
= std::max(inlevel
, level
);
1970 if (prevtrig
<= 0.f
&& curtrig
> 0.f
) level
= inlevel
;
1973 unit
->m_prevtrig
= prevtrig
;
1974 unit
->mLevel
= level
;
1977 static inline float Peak_unroll_body(Peak
*unit
, int inNumSamples
, float & level
)
1979 float *out
= OUT(0);
1983 using namespace std
;
1984 for (int i
= 0; i
!= inNumSamples
; i
+= 8, out
+= 8, in
+= 8)
1986 float level0
= max(abs(in
[0]), level
);
1987 float level1
= max(abs(in
[1]), level0
);
1988 float level2
= max(abs(in
[2]), level1
);
1989 float level3
= max(abs(in
[3]), level2
);
1990 float level4
= max(abs(in
[4]), level3
);
1991 float level5
= max(abs(in
[5]), level4
);
1992 float level6
= max(abs(in
[6]), level5
);
1993 inlevel
= abs(in
[7]);
1994 float level7
= max(inlevel
, level6
);
2005 return inlevel
; /* input level of the last sample */
2008 void Peak_next_ak_unroll(Peak
*unit
, int inNumSamples
)
2010 float curtrig
= ZIN0(1);
2011 float level
= unit
->mLevel
;
2012 float inlevel
= Peak_unroll_body(unit
, inNumSamples
, level
);
2014 if (unit
->m_prevtrig
<= 0.f
&& curtrig
> 0.f
) level
= inlevel
;
2015 unit
->m_prevtrig
= curtrig
;
2016 unit
->mLevel
= level
;
2019 void Peak_next_ai_unroll(Peak
*unit
, int inNumSamples
)
2021 float level
= unit
->mLevel
;
2022 Peak_unroll_body(unit
, inNumSamples
, level
);
2023 unit
->mLevel
= level
;
2026 void Peak_next_ak_k(Peak
*unit
, int inNumSamples
)
2028 float *out
= ZOUT(0);
2030 float curtrig
= ZIN0(1);
2032 inNumSamples
= INBUFLENGTH(0);
2033 if (unit
->m_prevtrig
<= 0.f
&& curtrig
> 0.f
) {
2034 level
= std::abs(ZXP(in
));
2038 level
= unit
->mLevel
;
2040 level
= std::max(std::abs(ZXP(in
)), level
);
2043 unit
->m_prevtrig
= curtrig
;
2044 unit
->mLevel
= level
;
2047 void Peak_next_ai_k(Peak
*unit
, int inNumSamples
)
2049 float *out
= ZOUT(0);
2051 float level
= unit
->mLevel
;
2052 inNumSamples
= INBUFLENGTH(0);
2054 level
= std::max(std::abs(ZXP(in
)), level
);
2057 unit
->mLevel
= level
;
2060 void Peak_next_aa_k(Peak
*unit
, int inNumSamples
)
2062 float *out
= ZOUT(0);
2064 float *trig
= ZIN(1);
2065 float prevtrig
= unit
->m_prevtrig
;
2066 float level
= unit
->mLevel
;
2068 bool triggered
= false;
2070 inNumSamples
= INBUFLENGTH(0);
2072 float curtrig
= ZXP(trig
);
2073 float inlevel
= std::abs(ZXP(in
));
2074 level
= std::max(inlevel
, level
);
2075 if (prevtrig
<= 0.f
&& curtrig
> 0.f
) {
2083 ZXP(out
) = out_level
;
2086 unit
->m_prevtrig
= prevtrig
;
2087 unit
->mLevel
= level
;
2091 void Peak_next_ak_k_nova(Peak
*unit
, int inNumSamples
)
2093 float *out
= ZOUT(0);
2095 float curtrig
= ZIN0(1);
2096 float level
= unit
->mLevel
;
2098 inNumSamples
= INBUFLENGTH(0);
2099 inlevel
= nova::peak_vec_simd(in
, &level
, inNumSamples
);
2101 if (unit
->m_prevtrig
<= 0.f
&& curtrig
> 0.f
) level
= inlevel
;
2102 unit
->m_prevtrig
= curtrig
;
2103 unit
->mLevel
= level
;
2106 void Peak_next_ai_k_nova(Peak
*unit
, int inNumSamples
)
2108 float *out
= ZOUT(0);
2110 float level
= unit
->mLevel
;
2112 inNumSamples
= INBUFLENGTH(0);
2113 inlevel
= nova::peak_vec_simd(in
, &level
, inNumSamples
);
2115 unit
->mLevel
= level
;
2119 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2121 void RunningMin_Ctor(RunningMin
*unit
)
2123 if (INRATE(1) == calc_FullRate
) {
2124 SETCALC(RunningMin_next_aa
);
2125 } else if (INRATE(1) == calc_ScalarRate
) {
2126 SETCALC(RunningMin_next_ai
);
2128 SETCALC(RunningMin_next_ak
);
2130 unit
->m_prevtrig
= 0.f
;
2131 ZOUT0(0) = unit
->mLevel
= ZIN0(0);
2134 void RunningMin_next_ak(RunningMin
*unit
, int inNumSamples
)
2136 float *out
= ZOUT(0);
2138 float curtrig
= ZIN0(1);
2139 float level
= unit
->mLevel
;
2143 if (inlevel
< level
) level
= inlevel
;
2146 if (unit
->m_prevtrig
<= 0.f
&& curtrig
> 0.f
) level
= inlevel
;
2147 unit
->m_prevtrig
= curtrig
;
2148 unit
->mLevel
= level
;
2151 void RunningMin_next_ai(RunningMin
*unit
, int inNumSamples
)
2153 float *out
= ZOUT(0);
2155 float level
= unit
->mLevel
;
2159 if (inlevel
< level
) level
= inlevel
;
2162 unit
->mLevel
= level
;
2165 void RunningMin_next_aa(RunningMin
*unit
, int inNumSamples
)
2167 float *out
= ZOUT(0);
2169 float *trig
= ZIN(1);
2170 float prevtrig
= unit
->m_prevtrig
;
2171 float level
= unit
->mLevel
;
2174 float curtrig
= ZXP(trig
);
2175 float inlevel
= ZXP(in
);
2176 if (inlevel
< level
) level
= inlevel
;
2178 if (prevtrig
<= 0.f
&& curtrig
> 0.f
) level
= inlevel
;
2181 unit
->m_prevtrig
= prevtrig
;
2182 unit
->mLevel
= level
;
2186 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2187 void RunningMax_Ctor(RunningMax
*unit
)
2189 if (INRATE(1) == calc_FullRate
) {
2190 SETCALC(RunningMax_next_aa
);
2191 } else if (INRATE(1) == calc_ScalarRate
) {
2192 SETCALC(RunningMax_next_ai
);
2194 SETCALC(RunningMax_next_ak
);
2196 unit
->m_prevtrig
= 0.f
;
2197 ZOUT0(0) = unit
->mLevel
= ZIN0(0);
2200 void RunningMax_next_ak(RunningMax
*unit
, int inNumSamples
)
2202 float *out
= ZOUT(0);
2204 float curtrig
= ZIN0(1);
2205 float level
= unit
->mLevel
;
2209 if (inlevel
> level
) level
= inlevel
;
2212 if (unit
->m_prevtrig
<= 0.f
&& curtrig
> 0.f
) level
= inlevel
;
2213 unit
->m_prevtrig
= curtrig
;
2214 unit
->mLevel
= level
;
2217 void RunningMax_next_ai(RunningMax
*unit
, int inNumSamples
)
2219 float *out
= ZOUT(0);
2221 float level
= unit
->mLevel
;
2225 if (inlevel
> level
) level
= inlevel
;
2228 unit
->mLevel
= level
;
2231 void RunningMax_next_aa(RunningMax
*unit
, int inNumSamples
)
2233 float *out
= ZOUT(0);
2235 float *trig
= ZIN(1);
2236 float prevtrig
= unit
->m_prevtrig
;
2237 float level
= unit
->mLevel
;
2240 float curtrig
= ZXP(trig
);
2241 float inlevel
= ZXP(in
);
2242 if (inlevel
> level
) level
= inlevel
;
2244 if (prevtrig
<= 0.f
&& curtrig
> 0.f
) level
= inlevel
;
2247 unit
->m_prevtrig
= prevtrig
;
2248 unit
->mLevel
= level
;
2252 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2255 void PeakFollower_Ctor(PeakFollower
*unit
)
2258 if (INRATE(1) == calc_ScalarRate
) {
2259 SETCALC(PeakFollower_next_ai
);
2261 SETCALC(PeakFollower_next
);
2264 unit
->mDecay
= ZIN0(1);
2265 ZOUT0(0) = unit
->mLevel
= ZIN0(0);
2268 void PeakFollower_next(PeakFollower
*unit
, int inNumSamples
)
2270 float *out
= ZOUT(0);
2272 float decay
= ZIN0(1);
2273 float level
= unit
->mLevel
;
2276 if(decay
== unit
->mDecay
) {
2278 float inlevel
= std::abs(ZXP(in
));
2279 if (inlevel
>= level
) {
2282 level
= inlevel
+ decay
* (level
- inlevel
);
2289 float decay_slope
= CALCSLOPE(decay
, unit
->mDecay
);
2290 if (decay
>= 0.f
&& unit
->mDecay
>= 0.f
) {
2292 float inlevel
= std::abs(ZXP(in
));
2293 if (inlevel
>= level
) {
2296 level
= inlevel
+ decay
* (level
- inlevel
);
2297 decay
+= decay_slope
;
2301 } else if (decay
<= 0.f
&& unit
->mDecay
<= 0.f
) {
2303 float inlevel
= std::abs(ZXP(in
));
2304 if (inlevel
>= level
) {
2307 level
= inlevel
+ decay
* (level
+ inlevel
);
2308 decay
+= decay_slope
;
2314 float inlevel
= std::abs(ZXP(in
));
2315 if (inlevel
>= level
) {
2318 level
= (1.f
- std::abs(decay
)) * inlevel
+ decay
* level
;
2319 decay
+= decay_slope
;
2326 unit
->mLevel
= level
;
2327 unit
->mDecay
= decay
;
2331 void PeakFollower_next_ai(PeakFollower
*unit
, int inNumSamples
)
2333 float *out
= ZOUT(0);
2335 float decay
= ZIN0(1);
2336 float level
= unit
->mLevel
;
2339 float inlevel
= std::abs(ZXP(in
));
2340 if (inlevel
>= level
) {
2343 level
= inlevel
+ decay
* (level
- inlevel
);
2348 unit
->mLevel
= level
;
2352 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2355 void MostChange_Ctor(MostChange
*unit
)
2357 if (INRATE(0) == calc_FullRate
) {
2358 if (INRATE(1) == calc_FullRate
) {
2359 SETCALC(MostChange_next_aa
);
2361 SETCALC(MostChange_next_ak
);
2364 if (INRATE(1) == calc_FullRate
) {
2365 SETCALC(MostChange_next_ka
);
2367 SETCALC(MostChange_next_aa
);
2373 MostChange_next_aa(unit
, 1);
2376 void MostChange_next_ak(MostChange
*unit
, int inNumSamples
)
2378 float *out
= ZOUT(0);
2381 float prevA
= unit
->mPrevA
;
2382 float prevB
= unit
->mPrevB
;
2383 int recent
= unit
->mRecent
;
2386 float diff
= std::abs(xa
- prevA
) - std::abs(xb
- prevB
);
2390 } else if (diff
< 0.f
) {
2394 ZXP(out
) = recent
? xb
: xa
;
2399 unit
->mPrevA
= prevA
;
2400 unit
->mPrevB
= prevB
;
2401 unit
->mRecent
= recent
;
2404 void MostChange_next_aa(MostChange
*unit
, int inNumSamples
)
2406 float *out
= ZOUT(0);
2409 float prevA
= unit
->mPrevA
;
2410 float prevB
= unit
->mPrevB
;
2411 int recent
= unit
->mRecent
;
2415 float diff
= std::abs(xa
- prevA
) - std::abs(xb
- prevB
);
2419 } else if (diff
< 0.f
) {
2423 ZXP(out
) = recent
? xb
: xa
;
2428 unit
->mPrevA
= prevA
;
2429 unit
->mPrevB
= prevB
;
2430 unit
->mRecent
= recent
;
2433 void MostChange_next_ka(MostChange
*unit
, int inNumSamples
)
2435 float *out
= ZOUT(0);
2438 float prevA
= unit
->mPrevA
;
2439 float prevB
= unit
->mPrevB
;
2440 int recent
= unit
->mRecent
;
2443 float diff
= std::abs(xa
- prevA
) - std::abs(xb
- prevB
);
2447 } else if (diff
< 0.f
) {
2451 ZXP(out
) = recent
? xb
: xa
;
2456 unit
->mPrevA
= prevA
;
2457 unit
->mPrevB
= prevB
;
2458 unit
->mRecent
= recent
;
2462 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2464 void LeastChange_Ctor(LeastChange
*unit
)
2466 if (INRATE(0) == calc_FullRate
) {
2467 if (INRATE(1) == calc_FullRate
) {
2468 SETCALC(LeastChange_next_aa
);
2470 SETCALC(LeastChange_next_ak
);
2473 if (INRATE(1) == calc_FullRate
) {
2474 SETCALC(LeastChange_next_ka
);
2476 SETCALC(LeastChange_next_aa
);
2482 LeastChange_next_aa(unit
, 1);
2485 void LeastChange_next_ak(LeastChange
*unit
, int inNumSamples
)
2487 float *out
= ZOUT(0);
2490 float prevA
= unit
->mPrevA
;
2491 float prevB
= unit
->mPrevB
;
2492 int recent
= unit
->mRecent
;
2495 float diff
= std::abs(xa
- prevA
) - std::abs(xb
- prevB
);
2499 } else if (diff
> 0.f
) {
2503 ZXP(out
) = recent
? xb
: xa
;
2508 unit
->mPrevA
= prevA
;
2509 unit
->mPrevB
= prevB
;
2510 unit
->mRecent
= recent
;
2513 void LeastChange_next_aa(LeastChange
*unit
, int inNumSamples
)
2515 float *out
= ZOUT(0);
2518 float prevA
= unit
->mPrevA
;
2519 float prevB
= unit
->mPrevB
;
2520 int recent
= unit
->mRecent
;
2524 float diff
= std::abs(xa
- prevA
) - std::abs(xb
- prevB
);
2528 } else if (diff
> 0.f
) {
2532 ZXP(out
) = recent
? xb
: xa
;
2537 unit
->mPrevA
= prevA
;
2538 unit
->mPrevB
= prevB
;
2539 unit
->mRecent
= recent
;
2542 void LeastChange_next_ka(LeastChange
*unit
, int inNumSamples
)
2544 float *out
= ZOUT(0);
2547 float prevA
= unit
->mPrevA
;
2548 float prevB
= unit
->mPrevB
;
2549 int recent
= unit
->mRecent
;
2552 float diff
= std::abs(xa
- prevA
) - std::abs(xb
- prevB
);
2556 } else if (diff
> 0.f
) {
2560 ZXP(out
) = recent
? xb
: xa
;
2565 unit
->mPrevA
= prevA
;
2566 unit
->mPrevB
= prevB
;
2567 unit
->mRecent
= recent
;
2571 ////////////////////
2573 void LastValue_Ctor(LastValue
*unit
)
2575 if (INRATE(0) == calc_FullRate
) {
2576 SETCALC(LastValue_next_ak
);
2578 SETCALC(LastValue_next_kk
);
2581 unit
->mPrev
= ZIN0(0);
2582 unit
->mCurr
= ZIN0(0);
2583 LastValue_next_kk(unit
, 1);
2586 void LastValue_next_kk(LastValue
*unit
, int inNumSamples
)
2588 float *out
= ZOUT(0);
2589 float inval
= ZIN0(0);
2590 float delta
= ZIN0(1);
2591 float diff
= std::abs(inval
- unit
->mCurr
);
2593 unit
->mPrev
= unit
->mCurr
;
2594 unit
->mCurr
= inval
;
2596 float level
= unit
->mPrev
;
2597 LOOP1(inNumSamples
, ZXP(out
) = level
; );
2601 void LastValue_next_ak(LastValue
*unit
, int inNumSamples
)
2603 float *out
= ZOUT(0);
2605 float delta
= ZIN0(1);
2606 float prev
= unit
->mPrev
;
2607 float curr
= unit
->mCurr
;
2610 float inval
= ZXP(in
);
2611 float diff
= std::abs(inval
- curr
);
2625 //////////////////////////////////////////////////////////////////////////////////////////
2627 void Done_Ctor(Done
*unit
)
2631 unit
->m_src
= unit
->mInput
[0]->mFromUnit
;
2638 void Done_next(Done
*unit
, int inNumSamples
)
2640 float *out
= OUT(0);
2641 Unit
*src
= unit
->m_src
;
2642 if (src
) *out
= src
->mDone
? 1.f
: 0.f
;
2646 //////////////////////////////////////////////////////////////////////////////////////////
2648 void FreeSelf_Ctor(FreeSelf
*unit
)
2650 SETCALC(FreeSelf_next
);
2651 unit
->m_prevtrig
= 0.f
;
2652 FreeSelf_next(unit
, 1);
2656 void FreeSelf_next(FreeSelf
*unit
, int inNumSamples
)
2659 if (in
> 0.f
&& unit
->m_prevtrig
<= 0.f
) {
2660 NodeEnd(&unit
->mParent
->mNode
);
2662 unit
->m_prevtrig
= in
;
2665 //////////////////////////////////////////////////////////////////////////////////////////
2667 void PauseSelf_Ctor(PauseSelf
*unit
)
2669 SETCALC(PauseSelf_next
);
2670 unit
->m_prevtrig
= 0.f
;
2671 PauseSelf_next(unit
, 1);
2675 void PauseSelf_next(PauseSelf
*unit
, int inNumSamples
)
2678 if (in
> 0.f
&& unit
->m_prevtrig
<= 0.f
) {
2679 NodeRun(&unit
->mParent
->mNode
, 0);
2681 unit
->m_prevtrig
= in
;
2684 //////////////////////////////////////////////////////////////////////////////////////////
2686 void Pause_Ctor(Pause
*unit
)
2688 SETCALC(Pause_next
);
2696 void Pause_next(Pause
*unit
, int inNumSamples
)
2699 int state
= in
== 0.f
? 0 : 1;
2700 if (state
!= unit
->m_state
) {
2701 unit
->m_state
= state
;
2702 int id
= (int)ZIN0(1);
2703 Node
*node
= SC_GetNode(unit
->mWorld
, id
);
2705 NodeRun(node
, state
);
2711 //////////////////////////////////////////////////////////////////////////////////////////
2713 void Free_Ctor(Free
*unit
)
2717 unit
->m_prevtrig
= 0.f
;
2723 void Free_next(Free
*unit
, int inNumSamples
)
2725 float trig
= ZIN0(0);
2726 if (trig
> 0.f
&& unit
->m_prevtrig
<= 0) {
2727 int id
= (int)ZIN0(1);
2728 Node
*node
= SC_GetNode(unit
->mWorld
, id
);
2733 unit
->m_prevtrig
= trig
;
2737 //////////////////////////////////////////////////////////////////////////////////////////
2739 void FreeSelfWhenDone_Ctor(FreeSelfWhenDone
*unit
)
2741 unit
->m_src
= unit
->mInput
[0]->mFromUnit
;
2744 SETCALC(FreeSelfWhenDone_next
);
2745 FreeSelfWhenDone_next(unit
, 1);
2747 SETCALC(ClearUnitOutputs
);
2748 ClearUnitOutputs(unit
, 1);
2753 void FreeSelfWhenDone_next(FreeSelfWhenDone
*unit
, int inNumSamples
)
2755 float *out
= OUT(0);
2757 Unit
*src
= unit
->m_src
;
2759 NodeEnd(&unit
->mParent
->mNode
);
2760 SETCALC(ClearUnitOutputs
);
2765 //////////////////////////////////////////////////////////////////////////////////////////
2767 void PauseSelfWhenDone_Ctor(PauseSelfWhenDone
*unit
)
2769 unit
->m_src
= unit
->mInput
[0]->mFromUnit
;
2772 SETCALC(PauseSelfWhenDone_next
);
2773 PauseSelfWhenDone_next(unit
, 1);
2775 SETCALC(ClearUnitOutputs
);
2776 ClearUnitOutputs(unit
, 1);
2781 void PauseSelfWhenDone_next(PauseSelfWhenDone
*unit
, int inNumSamples
)
2783 float *out
= OUT(0);
2785 Unit
*src
= unit
->m_src
;
2787 NodeRun(&unit
->mParent
->mNode
, 0);
2788 SETCALC(ClearUnitOutputs
);
2793 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2798 // rate, level lag, replyid, channel count, [channels, ], cmd name size, [cmdname, ]
2799 static const int rateIndex
= 0;
2800 static const int levelLagIndex
= 1;
2801 static const int replyIdIndex
= 2;
2802 static const int channelCountIndex
= 3;
2803 static const int signalStartIndex
= 4;
2807 SendPeakRMS
* unit
= this;
2809 mChannelCount
= (unsigned int)IN0(channelCountIndex
);
2810 size_t channelDataAllocSize
= mChannelCount
* 3 * sizeof(float);
2812 int cmdSizeIndex
= signalStartIndex
+ mChannelCount
;
2813 size_t cmdNameSize
= IN0(cmdSizeIndex
);
2814 size_t cmdNameAllocSize
= (cmdNameSize
+ 1) * sizeof(char);
2816 void * allocData
= RTAlloc(unit
->mWorld
, channelDataAllocSize
+ cmdNameAllocSize
);
2818 memset(allocData
, 0, channelDataAllocSize
);
2819 mChannelData
= (float*)allocData
;
2821 char * cmdName
= (char*)(allocData
) + channelDataAllocSize
;
2823 size_t cmdNameIndex
= cmdSizeIndex
+ 1;
2824 for(int i
= 0; i
< cmdNameSize
; i
++)
2825 cmdName
[i
] = (char)IN0(cmdNameIndex
+ i
);
2826 cmdName
[cmdNameSize
] = 0;
2828 if ((FULLBUFLENGTH
& 15) == 0) {
2829 if (mCalcRate
== calc_FullRate
)
2830 SETCALC(SendPeakRMS::perform_a
<true>);
2832 SETCALC(SendPeakRMS::perform_k
<true>);
2834 if (mCalcRate
== calc_FullRate
)
2835 SETCALC(SendPeakRMS::perform_a
<false>);
2837 SETCALC(SendPeakRMS::perform_k
<false>);
2840 float replyRate
= IN0(rateIndex
);
2842 mAudioSamplesPerTick
= FULLRATE
/ replyRate
;
2843 mControlSamplesPerTick
= BUFRATE
/ replyRate
;
2845 mPhaseRemain
= (mCalcRate
== calc_FullRate
) ? mAudioSamplesPerTick
2846 : mControlSamplesPerTick
;
2848 float32 lag
= ZIN0(levelLagIndex
);
2849 mB1
= (lag
!= 0.f
) ? exp(log001
/ (lag
* replyRate
))
2855 SendPeakRMS
* unit
= this;
2856 RTFree(unit
->mWorld
, mChannelData
);
2859 unsigned int mChannelCount
;
2860 float * mChannelData
;
2863 int mAudioSamplesPerTick
;
2864 int mControlSamplesPerTick
;
2867 void performLevelLag(float & out
, float y0
, float & y1
)
2872 out
= y1
= y0
+ mB1
* (y1
- y0
);
2875 char * getCmdName (void)
2877 void * buffer
= mChannelData
;
2878 return (char*)(buffer
) + mChannelCount
* 3 * sizeof(float);
2881 void sendReply(void)
2883 SendPeakRMS
* unit
= this;
2884 float * reply
= (float*)alloca(mChannelCount
* 2 * sizeof(float));
2887 for (int i
= 0; i
!= mChannelCount
; ++i
) {
2888 float & maxLevel
= reply
[2*i
];
2889 float & rms
= reply
[2*i
+ 1];
2891 performLevelLag(maxLevel
, mChannelData
[2*i
], mChannelData
[2*mChannelCount
+ i
]);
2893 if (INRATE(signalStartIndex
+ i
) == calc_FullRate
)
2894 rms
= std::sqrt(mChannelData
[2*i
+ 1] / (float)mAudioSamplesPerTick
);
2896 rms
= std::sqrt(mChannelData
[2*i
+ 1] / (float)mControlSamplesPerTick
);
2899 SendNodeReply(&unit
->mParent
->mNode
, (int)ZIN0(replyIdIndex
), getCmdName(), mChannelCount
*2, reply
);
2900 memset(mChannelData
, 0, mChannelCount
* 2 * sizeof(float));
2903 template <bool simd
>
2904 void analyzeFullBlock(void)
2906 SendPeakRMS
* unit
= this;
2907 for (int i
= 0; i
!= mChannelCount
; ++i
) {
2908 float * in
= IN(signalStartIndex
+ i
);
2909 int numSamples
= INBUFLENGTH(signalStartIndex
+ i
);
2911 float & level
= mChannelData
[2*i
];
2912 float & sqrsum
= mChannelData
[2*i
+ 1];
2913 if (numSamples
== 1)
2914 nova::peak_rms_vec(in
, &level
, &sqrsum
, 1);
2917 nova::peak_rms_vec_simd(in
, &level
, &sqrsum
, numSamples
);
2919 nova::peak_rms_vec(in
, &level
, &sqrsum
, numSamples
);
2924 void analyzePartialBlock(int firstSample
, int samplesToAnalyze
)
2926 SendPeakRMS
* unit
= this;
2927 for (int i
= 0; i
!= mChannelCount
; ++i
) {
2928 float * in
= IN(signalStartIndex
+ i
) + firstSample
;
2929 int numSamples
= INBUFLENGTH(signalStartIndex
+ i
);
2931 float & level
= mChannelData
[2*i
];
2932 float & sqrsum
= mChannelData
[2*i
+ 1];
2933 if (numSamples
== 1) {
2934 if (firstSample
== 0)
2935 nova::peak_rms_vec(in
, &level
, &sqrsum
, 1);
2937 if (!(samplesToAnalyze
& 15) && !(firstSample
& 3)) // check for unrolling and alignment
2938 nova::peak_rms_vec_simd(in
, &level
, &sqrsum
, samplesToAnalyze
);
2940 nova::peak_rms_vec(in
, &level
, &sqrsum
, samplesToAnalyze
);
2945 template <bool simd
>
2946 inline void next_k(int inNumSamples
)
2950 if (mPhaseRemain
<= 0) {
2951 mPhaseRemain
+= mControlSamplesPerTick
;
2955 analyzeFullBlock
<simd
>();
2958 template <bool simd
>
2959 inline void next_a(int inNumSamples
)
2961 if (mPhaseRemain
>= inNumSamples
) {
2962 mPhaseRemain
-= inNumSamples
;
2963 analyzeFullBlock
<simd
>();
2965 if (mPhaseRemain
== 0) {
2967 mPhaseRemain
= mAudioSamplesPerTick
;
2970 int startSample
= 0;
2971 int samplesToAnalyze
= std::min(mPhaseRemain
, inNumSamples
);
2972 int remain
= inNumSamples
;
2975 analyzePartialBlock(startSample
, samplesToAnalyze
);
2977 startSample
+= samplesToAnalyze
;
2978 mPhaseRemain
-= samplesToAnalyze
;
2979 if (mPhaseRemain
== 0) {
2981 mPhaseRemain
= mAudioSamplesPerTick
;
2984 remain
-= samplesToAnalyze
;
2985 samplesToAnalyze
= std::min(remain
, mPhaseRemain
);
2990 template <bool simd
>
2991 static void perform_k(Unit
* unit
, int inNumSamples
)
2993 static_cast<SendPeakRMS
*>(unit
)->next_k
<simd
>(inNumSamples
);
2996 template <bool simd
>
2997 static void perform_a(Unit
* unit
, int inNumSamples
)
2999 static_cast<SendPeakRMS
*>(unit
)->next_a
<simd
>(inNumSamples
);
3003 static void SendPeakRMS_Ctor(SendPeakRMS
* unit
) { new(unit
) SendPeakRMS (); }
3004 static void SendPeakRMS_Dtor(SendPeakRMS
* unit
) { unit
->~SendPeakRMS (); }
3006 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3012 DefineSimpleUnit(Trig1
);
3013 DefineSimpleUnit(Trig
);
3014 DefineSimpleUnit(SendTrig
);
3015 DefineDtorUnit(SendReply
);
3016 DefineDtorUnit(Poll
);
3017 DefineSimpleUnit(ToggleFF
);
3018 DefineSimpleUnit(SetResetFF
);
3019 DefineSimpleUnit(Latch
);
3020 DefineSimpleUnit(Gate
);
3021 DefineSimpleUnit(Schmidt
);
3022 DefineSimpleUnit(PulseDivider
);
3023 DefineSimpleUnit(PulseCount
);
3024 DefineSimpleUnit(Stepper
);
3025 DefineSimpleUnit(TDelay
);
3026 DefineSimpleUnit(ZeroCrossing
);
3027 DefineSimpleUnit(Timer
);
3028 DefineSimpleUnit(Sweep
);
3029 DefineSimpleUnit(Phasor
);
3030 DefineSimpleUnit(Peak
);
3031 DefineSimpleUnit(RunningMin
);
3032 DefineSimpleUnit(RunningMax
);
3033 DefineSimpleUnit(PeakFollower
);
3034 DefineSimpleUnit(MostChange
);
3035 DefineSimpleUnit(LeastChange
);
3036 DefineSimpleUnit(LastValue
);
3037 DefineSimpleUnit(Done
);
3038 DefineSimpleUnit(Pause
);
3039 DefineSimpleUnit(FreeSelf
);
3040 DefineSimpleUnit(PauseSelf
);
3041 DefineSimpleUnit(Free
);
3042 DefineSimpleUnit(FreeSelfWhenDone
);
3043 DefineSimpleUnit(PauseSelfWhenDone
);
3045 DefineDtorUnit(SendPeakRMS
);