mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 13:37:45 +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:
parent
c5f6ba6e71
commit
ed46d52252
40 changed files with 116 additions and 156 deletions
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "AudioAlgorithms.h"
|
||||
#include <AK/Complex.h>
|
||||
#include <math.h>
|
||||
#include <AK/Math.h>
|
||||
|
||||
// This function uses the input vector as output too. therefore, if you wish to
|
||||
// leave it intact, pass a copy to this function
|
||||
|
@ -38,8 +38,8 @@ void fft(Vector<Complex<double>>& sample_data, bool invert)
|
|||
}
|
||||
|
||||
for (int len = 2; len <= n; len <<= 1) {
|
||||
double ang = 2 * M_PI / len * (invert ? -1 : 1);
|
||||
Complex<double> wlen(cos(ang), sin(ang));
|
||||
double ang = 2 * AK::Pi<double> / len * (invert ? -1 : 1);
|
||||
Complex<double> wlen(AK::cos(ang), AK::sin(ang));
|
||||
for (int i = 0; i < n; i += len) {
|
||||
Complex<double> w = { 1., 0. };
|
||||
for (int j = 0; j < len / 2; j++) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
*/
|
||||
|
||||
#include "SampleWidget.h"
|
||||
#include <AK/Math.h>
|
||||
#include <LibAudio/Buffer.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <math.h>
|
||||
|
||||
SampleWidget::SampleWidget()
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ void SampleWidget::paint_event(GUI::PaintEvent& event)
|
|||
if (m_buffer) {
|
||||
int samples_per_pixel = m_buffer->sample_count() / frame_inner_rect().width();
|
||||
for (int sample_index = 0; sample_index < m_buffer->sample_count() && (x - x_offset) < frame_inner_rect().width(); ++sample_index) {
|
||||
float sample = fabsf((float)m_buffer->samples()[sample_index].left);
|
||||
float sample = AK::fabs((float)m_buffer->samples()[sample_index].left);
|
||||
|
||||
sample_max = max(sample, sample_max);
|
||||
++count;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue