Skip to content

Commit acc4035

Browse files
Remove C-style casts
1 parent 7609c1d commit acc4035

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/dsp/generators/oscillator.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void Oscillator::AttachParameterToSourceImpl(OscillatorParameter parameter, std:
4242

4343
void Oscillator::Reset(float phase)
4444
{
45-
float clampedPhase = clamp(phase, 0.0f, (float)WAVETABLE_SIZE);
45+
float clampedPhase = clamp(phase, 0.0f, static_cast<float>(WAVETABLE_SIZE));
4646
m_phase = clampedPhase;
4747
if (m_follower != nullptr) {
4848
m_follower->Reset(clampedPhase);
@@ -52,7 +52,7 @@ void Oscillator::Reset(float phase)
5252
void Oscillator::SetFrequency(float frequency)
5353
{
5454
p_frequency = frequency;
55-
m_phaseIncrement = p_frequency * (float)WAVETABLE_SIZE / (float)m_context.sampleRate;
55+
m_phaseIncrement = p_frequency * static_cast<float>(WAVETABLE_SIZE) / static_cast<float>(m_context.sampleRate);
5656
}
5757

5858
void Oscillator::SetWaveform(Waveform waveform)
@@ -75,16 +75,16 @@ void Oscillator::DetachFollower()
7575
void Oscillator::PopulateWavetable()
7676
{
7777
for (size_t idx = 0; idx < WAVETABLE_SIZE; idx++) {
78-
float phase = (float)idx * PI * 2.0f / (float)WAVETABLE_SIZE;
78+
float phase = static_cast<float>(idx) * PI * 2.0f / static_cast<float>(WAVETABLE_SIZE);
7979
m_wavetable[idx] = sin(phase);
8080
}
8181
}
8282

8383
void Oscillator::IncrementPhase()
8484
{
8585
m_phase += m_phaseIncrement;
86-
if (m_phase >= (float)WAVETABLE_SIZE) {
87-
m_phase -= (float)WAVETABLE_SIZE;
86+
if (m_phase >= static_cast<float>(WAVETABLE_SIZE)) {
87+
m_phase -= static_cast<float>(WAVETABLE_SIZE);
8888
if (m_follower != nullptr) {
8989
m_follower->Reset(m_phase);
9090
}
@@ -95,7 +95,7 @@ Sample Oscillator::Lerp()
9595
{
9696
size_t truncatedIdx = m_phase;
9797
size_t nextIdx = (truncatedIdx + 1) % WAVETABLE_SIZE;
98-
float nextIdxWeight = m_phase - (float)truncatedIdx;
98+
float nextIdxWeight = m_phase - static_cast<float>(truncatedIdx);
9999
float truncatedIdxWeight = 1.0f - nextIdxWeight;
100100

101101
return (m_wavetable[truncatedIdx] * truncatedIdxWeight) + (m_wavetable[nextIdx] * nextIdxWeight);

src/dsp/modulators/adsr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ AdsrEnvelopeModulator::AdsrEnvelopeModulator(Context& context, AdsrEnvelope enve
1313

1414
float AdsrEnvelopeModulator::ModulateImpl()
1515
{
16-
float position = (float)m_samplesSinceLastStage * (1000.0f / (float)m_context.sampleRate);
16+
float position = static_cast<float>(m_samplesSinceLastStage) * (1000.0f / static_cast<float>(m_context.sampleRate));
1717

1818
/**
1919
* NOTE: The modulation value is calculated based on the current stage of the modulator.
@@ -117,8 +117,8 @@ void AdsrEnvelopeModulator::Update(float stageDuration, AdsrStage nextStage, boo
117117
m_samplesSinceLastStage++;
118118
}
119119

120-
float msPerSample = 1000.0f / (float)m_context.sampleRate;
121-
if ((float)m_samplesSinceLastStage * msPerSample >= stageDuration) {
120+
float msPerSample = 1000.0f / static_cast<float>(m_context.sampleRate);
121+
if (static_cast<float>(m_samplesSinceLastStage) * msPerSample >= stageDuration) {
122122
m_samplesSinceLastStage = 0;
123123
m_stage = nextStage;
124124
}

src/dsp/processors/filter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ void Filter::SetCutoffFrequency(float frequency)
4040
void Filter::CalculateAlpha()
4141
{
4242
float cutoffResponse = 1.0f / (2.0f * PI * p_cutoffFrequency);
43-
float deltaTime = 1.0f / (float)m_context.sampleRate;
43+
float deltaTime = 1.0f / static_cast<float>(m_context.sampleRate);
4444
m_alpha = deltaTime / (cutoffResponse + deltaTime);
4545
}

tests/dsp/generators/oscillator_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ TEST(oscillator_suite, reset_test)
3434
EXPECT_FLOAT_EQ(osc.Generate(), 0.0f);
3535
EXPECT_FLOAT_EQ(osc.Generate(), 0.06264372f);
3636

37-
osc.Reset((float)WAVETABLE_SIZE / 2.0f);
37+
osc.Reset(static_cast<float>(WAVETABLE_SIZE) / 2.0f);
3838
EXPECT_NEAR(osc.Generate(), 0.0f, 1e-5f);
3939
EXPECT_NEAR(osc.Generate(), -0.06264372f, 1e-5f);
4040
}

0 commit comments

Comments
 (0)