diff --git a/libs/audio/include/psemek/audio/effect/envelope.hpp b/libs/audio/include/psemek/audio/effect/envelope_base.hpp similarity index 76% rename from libs/audio/include/psemek/audio/effect/envelope.hpp rename to libs/audio/include/psemek/audio/effect/envelope_base.hpp index b4607456..349f73f6 100644 --- a/libs/audio/include/psemek/audio/effect/envelope.hpp +++ b/libs/audio/include/psemek/audio/effect/envelope_base.hpp @@ -8,10 +8,10 @@ namespace psemek::audio { template - struct envelope_impl + struct envelope_base_impl : stream { - envelope_impl(stream_ptr stream, EnvelopeFn envelope_fn, std::optional truncate) + envelope_base_impl(stream_ptr stream, EnvelopeFn envelope_fn, std::optional truncate) : stream_(std::move(stream)) , envelope_fn_(std::move(envelope_fn)) , remaining_(truncate ? std::optional{truncate->samples()} : std::nullopt) @@ -59,9 +59,11 @@ namespace psemek::audio } + // Guaranteed to call envelope_fn exactly once per audio frame template - stream_ptr envelope(stream_ptr stream, EnvelopeFn envelope_fn, std::optional truncate = {}) + stream_ptr envelope_base(stream_ptr stream, EnvelopeFn envelope_fn, std::optional truncate = {}) { - return std::make_shared>(std::move(stream), std::move(envelope_fn), truncate); + return std::make_shared>(std::move(stream), std::move(envelope_fn), truncate); } + } diff --git a/libs/audio/source/effect/fade_in.cpp b/libs/audio/source/effect/fade_in.cpp index 70980ebb..e242c401 100644 --- a/libs/audio/source/effect/fade_in.cpp +++ b/libs/audio/source/effect/fade_in.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include namespace psemek::audio @@ -7,7 +7,7 @@ namespace psemek::audio stream_ptr fade_in(stream_ptr stream, duration length, duration start) { - return envelope(std::move(stream), [start, length](duration time){ + return envelope_base(std::move(stream), [start, length](duration time){ return math::clamp(static_cast(time.frames() - start.frames()) / length.frames(), {0.f, 1.f}); }); } diff --git a/libs/audio/source/effect/fade_out.cpp b/libs/audio/source/effect/fade_out.cpp index 53b7f29b..e19b89e2 100644 --- a/libs/audio/source/effect/fade_out.cpp +++ b/libs/audio/source/effect/fade_out.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include namespace psemek::audio @@ -7,7 +7,7 @@ namespace psemek::audio stream_ptr fade_out(stream_ptr stream, duration length, duration start) { - return envelope(std::move(stream), [start, length](duration time){ + return envelope_base(std::move(stream), [start, length](duration time){ return math::clamp(static_cast(length.frames() + start.frames() - time.frames()) / length.frames(), {0.f, 1.f}); }, start + length); }