Skip to content

Commit 59c4829

Browse files
committed
add ampslice
1 parent 8a6a369 commit 59c4829

File tree

6 files changed

+178
-42
lines changed

6 files changed

+178
-42
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
#include "flucoma/clients/rt/AmpSliceClient.hpp"
3+
#include "SlicingAlgorithm.h"
4+
5+
class AmpSliceAlgorithm
6+
: public SlicingAlgorithm<fluid::client::NRTThreadedAmpSliceClient> {
7+
public:
8+
enum Params {
9+
kFastRampUpTime = 0,
10+
kFastRampDownTime,
11+
kSlowRampUpTime,
12+
kSlowRampDownTime,
13+
kOnThreshold,
14+
kOffThreshold,
15+
kSilenceThreshold,
16+
kDebounce,
17+
kHiPassFreq,
18+
kNumParams
19+
};
20+
21+
AmpSliceAlgorithm(ReacomaExtension *apiProvider);
22+
~AmpSliceAlgorithm() override;
23+
24+
const char *GetName() const override;
25+
void RegisterParameters() override;
26+
int GetNumAlgorithmParams() const override;
27+
28+
protected:
29+
BufferT::type &GetSlicesBuffer() override;
30+
bool DoProcess(InputBufferT::type &sourceBuffer, int numChannels,
31+
int frameCount, int sampleRate) override;
32+
};

ReacomaExtension/Algorithms/ProcessingJob.cpp

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "TransientSliceAlgorithm.h"
88
#include "TransientAlgorithm.h"
99
#include "NoveltyFeatureAlgorithm.h"
10+
#include "AmpSliceAlgorithm.h"
1011
#include <memory>
1112

1213
ProcessingJob::ProcessingJob(std::unique_ptr<IAlgorithm> algorithm,
@@ -42,38 +43,38 @@ ProcessingJob::Create(ReacomaExtension::EAlgorithmChoice algoChoice,
4243
const IAlgorithm *prototypeAlgorithm = nullptr;
4344

4445
switch (algoChoice) {
45-
case ReacomaExtension::kNoveltySlice:
46-
algorithm = std::make_unique<NoveltySliceAlgorithm>(provider);
47-
prototypeAlgorithm = provider->GetNoveltySliceAlgorithm();
48-
break;
49-
case ReacomaExtension::kHPSS:
50-
algorithm = std::make_unique<HPSSAlgorithm>(provider);
51-
prototypeAlgorithm = provider->GetHPSSAlgorithm();
52-
break;
53-
case ReacomaExtension::kNMF:
54-
algorithm = std::make_unique<NMFAlgorithm>(provider);
55-
prototypeAlgorithm = provider->GetNMFAlgorithm();
56-
break;
57-
case ReacomaExtension::kOnsetSlice:
58-
algorithm = std::make_unique<OnsetSliceAlgorithm>(provider);
59-
prototypeAlgorithm = provider->GetOnsetSliceAlgorithm();
60-
break;
61-
case ReacomaExtension::kTransients:
62-
algorithm = std::make_unique<TransientAlgorithm>(provider);
63-
prototypeAlgorithm = provider->GetTransientsAlgorithm();
64-
break;
65-
case ReacomaExtension::kTransientSlice:
66-
algorithm = std::make_unique<TransientSliceAlgorithm>(provider);
67-
prototypeAlgorithm = provider->GetTransientSliceAlgorithm();
68-
break;
69-
case ReacomaExtension::kAmpGate:
70-
algorithm = std::make_unique<AmpGateAlgorithm>(provider);
71-
prototypeAlgorithm = provider->GetAmpGateAlgorithm();
72-
break;
73-
case ReacomaExtension::kNoveltyFeature:
74-
algorithm = std::make_unique<NoveltyFeatureAlgorithm>(provider);
75-
prototypeAlgorithm = provider->GetNoveltyFeatureAlgorithm();
76-
break;
46+
case ReacomaExtension::kNoveltySlice:
47+
algorithm = std::make_unique<NoveltySliceAlgorithm>(provider);
48+
prototypeAlgorithm = provider->GetNoveltySliceAlgorithm();
49+
break;
50+
case ReacomaExtension::kHPSS:
51+
algorithm = std::make_unique<HPSSAlgorithm>(provider);
52+
prototypeAlgorithm = provider->GetHPSSAlgorithm();
53+
break;
54+
case ReacomaExtension::kNMF:
55+
algorithm = std::make_unique<NMFAlgorithm>(provider);
56+
prototypeAlgorithm = provider->GetNMFAlgorithm();
57+
break;
58+
case ReacomaExtension::kOnsetSlice:
59+
algorithm = std::make_unique<OnsetSliceAlgorithm>(provider);
60+
prototypeAlgorithm = provider->GetOnsetSliceAlgorithm();
61+
break;
62+
case ReacomaExtension::kTransients:
63+
algorithm = std::make_unique<TransientAlgorithm>(provider);
64+
prototypeAlgorithm = provider->GetTransientsAlgorithm();
65+
break;
66+
case ReacomaExtension::kTransientSlice:
67+
algorithm = std::make_unique<TransientSliceAlgorithm>(provider);
68+
prototypeAlgorithm = provider->GetTransientSliceAlgorithm();
69+
break;
70+
case ReacomaExtension::kAmpGate:
71+
algorithm = std::make_unique<AmpGateAlgorithm>(provider);
72+
prototypeAlgorithm = provider->GetAmpGateAlgorithm();
73+
break;
74+
case ReacomaExtension::kAmpSlice:
75+
algorithm = std::make_unique<AmpSliceAlgorithm>(provider);
76+
prototypeAlgorithm = provider->GetAmpSliceAlgorithm();
77+
break;
7778
}
7879

7980
if (algorithm && prototypeAlgorithm) {

ReacomaExtension/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ set(REACOMA_SOURCES
162162
"Algorithms/TransientAlgorithm.h"
163163
"Algorithms/TransientSliceAlgorithm.cpp"
164164
"Algorithms/TransientSliceAlgorithm.h"
165+
"Algorithms/AmpSliceAlgorithm.cpp"
166+
"Algorithms/AmpSliceAlgorithm.h"
165167

166168
# UI Components
167169
"Components/ReacomaButton.cpp"

ReacomaExtension/ReacomaExtension.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "Algorithms/OnsetSliceAlgorithm.h"
2424
#include "Algorithms/AmpGateAlgorithm.h"
2525
#include "Algorithms/NoveltyFeatureAlgorithm.h"
26+
#include "Algorithms/AmpSliceAlgorithm.h"
2627

2728
template <ReacomaExtension::Mode M> struct ProcessAction {
2829
void operator()(IControl *pCaller) {
@@ -86,9 +87,9 @@ ReacomaExtension::ReacomaExtension(reaper_plugin_info_t *pRec)
8687
true, &mGUIToggle);
8788

8889
AddParam();
89-
auto parameterLabels = {
90-
"Novelty Slice", "Onset Slice", "Transient Slice", "HPSS",
91-
"NMF", "Transients", "Amp Gate", "Novelty Feature"};
90+
auto parameterLabels = {"Novelty Slice", "Amp Slice", "Amp Gate",
91+
"Onset Slice", "Transient Slice", "HPSS",
92+
"NMF", "Transients"};
9293
GetParam(kParamAlgorithmChoice)
9394
->InitEnum("Algorithm", kNoveltySlice, parameterLabels);
9495

@@ -113,8 +114,8 @@ ReacomaExtension::ReacomaExtension(reaper_plugin_info_t *pRec)
113114
mAmpGateAlgorithm = std::make_unique<AmpGateAlgorithm>(this);
114115
mAmpGateAlgorithm->RegisterParameters();
115116

116-
mNoveltyFeatureAlgorithm = std::make_unique<NoveltyFeatureAlgorithm>(this);
117-
mNoveltyFeatureAlgorithm->RegisterParameters();
117+
mAmpSliceAlgorithm = std::make_unique<AmpSliceAlgorithm>(this);
118+
mAmpSliceAlgorithm->RegisterParameters();
118119

119120
mAllAlgorithms.push_back(mNoveltyAlgorithm.get());
120121
mAllAlgorithms.push_back(mHPSSAlgorithm.get());
@@ -124,8 +125,9 @@ ReacomaExtension::ReacomaExtension(reaper_plugin_info_t *pRec)
124125
mAllAlgorithms.push_back(mTransientSliceAlgorithm.get());
125126
mAllAlgorithms.push_back(mAmpGateAlgorithm.get());
126127
mAllAlgorithms.push_back(mNoveltyFeatureAlgorithm.get());
128+
mAllAlgorithms.push_back(mAmpSliceAlgorithm.get());
127129

128-
SetAlgorithmChoice(kNoveltyFeature, false);
130+
SetAlgorithmChoice(kNoveltySlice, false);
129131

130132
mLayoutFunc = [&](IGraphics *pGraphics) { SetupUI(pGraphics); };
131133
}
@@ -546,8 +548,8 @@ void ReacomaExtension::SetAlgorithmChoice(EAlgorithmChoice choice,
546548
case kAmpGate:
547549
mCurrentActiveAlgorithmPtr = mAmpGateAlgorithm.get();
548550
break;
549-
case kNoveltyFeature:
550-
mCurrentActiveAlgorithmPtr = mNoveltyFeatureAlgorithm.get();
551+
case kAmpSlice:
552+
mCurrentActiveAlgorithmPtr = mAmpSliceAlgorithm.get();
551553
break;
552554
default:
553555
mCurrentActiveAlgorithmPtr = nullptr;

ReacomaExtension/ReacomaExtension.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class NoveltySliceAlgorithm;
3333
class OnsetSliceAlgorithm;
3434
class AmpGateAlgorithm;
3535
class NoveltyFeatureAlgorithm;
36+
class AmpSliceAlgorithm;
3637
struct ReacomaTheme;
3738

3839
class IAlgorithm;
@@ -53,13 +54,13 @@ class ReacomaExtension : public ReaperExtBase {
5354

5455
enum EAlgorithmChoice {
5556
kNoveltySlice = 0,
57+
kAmpSlice,
58+
kAmpGate,
5659
kOnsetSlice,
5760
kTransientSlice,
5861
kHPSS,
5962
kNMF,
6063
kTransients,
61-
kAmpGate,
62-
kNoveltyFeature,
6364
kNumAlgorithmChoices
6465
};
6566

@@ -91,6 +92,9 @@ class ReacomaExtension : public ReaperExtBase {
9192
NoveltyFeatureAlgorithm *GetNoveltyFeatureAlgorithm() const {
9293
return mNoveltyFeatureAlgorithm.get();
9394
}
95+
AmpSliceAlgorithm *GetAmpSliceAlgorithm() const {
96+
return mAmpSliceAlgorithm.get();
97+
}
9498

9599
private:
96100
bool mUIRelayoutIsNeeded = false;
@@ -105,6 +109,7 @@ class ReacomaExtension : public ReaperExtBase {
105109
std::unique_ptr<TransientSliceAlgorithm> mTransientSliceAlgorithm;
106110
std::unique_ptr<AmpGateAlgorithm> mAmpGateAlgorithm;
107111
std::unique_ptr<NoveltyFeatureAlgorithm> mNoveltyFeatureAlgorithm;
112+
std::unique_ptr<AmpSliceAlgorithm> mAmpSliceAlgorithm;
108113
std::vector<IAlgorithm *> mAllAlgorithms;
109114

110115
void OnParamChangeUI(int paramIdx, EParamSource source) override;

0 commit comments

Comments
 (0)