This repository was archived by the owner on Aug 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginProcessor.cpp
More file actions
200 lines (163 loc) · 7.51 KB
/
Copy pathPluginProcessor.cpp
File metadata and controls
200 lines (163 loc) · 7.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include "PluginProcessor.h"
#include "PluginEditor.h"
#include "LPCeffect.cpp"
//==============================================================================
MyAudioProcessor::MyAudioProcessor() :
AudioProcessor (BusesProperties()
.withInput("Input", juce::AudioChannelSet::stereo(), true)
.withInput("Sidechain", juce::AudioChannelSet::stereo(), true)
.withOutput ("Output", juce::AudioChannelSet::stereo(), true)
),
treeState{*this, nullptr, "PARAMETERS", createParameterLayout()},
modelOrder{treeState.getRawParameterValue("modelOrder")},
passthrough{treeState.getRawParameterValue("passthrough")},
shiftVoice1{treeState.getRawParameterValue("shiftVoice1")},
shiftVoice2{treeState.getRawParameterValue("shiftVoice2")},
shiftVoice3{treeState.getRawParameterValue("shiftVoice3")},
monostereo{treeState.getRawParameterValue("monostereo")},
enableLPC{treeState.getRawParameterValue("enableLPC")}
{ }
MyAudioProcessor::~MyAudioProcessor() { }
//defining parameters of the plugin
juce::AudioProcessorValueTreeState::ParameterLayout MyAudioProcessor::createParameterLayout() {
using namespace juce;
AudioProcessorValueTreeState::ParameterLayout layout;
layout.add(std::make_unique<AudioParameterFloat>("modelOrder", "modelOrder",
NormalisableRange<float>(6.f, 76.f, 1.f, 1.f), 76.f));
layout.add(std::make_unique<AudioParameterFloat>("passthrough", "passthrough",
NormalisableRange<float>(0.f, 1.f, 0.1f, 1.f), 1.f));
layout.add(std::make_unique<AudioParameterFloat>("enableLPC", "enableLPC",
NormalisableRange<float>(0.f, 1.f, 1.f, 1.f), 0.f));
layout.add(std::make_unique<AudioParameterFloat>("shiftVoice1", "shiftVoice1",
NormalisableRange<float>(0.6f, 2.f, 0.01f, 0.55f), 1.f));
layout.add(std::make_unique<AudioParameterFloat>("shiftVoice2", "shiftVoice2",
NormalisableRange<float>(0.6f, 2.f, 0.01f, 0.55f), 1.f));
layout.add(std::make_unique<AudioParameterFloat>("shiftVoice3", "shiftVoice3",
NormalisableRange<float>(0.6f, 2.f, 0.01f, 0.55f), 1.f));
layout.add(std::make_unique<AudioParameterFloat>("monostereo", "monostereo",
NormalisableRange<float>(0.f, 1.f, 0.01f, 1.f), 0.5f));
return layout;
}
//==============================================================================
const juce::String MyAudioProcessor::getName() const {
return JucePlugin_Name;
}
bool MyAudioProcessor::acceptsMidi() const {
return false;
}
bool MyAudioProcessor::producesMidi() const {
return false;
}
bool MyAudioProcessor::isMidiEffect() const {
return false;
}
double MyAudioProcessor::getTailLengthSeconds() const {
return 0.0;
}
int MyAudioProcessor::getNumPrograms() {
return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs, so this should be at least 1, even if you're not really implementing programs.
}
int MyAudioProcessor::getCurrentProgram() {
return 0;
}
void MyAudioProcessor::setCurrentProgram (int index) {
juce::ignoreUnused (index);
}
const juce::String MyAudioProcessor::getProgramName (int index) {
juce::ignoreUnused (index);
return {};
}
void MyAudioProcessor::changeProgramName (int index, const juce::String& newName) {
juce::ignoreUnused (index, newName);
}
void MyAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock) {
setLatencySamples(lpcEffect[0].getLatency());
juce::ignoreUnused (sampleRate, samplesPerBlock);
juce::dsp::ProcessSpec spec{};
spec.maximumBlockSize = samplesPerBlock;
spec.numChannels = 2;
spec.sampleRate = sampleRate;
}
void MyAudioProcessor::releaseResources() {
}
bool MyAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const {
if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono()
&& layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo())
return false;
if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
return false;
return true;
}
void MyAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages) {
juce::ignoreUnused (midiMessages);
juce::ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear (i, 0, buffer.getNumSamples());
//=================================================================================
// pointers to acquite write access to audio busses and their channels
auto mainInput = getBusBuffer (buffer, true, 0);
auto sideChain = getBusBuffer (buffer, true, 1);
auto* channelL = mainInput.getWritePointer(0);
auto* channelR = mainInput.getWritePointer(1);
auto* sideChainL = sideChain.getReadPointer(0);
auto* sideChainR = sideChain.getReadPointer(1);
// float* sideChainL;
// float* sideChainR;
// disable processing if no input
bool isSilent = true;
for (int sample = 0; sample < buffer.getNumSamples(); ++sample) {
if (std::fabs(channelL[sample]) > 0.0001f || std::fabs(channelR[sample]) > 0.0001f) {
isSilent = false;
break;
}
}
if (isSilent)
return;
for (int sample = 0; sample < buffer.getNumSamples(); ++sample) {
float sampleL = channelL[sample];
float sampleR = channelR[sample];
// providing samples to effect chain and getting output in real-time
sampleL = lpcEffect[0].sendSample(sampleL, sideChainL[sample], *modelOrder,
*shiftVoice1, *shiftVoice2, *shiftVoice3, *enableLPC > 0.99, *passthrough);
sampleR = lpcEffect[1].sendSample(sampleR, sideChainR[sample], *modelOrder,
*shiftVoice1, *shiftVoice2, *shiftVoice3, *enableLPC > 0.99, *passthrough);
// midside processing for stereo limiting
float width = *monostereo;
auto sideNew = width * 0.5 * (sampleL - sampleR);
auto midNew = (2 - width) * 0.5 * (sampleL + sampleR);
sampleL = static_cast<float>(midNew + sideNew);
sampleR = static_cast<float>(midNew - sideNew);
channelL[sample] = sampleL;
channelR[sample] = sampleR;
}
}
//==============================================================================
bool MyAudioProcessor::hasEditor() const {
return true; // false if you choose to not supply an editor
}
juce::AudioProcessorEditor* MyAudioProcessor::createEditor() {
return new MyAudioProcessorEditor (*this);
//generic UI:
// return new juce::GenericAudioProcessorEditor(*this);
}
//==============================================================================
// storing parameters in memory block
// destination data from DAW
void MyAudioProcessor::getStateInformation (juce::MemoryBlock& destData) {
juce::ignoreUnused (destData);
juce::MemoryOutputStream stream(destData, false);
treeState.state.writeToStream(stream);
}
//when plugin is opened - restore saved parameters
void MyAudioProcessor::setStateInformation (const void* data, int sizeInBytes) {
juce::ignoreUnused (data, sizeInBytes);
juce::ValueTree tree = juce::ValueTree::readFromData(data, size_t(sizeInBytes));
treeState.state = tree;
}
//==============================================================================
// This creates new instances of the plugin..
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter() {
return new MyAudioProcessor();
}