From b7cf29d767b30d84c9d57d20735aa95e6429271e Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sun, 25 Nov 2012 23:52:25 +0900 Subject: [PATCH] add compost auto_pan, vocal_cancelled --- sprout/compost/effects.hpp | 2 + sprout/compost/effects/auto_pan.hpp | 158 +++++++++++++++++++++ sprout/compost/effects/vocal_cancelled.hpp | 53 +++++++ 3 files changed, 213 insertions(+) create mode 100644 sprout/compost/effects/auto_pan.hpp create mode 100644 sprout/compost/effects/vocal_cancelled.hpp diff --git a/sprout/compost/effects.hpp b/sprout/compost/effects.hpp index 5e6a5329..91e3f126 100644 --- a/sprout/compost/effects.hpp +++ b/sprout/compost/effects.hpp @@ -13,8 +13,10 @@ #include #include #include +#include #include #include +#include #include #endif // #ifndef SPROUT_COMPOST_EFFECTS_HPP diff --git a/sprout/compost/effects/auto_pan.hpp b/sprout/compost/effects/auto_pan.hpp new file mode 100644 index 00000000..7dec17a6 --- /dev/null +++ b/sprout/compost/effects/auto_pan.hpp @@ -0,0 +1,158 @@ +#ifndef SPROUT_COMPOST_EFFECTS_AUTO_PAN_HPP +#define SPROUT_COMPOST_EFFECTS_AUTO_PAN_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace compost { + // + // auto_pan_outdirected_value + // + template + struct auto_pan_outdirected_value { + public: + typedef Value value_type; + typedef IntType int_type; + private: + value_type depth_; + value_type rate_; + int_type samples_per_sec_; + private: + template + SPROUT_CONSTEXPR typename std::enable_if< + Left, + typename std::iterator_traits::value_type + >::type + calc(Outdirected const& x) const { + return (1 + depth_ * sprout::sin(2 * sprout::math::pi() * rate_ * x.index() / samples_per_sec_)) * *x; + } + template + SPROUT_CONSTEXPR typename std::enable_if< + !Left, + typename std::iterator_traits::value_type + >::type + calc(Outdirected const& x) const { + return (1 + depth_ * sprout::sin(2 * sprout::math::pi() * rate_ * x.index() / samples_per_sec_ + sprout::math::pi())) * *x; + } + public: + SPROUT_CONSTEXPR auto_pan_outdirected_value( + value_type const& depth, value_type const& rate, + int_type samples_per_sec = 44100 + ) + : depth_(depth), rate_(rate), samples_per_sec_(samples_per_sec) + {} + template + SPROUT_CONSTEXPR typename std::iterator_traits::value_type + operator()(Outdirected const& x) const { + return calc(x); + } + }; + + namespace effects { + // + // auto_pan_holder + // + template + class auto_pan_holder { + public: + typedef T value_type; + typedef IntType int_type; + private: + value_type depth_; + value_type rate_; + int_type samples_per_sec_; + public: + auto_pan_holder() = default; + auto_pan_holder(auto_pan_holder const&) = default; + SPROUT_CONSTEXPR auto_pan_holder( + value_type const& depth, value_type const& rate, + int_type samples_per_sec = 44100 + ) + : depth_(depth), rate_(rate), samples_per_sec_(samples_per_sec) + {} + SPROUT_CONSTEXPR value_type const& depth() const { + return depth_; + } + SPROUT_CONSTEXPR value_type const& rate() const { + return rate_; + } + SPROUT_CONSTEXPR int_type const& samples_per_sec() const { + return samples_per_sec_; + } + }; + + // + // auto_pan_forwarder + // + class auto_pan_forwarder { + public: + template + SPROUT_CONSTEXPR sprout::compost::effects::auto_pan_holder + operator()(T const& depth, T const& rate, IntType samples_per_sec) { + return sprout::compost::effects::auto_pan_holder(depth, rate, samples_per_sec); + } + template + SPROUT_CONSTEXPR sprout::compost::effects::auto_pan_holder + operator()(T const& depth, T const& rate) { + return sprout::compost::effects::auto_pan_holder(depth, rate); + } + }; + + // + // auto_pan + // + namespace { + SPROUT_STATIC_CONSTEXPR sprout::compost::effects::auto_pan_forwarder auto_pan{}; + } // anonymous-namespace + + // + // operator| + // + template + inline SPROUT_CONSTEXPR auto + operator|(Range&& lhs, sprout::compost::effects::auto_pan_holder const& rhs) + -> decltype( + sprout::forward(lhs) + | sprout::adaptors::indexed | sprout::adaptors::outdirected + | sprout::adaptors::transformed( + sprout::compost::auto_pan_outdirected_value(rhs.depth(), rhs.rate(), rhs.samples_per_sec()) + ) + | sprout::compost::formats::stereo( + sprout::forward(lhs) + | sprout::adaptors::indexed | sprout::adaptors::outdirected + | sprout::adaptors::transformed( + sprout::compost::auto_pan_outdirected_value(rhs.depth(), rhs.rate(), rhs.samples_per_sec()) + ) + ) + ) + { + return sprout::forward(lhs) + | sprout::adaptors::indexed | sprout::adaptors::outdirected + | sprout::adaptors::transformed( + sprout::compost::auto_pan_outdirected_value(rhs.depth(), rhs.rate(), rhs.samples_per_sec()) + ) + | sprout::compost::formats::stereo( + sprout::forward(lhs) + | sprout::adaptors::indexed | sprout::adaptors::outdirected + | sprout::adaptors::transformed( + sprout::compost::auto_pan_outdirected_value(rhs.depth(), rhs.rate(), rhs.samples_per_sec()) + ) + ) + ; + } + } // namespace effects + + using sprout::compost::effects::auto_pan; + } // namespace compost +} // namespace sprout + +#endif // #ifndef SPROUT_COMPOST_EFFECTS_AUTO_PAN_HPP diff --git a/sprout/compost/effects/vocal_cancelled.hpp b/sprout/compost/effects/vocal_cancelled.hpp new file mode 100644 index 00000000..6e778ba0 --- /dev/null +++ b/sprout/compost/effects/vocal_cancelled.hpp @@ -0,0 +1,53 @@ +#ifndef SPROUT_COMPOST_EFFECTS_VOCAL_CANCELLED_HPP +#define SPROUT_COMPOST_EFFECTS_VOCAL_CANCELLED_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace compost { + namespace effects { + // + // vocal_cancelled_forwarder + // + class vocal_cancelled_forwarder {}; + + // + // vocal_cancelled + // + namespace { + SPROUT_STATIC_CONSTEXPR sprout::compost::effects::vocal_cancelled_forwarder vocal_cancelled{}; + } // anonymous-namespace + + // + // operator| + // + template + inline SPROUT_CONSTEXPR auto + operator|(Range&& lhs, sprout::compost::effects::vocal_cancelled_forwarder const& rhs) + -> decltype( + sprout::lvalue_forward(lhs) | sprout::compost::formats::left_channel + | sprout::adaptors::transformed( + sprout::lvalue_forward(lhs) | sprout::compost::formats::right_channel, + sprout::minus<>() + ) + ) + { + return sprout::lvalue_forward(lhs) | sprout::compost::formats::left_channel + | sprout::adaptors::transformed( + sprout::lvalue_forward(lhs) | sprout::compost::formats::right_channel, + sprout::minus<>() + ) + ; + } + } // namespace effects + + using sprout::compost::effects::vocal_cancelled; + } // namespace compost +} // namespace sprout + +#endif // #ifndef SPROUT_COMPOST_EFFECTS_VOCAL_CANCELLED_HPP