mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:37:45 +00:00
LibDSP+Piano: Convert DSP APIs to accept entire sample ranges
This has mainly performance benefits, so that we only need to call into all processors once for every audio buffer segment. It requires adjusting quite some logic in most processors and in Track, as we have to consider a larger collection of notes and samples at each step. There's some cautionary TODOs in the currently unused LibDSP tracks because they don't do things properly yet.
This commit is contained in:
parent
4d65607649
commit
9035d9e845
9 changed files with 123 additions and 75 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include "Effects.h"
|
||||
#include <AK/FixedArray.h>
|
||||
#include <math.h>
|
||||
|
||||
namespace LibDSP::Effects {
|
||||
|
@ -32,23 +33,26 @@ void Delay::handle_delay_time_change()
|
|||
}
|
||||
}
|
||||
|
||||
Signal Delay::process_impl(Signal const& input_signal)
|
||||
void Delay::process_impl(Signal const& input_signal, Signal& output_signal)
|
||||
{
|
||||
// FIXME: This is allocating and needs to happen on a different thread.
|
||||
handle_delay_time_change();
|
||||
|
||||
Sample const& in = input_signal.get<Sample>();
|
||||
Sample out;
|
||||
out += in.log_multiplied(static_cast<double>(m_dry_gain));
|
||||
out += m_delay_buffer[m_delay_index].log_multiplied(m_delay_decay);
|
||||
auto const& samples = input_signal.get<FixedArray<Sample>>();
|
||||
auto& output = output_signal.get<FixedArray<Sample>>();
|
||||
for (size_t i = 0; i < output.size(); ++i) {
|
||||
auto& out = output[i];
|
||||
auto const& sample = samples[i];
|
||||
out += sample.log_multiplied(static_cast<double>(m_dry_gain));
|
||||
out += m_delay_buffer[m_delay_index].log_multiplied(m_delay_decay);
|
||||
|
||||
// This is also convenient for disabling the delay effect by setting the buffer size to 0
|
||||
if (m_delay_buffer.size() >= 1)
|
||||
m_delay_buffer[m_delay_index++] = out;
|
||||
// This is also convenient for disabling the delay effect by setting the buffer size to 0
|
||||
if (m_delay_buffer.size() >= 1)
|
||||
m_delay_buffer[m_delay_index++] = out;
|
||||
|
||||
if (m_delay_index >= m_delay_buffer.size())
|
||||
m_delay_index = 0;
|
||||
|
||||
return Signal(out);
|
||||
if (m_delay_index >= m_delay_buffer.size())
|
||||
m_delay_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Mastering::Mastering(NonnullRefPtr<Transport> transport)
|
||||
|
@ -56,7 +60,7 @@ Mastering::Mastering(NonnullRefPtr<Transport> transport)
|
|||
{
|
||||
}
|
||||
|
||||
Signal Mastering::process_impl([[maybe_unused]] Signal const& input_signal)
|
||||
void Mastering::process_impl([[maybe_unused]] Signal const& input_signal, [[maybe_unused]] Signal& output_signal)
|
||||
{
|
||||
TODO();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue