#include <psemek/audio/effect/fade_out.hpp>
#include <psemek/audio/effect/envelope_base.hpp>
#include <psemek/math/interval.hpp>

namespace psemek::audio
{

	stream_ptr fade_out(stream_ptr stream, duration length, duration start)
	{
		return envelope_base(std::move(stream), [start, length](duration time){
			return math::clamp(static_cast<float>(length.frames() + start.frames() - time.frames()) / length.frames(), {0.f, 1.f});
		}, start + length);
	}

}
