summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-07-23 15:40:18 +0200
committerAndreas Kling <kling@serenityos.org>2022-07-25 15:25:13 +0200
commitd5166ddbcf30d13a2af60b98e77c2322eb8cbc08 (patch)
treeb6250a80235438a1d8672689def60eff2001d3f9 /Userland/Libraries
parent281b319588b5af00445fdb9f5b57c51ff8eef05e (diff)
downloadserenity-d5166ddbcf30d13a2af60b98e77c2322eb8cbc08.zip
LibDSP: Actually implement the Mastering processor
This can now handle mute, volume control and panning.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibDSP/Effects.cpp26
-rw-r--r--Userland/Libraries/LibDSP/Effects.h8
2 files changed, 32 insertions, 2 deletions
diff --git a/Userland/Libraries/LibDSP/Effects.cpp b/Userland/Libraries/LibDSP/Effects.cpp
index c7c0fe9e92..777e1725b8 100644
--- a/Userland/Libraries/LibDSP/Effects.cpp
+++ b/Userland/Libraries/LibDSP/Effects.cpp
@@ -59,12 +59,34 @@ void Delay::process_impl(Signal const& input_signal, Signal& output_signal)
Mastering::Mastering(NonnullRefPtr<Transport> transport)
: EffectProcessor(move(transport))
+ , m_pan("Pan", -1, 1, 0, Logarithmic::No)
+ , m_volume("Volume", 0, 1, 1, Logarithmic::No)
+ , m_muted("Mute", false)
{
+ m_parameters.append(m_muted);
+ m_parameters.append(m_volume);
+ m_parameters.append(m_pan);
}
-void Mastering::process_impl([[maybe_unused]] Signal const& input_signal, [[maybe_unused]] Signal& output_signal)
+void Mastering::process_impl(Signal const& input_signal, Signal& output)
{
- TODO();
+ process_to_fixed_array(input_signal, output.get<FixedArray<Sample>>());
+}
+
+void Mastering::process_to_fixed_array(Signal const& input_signal, FixedArray<Sample>& output)
+{
+ if (m_muted) {
+ output.fill_with({});
+ return;
+ }
+
+ auto const& input = input_signal.get<FixedArray<Sample>>();
+ for (size_t i = 0; i < input.size(); ++i) {
+ auto sample = input[i];
+ sample.log_multiply(static_cast<float>(m_volume));
+ sample.pan(static_cast<float>(m_pan));
+ output[i] = sample;
+ }
}
}
diff --git a/Userland/Libraries/LibDSP/Effects.h b/Userland/Libraries/LibDSP/Effects.h
index c9844cca71..bcfa6feb32 100644
--- a/Userland/Libraries/LibDSP/Effects.h
+++ b/Userland/Libraries/LibDSP/Effects.h
@@ -37,8 +37,16 @@ class Mastering : public EffectProcessor {
public:
Mastering(NonnullRefPtr<Transport>);
+ // The mastering processor can be used by the track and therefore needs to be able to write to a fixed array directly.
+ // Otherwise, Track needs to do more unnecessary sample data copies.
+ void process_to_fixed_array(Signal const&, FixedArray<Sample>&);
+
private:
virtual void process_impl(Signal const&, Signal&) override;
+
+ ProcessorRangeParameter m_pan;
+ ProcessorRangeParameter m_volume;
+ ProcessorBooleanParameter m_muted;
};
}