1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 23:07:34 +00:00

Audio: Fix code smells and issues found by static analysis

This fixes all current code smells, bugs and issues reported by
SonarCloud static analysis. Other issues are almost exclusively false
positives. This makes much code clearer, and some minor benefits in
performance or bug evasion may be gained.
This commit is contained in:
kleines Filmröllchen 2021-11-15 22:27:28 +01:00 committed by Linus Groh
parent a757f3f421
commit 8af97d0ce7
12 changed files with 99 additions and 77 deletions

View file

@ -167,7 +167,7 @@ Audio::Sample Track::sine(size_t note)
double sin_step = pos * 2 * M_PI;
double w = sin(m_pos[note]);
m_pos[note] += sin_step;
return w;
return Audio::Sample { w };
}
Audio::Sample Track::saw(size_t note)
@ -176,7 +176,7 @@ Audio::Sample Track::saw(size_t note)
double t = m_pos[note];
double w = (0.5 - (t - floor(t))) * 2;
m_pos[note] += saw_step;
return w;
return Audio::Sample { w };
}
Audio::Sample Track::square(size_t note)
@ -185,7 +185,7 @@ Audio::Sample Track::square(size_t note)
double square_step = pos * 2 * M_PI;
double w = AK::sin(m_pos[note]) >= 0 ? 1 : -1;
m_pos[note] += square_step;
return w;
return Audio::Sample { w };
}
Audio::Sample Track::triangle(size_t note)
@ -194,7 +194,7 @@ Audio::Sample Track::triangle(size_t note)
double t = m_pos[note];
double w = AK::fabs(AK::fmod((4 * t) + 1, 4.) - 2) - 1.;
m_pos[note] += triangle_step;
return w;
return Audio::Sample { w };
}
Audio::Sample Track::noise(size_t note)
@ -207,14 +207,14 @@ Audio::Sample Track::noise(size_t note)
m_last_w[note] = (random_percentage * 2) - 1;
m_pos[note] = 0;
}
return m_last_w[note];
return Audio::Sample { m_last_w[note] };
}
Audio::Sample Track::recorded_sample(size_t note)
{
int t = m_pos[note];
if (t >= static_cast<int>(m_recorded_sample.size()))
return 0;
return {};
double w_left = m_recorded_sample[t].left;
double w_right = m_recorded_sample[t].right;
if (t + 1 < static_cast<int>(m_recorded_sample.size())) {