Skip to content

Commit 71bb686

Browse files
authored
Merge pull request #470 from ASleepyCat/laser-fx-fix
Clamp laser FX parameters, fix FX parameters being parsed incorrectly
2 parents df7b3b5 + 8447b54 commit 71bb686

File tree

6 files changed

+37
-33
lines changed

6 files changed

+37
-33
lines changed

Audio/include/Audio/DSP.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class BQFDSP : public DSP
4444
// Delayed samples
4545
static const uint32 order = 2;
4646
// FIR Delay buffers
47-
float zb[2][order];
47+
float zb[2][order]{};
4848
// IIR Delay buffers
49-
float za[2][order];
49+
float za[2][order]{};
5050
};
5151

5252
// Combinded Low/High-pass and Peaking filter
@@ -117,7 +117,7 @@ class GateDSP : public DSP
117117
uint32 m_length = 0;
118118
uint32 m_fadeIn = 0; // Fade In mark
119119
uint32 m_fadeOut = 0; // Fade Out mark
120-
uint32 m_halfway; // Halfway mark
120+
uint32 m_halfway{}; // Halfway mark
121121
uint32 m_currentSample = 0;
122122
};
123123

@@ -177,7 +177,7 @@ class WobbleDSP : public BQFDSP
177177
virtual const char *GetName() const { return "WobbleDSP"; }
178178

179179
private:
180-
uint32 m_length;
180+
uint32 m_length{};
181181
uint32 m_currentSample = 0;
182182
};
183183

@@ -269,7 +269,7 @@ class SidechainDSP : public DSP
269269
// Volume multiplier for the sidechaing
270270
float amount = 0.25f;
271271

272-
Interpolation::CubicBezier curve;
272+
Interpolation::CubicBezier curve{};
273273

274274
virtual void Process(float *out, uint32 numSamples);
275275
virtual const char *GetName() const { return "SidechainDSP"; }

Audio/src/DSP.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include "DSP.hpp"
33
#include "AudioOutput.hpp"
44
#include "Audio_Impl.hpp"
5-
#include <Shared/Interpolation.hpp>
65

76
void PanDSP::Process(float *out, uint32 numSamples)
87
{
@@ -217,6 +216,7 @@ void GateDSP::SetLength(double length)
217216
}
218217
void GateDSP::SetGating(float gating)
219218
{
219+
gating = Math::Clamp(gating, 0.f, 1.f);
220220
float flength = (float)m_length;
221221
m_gating = gating;
222222
m_halfway = (uint32)(flength * gating);
@@ -335,6 +335,7 @@ void RetriggerDSP::SetResetDuration(uint32 resetDuration)
335335
}
336336
void RetriggerDSP::SetGating(float gating)
337337
{
338+
gating = Math::Clamp(gating, 0.f, 1.f);
338339
m_gating = gating;
339340
m_gateLength = (uint32)((float)m_length * gating);
340341
}
@@ -675,12 +676,8 @@ class PitchShiftDSP_Impl
675676
Vector<float> m_receiveBuffer;
676677

677678
public:
678-
PitchShiftDSP_Impl()
679-
{
680-
}
681-
~PitchShiftDSP_Impl()
682-
{
683-
}
679+
PitchShiftDSP_Impl() = default;
680+
~PitchShiftDSP_Impl() = default;
684681
void Init(uint32 sampleRate)
685682
{
686683
m_soundtouch.setChannels(2);

Beatmap/src/BeatmapFromKSH.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,7 @@ struct MultiParamRange
198198
static MultiParam ParseParam(const String &in)
199199
{
200200
MultiParam ret;
201-
if (in.find('.') != -1)
202-
{
203-
ret.type = MultiParam::Float;
204-
sscanf(*in, "%f", &ret.fval);
205-
}
206-
else if (in.find('/') != -1)
201+
if (in.find('/') != -1)
207202
{
208203
ret.type = MultiParam::Float;
209204
String a, b;
@@ -222,6 +217,11 @@ static MultiParam ParseParam(const String &in)
222217
sscanf(*in, "%i", &percentage);
223218
ret.fval = percentage / 100.0;
224219
}
220+
else if (in.find('.') != -1)
221+
{
222+
ret.type = MultiParam::Float;
223+
sscanf(*in, "%f", &ret.fval);
224+
}
225225
else
226226
{
227227
ret.type = MultiParam::Int;
@@ -236,7 +236,7 @@ AudioEffect ParseCustomEffect(const KShootEffectDefinition &def, Vector<String>
236236
bool typeSet = false;
237237

238238
Map<String, MultiParamRange> params;
239-
for (auto s : def.parameters)
239+
for (const auto& s : def.parameters)
240240
{
241241
// This one is easy
242242
if (s.first == "type")

Main/include/Audio/AudioPlayback.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,6 @@ class AudioPlayback : Unique
122122
class DSP *m_buttonDSPs[2] = {nullptr};
123123
HoldObjectState *m_currentHoldEffects[2] = {nullptr};
124124
float m_effectMix[2] = {0.0f};
125+
126+
bool m_SkipEffectIfInputIsZero();
125127
};

Main/src/Audio/AudioPlayback.cpp

+15-13
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,15 @@ void AudioPlayback::SetLaserEffect(EffectType type)
251251
m_laserEffect = m_beatmap->GetFilter(type);
252252
}
253253
}
254+
bool AudioPlayback::m_SkipEffectIfInputIsZero()
255+
{
256+
return m_laserEffect.type == EffectType::PeakingFilter || m_laserEffect.type == EffectType::HighPassFilter
257+
|| m_laserEffect.type == EffectType::LowPassFilter || m_laserEffect.type == EffectType::PitchShift
258+
|| m_laserEffect.type == EffectType::Bitcrush;
259+
}
254260
void AudioPlayback::SetLaserFilterInput(float input, bool active)
255261
{
256-
if (m_laserEffect.type != EffectType::None && (active || (input != 0.0f)))
262+
if (m_laserEffect.type != EffectType::None && (active && (input != 0.0f || !m_SkipEffectIfInputIsZero())))
257263
{
258264
if (m_laserEffect.type == EffectType::SwitchAudio)
259265
{
@@ -292,6 +298,7 @@ void AudioPlayback::SetLaserFilterInput(float input, bool active)
292298

293299
// Set params
294300
m_SetLaserEffectParameter(input);
301+
m_laserDSP->mix = Math::Clamp(m_laserDSP->mix, 0.f, 1.f);
295302
m_laserInput = input;
296303
}
297304
else
@@ -436,9 +443,6 @@ void AudioPlayback::m_CleanupDSP(DSP *&ptr)
436443
}
437444
void AudioPlayback::m_SetLaserEffectParameter(float input)
438445
{
439-
if (!m_laserDSP)
440-
return;
441-
442446
assert(input >= 0.0f && input <= 1.0f);
443447

444448
// Mix float biquad filters, these are applied manualy by changing the filter parameters (gain,q,freq,etc.)
@@ -454,14 +458,14 @@ void AudioPlayback::m_SetLaserEffectParameter(float input)
454458
case EffectType::Bitcrush:
455459
{
456460
m_laserDSP->mix = m_laserEffect.mix.Sample(input);
457-
BitCrusherDSP *bcDSP = (BitCrusherDSP *)m_laserDSP;
461+
auto *bcDSP = (BitCrusherDSP *)m_laserDSP;
458462
bcDSP->SetPeriod((float)m_laserEffect.bitcrusher.reduction.Sample(input));
459463
break;
460464
}
461465
case EffectType::Echo:
462466
{
463467
m_laserDSP->mix = m_laserEffect.mix.Sample(input);
464-
EchoDSP *echoDSP = (EchoDSP *)m_laserDSP;
468+
auto *echoDSP = (EchoDSP *)m_laserDSP;
465469
echoDSP->feedback = m_laserEffect.echo.feedback.Sample(input);
466470
break;
467471
}
@@ -471,42 +475,40 @@ void AudioPlayback::m_SetLaserEffectParameter(float input)
471475
if (input > 0.8f)
472476
mix *= 1.0f - (input - 0.8f) / 0.2f;
473477

474-
BQFDSP *bqfDSP = (BQFDSP *)m_laserDSP;
478+
auto *bqfDSP = (BQFDSP *)m_laserDSP;
475479
bqfDSP->SetPeaking(m_laserEffect.peaking.q.Sample(input), m_laserEffect.peaking.freq.Sample(input), m_laserEffect.peaking.gain.Sample(input) * mix);
476480
break;
477481
}
478482
case EffectType::LowPassFilter:
479483
{
480484
m_laserDSP->mix = m_laserEffectMix;
481-
BQFDSP *bqfDSP = (BQFDSP *)m_laserDSP;
485+
auto *bqfDSP = (BQFDSP *)m_laserDSP;
482486
bqfDSP->SetLowPass(m_laserEffect.lpf.q.Sample(input) * mix + 0.1f, m_laserEffect.lpf.freq.Sample(input));
483487
break;
484488
}
485489
case EffectType::HighPassFilter:
486490
{
487491
m_laserDSP->mix = m_laserEffectMix;
488-
BQFDSP *bqfDSP = (BQFDSP *)m_laserDSP;
492+
auto *bqfDSP = (BQFDSP *)m_laserDSP;
489493
bqfDSP->SetHighPass(m_laserEffect.hpf.q.Sample(input) * mix + 0.1f, m_laserEffect.hpf.freq.Sample(input));
490494
break;
491495
}
492496
case EffectType::PitchShift:
493497
{
494498
m_laserDSP->mix = m_laserEffect.mix.Sample(input);
495-
PitchShiftDSP *ps = (PitchShiftDSP *)m_laserDSP;
499+
auto *ps = (PitchShiftDSP *)m_laserDSP;
496500
ps->amount = m_laserEffect.pitchshift.amount.Sample(input);
497501
break;
498502
}
499503
case EffectType::Gate:
500504
{
501505
m_laserDSP->mix = m_laserEffect.mix.Sample(input);
502-
GateDSP *gd = (GateDSP *)m_laserDSP;
503-
// gd->SetLength(actualLength);
504506
break;
505507
}
506508
case EffectType::Retrigger:
507509
{
508510
m_laserDSP->mix = m_laserEffect.mix.Sample(input);
509-
RetriggerDSP *rt = (RetriggerDSP *)m_laserDSP;
511+
auto *rt = (RetriggerDSP *)m_laserDSP;
510512
rt->SetLength(actualLength);
511513
break;
512514
}

Main/src/Scoring.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,10 @@ bool Scoring::IsLaserHeld(uint32 laserIndex, bool includeSlams) const
428428
if (m_holdObjects[laserIndex + 6])
429429
{
430430
// Check for slams
431-
return (((LaserObjectState*)m_holdObjects[laserIndex + 6])->flags & LaserObjectState::flag_Instant) == 0;
431+
auto obj = (LaserObjectState*)m_holdObjects[laserIndex + 6];
432+
if ((obj->flags & LaserObjectState::flag_Instant) && obj->next)
433+
return true;
434+
return !(obj->flags & LaserObjectState::flag_Instant);
432435
}
433436
return false;
434437
}

0 commit comments

Comments
 (0)