1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:37:35 +00:00

Everywhere: Use AK/Math.h if applicable

AK's version should see better inlining behaviors, than the LibM one.
We avoid mixed usage for now though.

Also clean up some stale math includes and improper floatingpoint usage.
This commit is contained in:
Hendiadyoin1 2021-07-17 18:29:28 +02:00 committed by Ali Mohammad Pur
parent c5f6ba6e71
commit ed46d52252
40 changed files with 116 additions and 156 deletions

View file

@ -7,11 +7,11 @@
#include "BarsVisualizationWidget.h"
#include "AudioAlgorithms.h"
#include <AK/Complex.h>
#include <AK/Math.h>
#include <LibGUI/Event.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Painter.h>
#include <LibGUI/Window.h>
#include <math.h>
u32 round_previous_power_of_2(u32 x);
@ -27,7 +27,7 @@ void BarsVisualizationWidget::paint_event(GUI::PaintEvent& event)
return;
fft(m_sample_buffer, false);
double max = sqrt(m_sample_count * 2);
double max = AK::sqrt(m_sample_count * 2.);
double freq_bin = m_samplerate / m_sample_count;
@ -45,10 +45,10 @@ void BarsVisualizationWidget::paint_event(GUI::PaintEvent& event)
int bins_per_group = ceil_div((m_sample_count - 1) / 2, group_count) * freq_bin;
for (int i = 1; i < m_sample_count / 2; i++) {
groups[(i * freq_bin) / bins_per_group] += fabs(m_sample_buffer.data()[i].real());
groups[(i * freq_bin) / bins_per_group] += AK::fabs(m_sample_buffer.data()[i].real());
}
for (int i = 0; i < group_count; i++)
groups[i] /= max * freq_bin / (m_adjust_frequencies ? (clamp(pow(M_E, (double)i / group_count * 3.) - 1.75, 1., 15.)) : 1.);
groups[i] /= max * freq_bin / (m_adjust_frequencies ? (clamp(AK::pow(AK::E<double>, (double)i / group_count * 3.) - 1.75, 1., 15.)) : 1.);
const int horizontal_margin = 30;
const int top_vertical_margin = 15;
@ -102,7 +102,7 @@ void BarsVisualizationWidget::set_buffer(RefPtr<Audio::Buffer> buffer, int sampl
m_sample_count = round_previous_power_of_2(samples_to_use);
m_sample_buffer.resize(m_sample_count);
for (int i = 0; i < m_sample_count; i++) {
m_sample_buffer.data()[i] = (fabs(buffer->samples()[i].left) + fabs(buffer->samples()[i].right)) / 2.;
m_sample_buffer.data()[i] = (AK::fabs(buffer->samples()[i].left) + AK::fabs(buffer->samples()[i].right)) / 2.;
}
update();