diff options
author | kleines Filmröllchen <malu.bertsch@gmail.com> | 2021-11-15 22:27:28 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-11-15 23:00:11 +0000 |
commit | 8af97d0ce740b83a261660a69fc3ce7a6e23221c (patch) | |
tree | ffe14bccb0076b3d2e2f8212c269647024d543b1 /Userland/Applications | |
parent | a757f3f421df252937295ba8f453551682de0bed (diff) | |
download | serenity-8af97d0ce740b83a261660a69fc3ce7a6e23221c.zip |
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.
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/Piano/Track.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Userland/Applications/Piano/Track.cpp b/Userland/Applications/Piano/Track.cpp index 0743db4e6e..40899e4568 100644 --- a/Userland/Applications/Piano/Track.cpp +++ b/Userland/Applications/Piano/Track.cpp @@ -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())) { |