mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
Piano: Use LibDSP to implement delay
This is the first step in transitioning Piano to a full LibDSP backend. For now, the delay effect is replaced with a (mostly identical) implementation in LibDSP. The new ProcessorParameterSlider attaches to a LibDSP::Processor's range parameter (LibDSP::ProcessorRangeParameter) and changes it automatically. It also has the ability to update an external GUI::Label. This is used for the three delay parameters and it will become useful for auto-generating UI for Processors.
This commit is contained in:
parent
a749b16674
commit
0dc6fe9102
8 changed files with 84 additions and 49 deletions
|
@ -10,10 +10,13 @@
|
|||
#include <AK/Math.h>
|
||||
#include <AK/NumericLimits.h>
|
||||
#include <LibAudio/Loader.h>
|
||||
#include <LibDSP/Music.h>
|
||||
#include <math.h>
|
||||
|
||||
Track::Track(const u32& time)
|
||||
: m_time(time)
|
||||
, m_temporary_transport(create<LibDSP::Transport>(120, 4))
|
||||
, m_delay(create<LibDSP::Effects::Delay>(m_temporary_transport))
|
||||
{
|
||||
set_volume(volume_max);
|
||||
set_sustain_impl(1000);
|
||||
|
@ -96,14 +99,11 @@ void Track::fill_sample(Sample& sample)
|
|||
new_sample.right += note_sample.right * m_power[note] * volume_factor * (static_cast<double>(volume()) / volume_max);
|
||||
}
|
||||
|
||||
if (m_delay) {
|
||||
new_sample.left += m_delay_buffer[m_delay_index].left * 0.333333;
|
||||
new_sample.right += m_delay_buffer[m_delay_index].right * 0.333333;
|
||||
m_delay_buffer[m_delay_index].left = new_sample.left;
|
||||
m_delay_buffer[m_delay_index].right = new_sample.right;
|
||||
if (++m_delay_index >= m_delay_samples)
|
||||
m_delay_index = 0;
|
||||
}
|
||||
auto new_sample_dsp = LibDSP::Signal(LibDSP::Sample { new_sample.left / NumericLimits<i16>::max(), new_sample.right / NumericLimits<i16>::max() });
|
||||
auto delayed_sample = m_delay->process(new_sample_dsp).get<LibDSP::Sample>();
|
||||
|
||||
new_sample.left = delayed_sample.left * NumericLimits<i16>::max();
|
||||
new_sample.right = delayed_sample.right * NumericLimits<i16>::max();
|
||||
|
||||
sample.left += new_sample.left;
|
||||
sample.right += new_sample.right;
|
||||
|
@ -111,8 +111,6 @@ void Track::fill_sample(Sample& sample)
|
|||
|
||||
void Track::reset()
|
||||
{
|
||||
memset(m_delay_buffer.data(), 0, m_delay_buffer.size() * sizeof(Sample));
|
||||
m_delay_index = 0;
|
||||
|
||||
memset(m_note_on, 0, sizeof(m_note_on));
|
||||
memset(m_power, 0, sizeof(m_power));
|
||||
|
@ -360,13 +358,3 @@ void Track::set_release(int release)
|
|||
VERIFY(release >= 0);
|
||||
m_release = release;
|
||||
}
|
||||
|
||||
void Track::set_delay(int delay)
|
||||
{
|
||||
VERIFY(delay >= 0);
|
||||
m_delay = delay;
|
||||
m_delay_samples = m_delay == 0 ? 0 : (sample_rate / (beats_per_minute / 60)) / m_delay;
|
||||
m_delay_buffer.resize(m_delay_samples);
|
||||
memset(m_delay_buffer.data(), 0, m_delay_buffer.size() * sizeof(Sample));
|
||||
m_delay_index = 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue