1+ #include " AmpSliceAlgorithm.h"
2+ #include " IPlugParameter.h"
3+ #include " ReacomaExtension.h"
4+ #include " flucoma/clients/common/ParameterTypes.hpp"
5+ #include " flucoma/clients/rt/AmpSliceClient.hpp"
6+
7+ AmpSliceAlgorithm::AmpSliceAlgorithm (ReacomaExtension *apiProvider)
8+ : SlicingAlgorithm<NRTThreadedAmpSliceClient>(apiProvider) {}
9+
10+ AmpSliceAlgorithm::~AmpSliceAlgorithm () = default ;
11+
12+ void AmpSliceAlgorithm::RegisterParameters () {
13+ mBaseParamIdx = mApiProvider ->NParams ();
14+
15+ for (int i = 0 ; i < kNumParams ; ++i) {
16+ mApiProvider ->AddParam ();
17+ }
18+ mApiProvider ->GetParam (mBaseParamIdx + kFastRampUpTime )
19+ ->InitInt (" Fast Ramp Up Length (samples)" , 3 , 1 , 88200 );
20+ mApiProvider ->GetParam (mBaseParamIdx + kFastRampDownTime )
21+ ->InitInt (" Fast Ramp Down Length (samples)" , 383 , 1 , 88200 );
22+ mApiProvider ->GetParam (mBaseParamIdx + kSlowRampUpTime )
23+ ->InitDouble (" Slow Ramp Down Length (samples)" , 2205 , 1 , 88200 , 1 );
24+ mApiProvider ->GetParam (mBaseParamIdx + kSlowRampDownTime )
25+ ->InitDouble (" Fast Ramp Down Length (samples)" , 2205 , 1 , 88200 , 1 );
26+ mApiProvider ->GetParam (mBaseParamIdx + kOnThreshold )
27+ ->InitInt (" On Threshold (dB)" , 19 , -144 , 144 );
28+ mApiProvider ->GetParam (mBaseParamIdx + kOffThreshold )
29+ ->InitInt (" Off Threshold" , 8 , -144 , 144 );
30+ mApiProvider ->GetParam (mBaseParamIdx + kSilenceThreshold )
31+ ->InitInt (" Floor value (dB)" , -70 , -144 , 144 );
32+ mApiProvider ->GetParam (mBaseParamIdx + kDebounce )
33+ ->InitInt (" Minimum Slice Length (samples)" , 1323 , 1 , 88200 );
34+ mApiProvider ->GetParam (mBaseParamIdx + kHiPassFreq )
35+ ->InitInt (" High-Pass Filter Cutoff" , 2000 , 0 , 10000 );
36+ }
37+
38+ bool AmpSliceAlgorithm::DoProcess (InputBufferT::type &sourceBuffer,
39+ int numChannels, int frameCount,
40+ int sampleRate) {
41+ int estimatedSlices = std::max (1 , static_cast <int >(frameCount / 1024.0 ));
42+ auto outBuffer =
43+ std::make_shared<MemoryBufferAdaptor>(1 , estimatedSlices, sampleRate);
44+ auto slicesOutputBuffer = fluid::client::BufferT::type (outBuffer);
45+
46+ auto fastRampUpTime =
47+ mApiProvider ->GetParam (mBaseParamIdx + kFastRampUpTime )->Value ();
48+ auto fastRampDownTime =
49+ mApiProvider ->GetParam (mBaseParamIdx + kFastRampDownTime )->Value ();
50+ auto slowRampUpTime =
51+ mApiProvider ->GetParam (mBaseParamIdx + kSlowRampUpTime )->Value ();
52+ auto slowRampDownTime =
53+ mApiProvider ->GetParam (mBaseParamIdx + kSlowRampDownTime )->Value ();
54+ auto onThreshold =
55+ mApiProvider ->GetParam (mBaseParamIdx + kOnThreshold )->Value ();
56+ auto offThreshold =
57+ mApiProvider ->GetParam (mBaseParamIdx + kOffThreshold )->Value ();
58+ auto floorValue =
59+ mApiProvider ->GetParam (mBaseParamIdx + kSilenceThreshold )->Value ();
60+ auto debounceTime =
61+ mApiProvider ->GetParam (mBaseParamIdx + kDebounce )->Value ();
62+ auto hiPassFreq =
63+ mApiProvider ->GetParam (mBaseParamIdx + kHiPassFreq )->Value ();
64+
65+ mParams .template set <0 >(std::move (sourceBuffer), nullptr );
66+ mParams .template set <1 >(std::move (LongT::type (0 )), nullptr );
67+ mParams .template set <2 >(std::move (LongT::type (-1 )), nullptr );
68+ mParams .template set <3 >(std::move (LongT::type (0 )), nullptr );
69+ mParams .template set <4 >(std::move (LongT::type (-1 )), nullptr );
70+ mParams .template set <5 >(std::move (slicesOutputBuffer), nullptr );
71+ mParams .template set <6 >(std::move (LongT::type (fastRampUpTime)), nullptr );
72+ mParams .template set <7 >(std::move (LongT::type (fastRampDownTime)), nullptr );
73+ mParams .template set <8 >(std::move (LongT::type (slowRampUpTime)), nullptr );
74+ mParams .template set <9 >(std::move (LongT::type (slowRampDownTime)), nullptr );
75+ mParams .template set <10 >(std::move (FloatT::type (onThreshold)), nullptr );
76+ mParams .template set <11 >(std::move (FloatT::type (offThreshold)), nullptr );
77+ mParams .template set <12 >(std::move (FloatT::type (floorValue)), nullptr );
78+ mParams .template set <13 >(std::move (LongT::type (debounceTime)), nullptr );
79+ mParams .template set <14 >(std::move (FloatT::type (hiPassFreq)), nullptr );
80+
81+ mClient = NRTThreadedAmpSliceClient (mParams , mContext );
82+ mClient .setSynchronous (false );
83+ mClient .enqueue (mParams );
84+ Result result = mClient .process ();
85+ return result.ok ();
86+ }
87+
88+ const char *AmpSliceAlgorithm::GetName () const { return " Amp Slice" ; }
89+
90+ int AmpSliceAlgorithm::GetNumAlgorithmParams () const { return kNumParams ; }
91+
92+ BufferT::type &AmpSliceAlgorithm::GetSlicesBuffer () {
93+ return mParams .template get <5 >();
94+ }
0 commit comments