Skip to content

Commit 1c23e75

Browse files
committed
- Changed saving / loading state to doubles instead of floats
- Updated parameter management system to use doubles
1 parent 172860d commit 1c23e75

File tree

7 files changed

+65
-65
lines changed

7 files changed

+65
-65
lines changed

resource/editor.uidesc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@
447447
"text-inset": "0, 0",
448448
"text-rotation": "0",
449449
"text-shadow-offset": "1, 1",
450-
"title": "v1.0.2",
450+
"title": "v1.0.3",
451451
"transparent": "false",
452452
"uidesc-label": "Title",
453453
"value-precision": "2",

source/AllpassFilter.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ class AllpassFilter {
6363
/// <param name="freqHz"></param>
6464
/// <param name="q"> Normalised 0 to 1, internally clamped</param>
6565

66-
static void calculateCoefficients(float freq_hz, float q, int sample_rate, AllpassInfo& State) {
66+
static void calculateCoefficients(double freq_hz, double q, int sample_rate, AllpassInfo& State) {
6767

68-
float q_actual = 0.5f + (q * 9.5f);
68+
double q_actual = 0.5f + (q * 9.5f);
6969

7070
// Calculate SVF coefficients, and set as targets
7171
State.g_target = ((E_PI * freq_hz) / (double)sample_rate);
@@ -74,8 +74,8 @@ class AllpassFilter {
7474
State.k_target = 1.0 / (2.0 * q_actual);
7575

7676
//Smooth
77-
float diff_k = State.k_target - State.k;
78-
float diff_g = State.g_target - State.g;
77+
double diff_k = State.k_target - State.k;
78+
double diff_g = State.g_target - State.g;
7979

8080
State.k += diff_k * State.smoothFactor;
8181
State.g += diff_g * State.smoothFactor;

source/CirculateEffect.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class CirculateEffect {
9595
AllpassFilter::calculateCoefficients(mCenterHz, mFocus, Setup.sampleRate, FilterState);
9696

9797
// Scale feedback parameter,
98-
float feedback = pParams->Feedback.getSampleAccurateValue(s);
98+
double feedback = pParams->Feedback.getSampleAccurateValue(s);
9999

100100
// Snap feedback to allow easy switching off
101101
if (abs(feedback - 0.5) < 0.1) {
@@ -144,14 +144,14 @@ class CirculateEffect {
144144
AllpassFilter::AllpassInfo* pState = nullptr;
145145
HELPERS::SetupInfo Setup;
146146

147-
float mCenterHz = 0;
148-
float mFocus = 0;
149-
float mNoteNumHz = 0;
150-
float mNoteOffsetHz = 0;
147+
double mCenterHz = 0;
148+
double mFocus = 0;
149+
double mNoteNumHz = 0;
150+
double mNoteOffsetHz = 0;
151151
int mNumActiveStages = 32;
152152

153153
bool mUseHzControl = true;
154-
float maxAllowedFreq = 0;
154+
double maxAllowedFreq = 0;
155155
float currentSample = 0;
156156

157157
HELPERS::ValueSmoother NoteControlSmoother;
@@ -162,8 +162,8 @@ class CirculateEffect {
162162
/// </summary>
163163
/// <param name="s"> sample index</param>
164164
/// <returns></returns>
165-
float updateFrequency(int s) {
166-
float freqHz = pParams->Center.getSampleAccurateValue(s);
165+
double updateFrequency(int s) {
166+
double freqHz = pParams->Center.getSampleAccurateValue(s);
167167
if (freqHz < 0.0) {
168168
freqHz = 0.0;
169169
};

source/CirculateHelpers.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace HELPERS {
2525

2626
typedef std::vector<float> AudioBuffer;
2727

28-
inline float noteNumToHz(int note_num) {
28+
inline double noteNumToHz(int note_num) {
2929
return 440.0 * pow(2.0, (note_num - 69.0) / 12.0);
3030
}
3131

@@ -40,8 +40,8 @@ namespace HELPERS {
4040
/// </summary>
4141
class ValueSmoother {
4242
public:
43-
float getSmoothedValue(float target) {
44-
float difference = target - lastValue;
43+
double getSmoothedValue(double target) {
44+
double difference = target - lastValue;
4545
// Snap to target if the difference is very small
4646
if (std::abs(difference) < 1e-9f) {
4747
lastValue = target;
@@ -51,7 +51,7 @@ namespace HELPERS {
5151
}
5252
return lastValue;
5353
}
54-
void setSmoothTime(float time_ms, int sample_rate) {
54+
void setSmoothTime(double time_ms, int sample_rate) {
5555
if (time_ms > 0) {
5656
smoothFactor = 1.0f - expf(-2.0f * 3.141592653589f / (time_ms * 0.001f * sample_rate));
5757
}
@@ -64,8 +64,8 @@ namespace HELPERS {
6464
}
6565

6666
private:
67-
float lastValue = 0;
68-
float smoothFactor = 0.005;
67+
double lastValue = 0;
68+
double smoothFactor = 0.005;
6969
};
7070

7171

source/CirculateParameters.h

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ namespace CIRCULATE_PARAMS {
124124
/// </summary>
125125
class ParamUnit {
126126
public:
127-
ParamUnit(int paramID = 0, float default_value = 0, bool sampleAccurate = false, int hostBlockSize = 0) {
127+
ParamUnit(int paramID = 0, double default_value = 0, bool sampleAccurate = false, int hostBlockSize = 0) {
128128
value = default_value;
129129
id = paramID;
130130
smoothedValue = default_value;
@@ -139,7 +139,7 @@ namespace CIRCULATE_PARAMS {
139139
/// Set parameters value and set dirty
140140
/// </summary>
141141
/// <param name="value"></param>
142-
void set(float value) {
142+
void set(double value) {
143143
this->value = value;
144144
setDirty();
145145
}
@@ -148,11 +148,11 @@ namespace CIRCULATE_PARAMS {
148148
/// smoothed
149149
/// </summary>
150150
/// <returns></returns>
151-
float getSmoothed() {
151+
double getSmoothed() {
152152

153-
float difference = value - smoothedValue;
153+
double difference = value - smoothedValue;
154154

155-
if (std::abs(difference) < 0.001f)
155+
if (std::abs(difference) < 0.01f)
156156
{
157157
smoothedValue = value;
158158
}
@@ -164,15 +164,15 @@ namespace CIRCULATE_PARAMS {
164164

165165
return smoothedValue;
166166
}
167-
float getSampleAccurateSmoothed(int index) {
167+
double getSampleAccurateSmoothed(int index) {
168168
value = BlockValues[index];
169169

170170
return getSmoothed();
171171
}
172172
int getID() const {
173173
return id;
174174
}
175-
void setSmoothTime(float timeInMs, float sampleRate) {
175+
void setSmoothTime(double timeInMs, int sampleRate) {
176176
if (timeInMs > 0) {
177177
smoothFactor = 1.0f - expf(-2.0f * 3.141592653589f / (timeInMs * 0.001f * sampleRate));
178178
}
@@ -181,19 +181,19 @@ namespace CIRCULATE_PARAMS {
181181
wantsSmoothing = false;
182182
}
183183
}
184-
float getSampleAccurateValue(int s) {
184+
double getSampleAccurateValue(int s) {
185185
return BlockValues[s];
186186
}
187187

188188
/// <summary>
189189
/// Get unsmoothed value and set clean
190190
/// </summary>
191191
/// <returns></returns>
192-
float getExplicit() {
192+
double getExplicit() {
193193

194194
return value;
195195
}
196-
float getLastValue() const {
196+
double getLastValue() const {
197197

198198
if (BlockValues.empty()) {
199199
return value;
@@ -218,7 +218,7 @@ namespace CIRCULATE_PARAMS {
218218
/// last result from the previous block
219219
/// </summary>
220220
void fillWithLastKnown() {
221-
float lastValue = getLastValue();
221+
double lastValue = getLastValue();
222222

223223
for (int i = 0; i < blockSize; i++) {
224224

@@ -231,7 +231,7 @@ namespace CIRCULATE_PARAMS {
231231
/// Fill the parameter block with an arbitrary value (0...1)
232232
/// </summary>
233233
/// <param name="value"></param>
234-
void fillWith(float value) {
234+
void fillWith(double value) {
235235

236236
for (int i = 0; i < blockSize; i++) {
237237

@@ -240,17 +240,16 @@ namespace CIRCULATE_PARAMS {
240240
}
241241

242242
}
243-
float smoothFactor = 0.005;
244-
std::vector<float> BlockValues;
243+
double smoothFactor = 0.005;
244+
std::vector<double> BlockValues;
245245
bool wantsSmoothing = true;
246246
private:
247-
float value = 0;
248-
float smoothedValue = 0;
247+
double value = 0;
248+
double smoothedValue = 0;
249249
int id = 0;
250250
bool dirty = false;
251251
int blockSize = 0;
252252

253-
254253
};
255254

256255
/// <summary>

source/controller.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ tresult PLUGIN_API CirculateController::setComponentState (IBStream* state)
5050

5151
IBStreamer streamer(state, kLittleEndian);
5252

53-
float depth, center, note, focus, type, offset, bypass, feed;
53+
double depth, center, note, focus, type, offset, bypass, feed;
5454

5555
// Read values in the SAME ORDER the processor wrote them
56-
if (streamer.readFloat(depth) == false) return kResultFalse;
57-
if (streamer.readFloat(center) == false) return kResultFalse;
58-
if (streamer.readFloat(note) == false) return kResultFalse;
59-
if (streamer.readFloat(focus) == false) return kResultFalse;
60-
if (streamer.readFloat(type) == false) return kResultFalse;
61-
if (streamer.readFloat(offset) == false) return kResultFalse;
62-
if (streamer.readFloat(bypass) == false) return kResultFalse;
63-
if (streamer.readFloat(feed) == false) return kResultFalse;
64-
56+
if (streamer.readDouble(depth) == false) return kResultFalse;
57+
if (streamer.readDouble(center) == false) return kResultFalse;
58+
if (streamer.readDouble(note) == false) return kResultFalse;
59+
if (streamer.readDouble(focus) == false) return kResultFalse;
60+
if (streamer.readDouble(type) == false) return kResultFalse;
61+
if (streamer.readDouble(offset) == false) return kResultFalse;
62+
if (streamer.readDouble(bypass) == false) return kResultFalse;
63+
if (streamer.readDouble(feed) == false) return kResultFalse;
64+
6565
// Update the controller's parameter objects.
6666
setParamNormalized(CIRCULATE_PARAMS::kDepth, depth);
6767
setParamNormalized(CIRCULATE_PARAMS::kCenter, center);

source/processor.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void CirculateProcessor::getParamChangesThisBlock(Steinberg::Vst::IParamValueQue
8383
return;
8484
}
8585
CIRCULATE_PARAMS::ParamUnit* Param = Params->getParameter(paramID);
86-
float* ParamValues = nullptr;
86+
double* ParamValues = nullptr;
8787
if (Param) {
8888
ParamValues = Param->BlockValues.data();
8989
}
@@ -290,17 +290,17 @@ tresult PLUGIN_API CirculateProcessor::setState (IBStream* state)
290290
IBStreamer streamer (state, kLittleEndian);
291291

292292

293-
float depth, center, note, focus, type, offset, bypass, feed;
293+
double depth, center, note, focus, type, offset, bypass, feed;
294294

295295
// Same order they were written in getState
296-
if (streamer.readFloat(depth) == false) return kResultFalse;
297-
if (streamer.readFloat(center) == false) return kResultFalse;
298-
if (streamer.readFloat(note) == false) return kResultFalse;
299-
if (streamer.readFloat(focus) == false) return kResultFalse;
300-
if (streamer.readFloat(type) == false) return kResultFalse;
301-
if (streamer.readFloat(offset) == false) return kResultFalse;
302-
if (streamer.readFloat(bypass) == false) return kResultFalse;
303-
if (streamer.readFloat(feed) == false) return kResultFalse;
296+
if (streamer.readDouble(depth) == false) return kResultFalse;
297+
if (streamer.readDouble(center) == false) return kResultFalse;
298+
if (streamer.readDouble(note) == false) return kResultFalse;
299+
if (streamer.readDouble(focus) == false) return kResultFalse;
300+
if (streamer.readDouble(type) == false) return kResultFalse;
301+
if (streamer.readDouble(offset) == false) return kResultFalse;
302+
if (streamer.readDouble(bypass) == false) return kResultFalse;
303+
if (streamer.readDouble(feed) == false) return kResultFalse;
304304

305305
// Fill sample accurate parameter buffers with loaded value
306306
Params->Depth.fillWith(depth);
@@ -310,6 +310,7 @@ tresult PLUGIN_API CirculateProcessor::setState (IBStream* state)
310310
Params->CenterType.fillWith(type);
311311
Params->NoteOffset.fillWith(offset);
312312
Params->Feedback.fillWith(feed);
313+
313314

314315
if (bypass > 0.5) {
315316
isBypassed = true;
@@ -337,15 +338,15 @@ tresult PLUGIN_API CirculateProcessor::getState (IBStream* state)
337338
}
338339

339340
IBStreamer streamer (state, kLittleEndian);
340-
341-
streamer.writeFloat(Params->Depth.getLastValue());
342-
streamer.writeFloat(Params->Center.getLastValue());
343-
streamer.writeFloat(Params->Note.getLastValue());
344-
streamer.writeFloat(Params->Focus.getLastValue());
345-
streamer.writeFloat(Params->CenterType.getLastValue());
346-
streamer.writeFloat(Params->NoteOffset.getLastValue());
347-
streamer.writeFloat(isBypassed);
348-
streamer.writeFloat(Params->Feedback.getLastValue());
341+
342+
streamer.writeDouble(Params->Depth.getLastValue());
343+
streamer.writeDouble(Params->Center.getLastValue());
344+
streamer.writeDouble(Params->Note.getLastValue());
345+
streamer.writeDouble(Params->Focus.getLastValue());
346+
streamer.writeDouble(Params->CenterType.getLastValue());
347+
streamer.writeDouble(Params->NoteOffset.getLastValue());
348+
streamer.writeDouble(isBypassed);
349+
streamer.writeDouble(Params->Feedback.getLastValue());
349350

350351
return kResultOk;
351352
}

0 commit comments

Comments
 (0)