add compost psuedo_stereo

This commit is contained in:
bolero-MURAKAMI 2012-11-25 10:09:41 +09:00
parent c33ae70d13
commit ca4fdcdbae
6 changed files with 190 additions and 35 deletions

View file

@ -13,6 +13,7 @@
#include <sprout/compost/effects/tremolo.hpp>
#include <sprout/compost/effects/vibrato.hpp>
#include <sprout/compost/effects/chorus.hpp>
#include <sprout/compost/effects/pseudo_stereo.hpp>
#include <sprout/compost/effects/noise_gated.hpp>
#include <sprout/compost/effects/superposed.hpp>

View file

@ -0,0 +1,154 @@
#ifndef SPROUT_COMPOST_EFFECTS_PSEUDO_STEREO_HPP
#define SPROUT_COMPOST_EFFECTS_PSEUDO_STEREO_HPP
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/lvalue_forward.hpp>
#include <sprout/range/adaptor/transformed.hpp>
#include <sprout/range/adaptor/outdirected.hpp>
#include <sprout/range/adaptor/indexed.hpp>
#include <sprout/compost/formats/stereo.hpp>
namespace sprout {
namespace compost {
//
// pseudo_stereo_outdirected_value
//
template<typename Value, typename IntType, bool IsLeft>
struct pseudo_stereo_outdirected_value {
public:
typedef Value value_type;
typedef IntType int_type;
private:
value_type delay_;
int_type samples_per_sec_;
int_type d_;
private:
template<bool Left, typename Outdirected>
SPROUT_CONSTEXPR typename std::enable_if<
Left,
typename std::iterator_traits<Outdirected>::value_type
>::type
calc(Outdirected const& x) const {
return x.index() + d_ >= 0 ? *x + x[d_]
: 0
;
}
template<bool Left, typename Outdirected>
SPROUT_CONSTEXPR typename std::enable_if<
!Left,
typename std::iterator_traits<Outdirected>::value_type
>::type
calc(Outdirected const& x) const {
return x.index() + d_ >= 0 ? *x - x[d_]
: 0
;
}
public:
explicit SPROUT_CONSTEXPR pseudo_stereo_outdirected_value(
value_type const& delay, int_type samples_per_sec = 44100
)
: delay_(delay), samples_per_sec_(samples_per_sec), d_(static_cast<int_type>(-delay * samples_per_sec_))
{}
template<typename Outdirected>
SPROUT_CONSTEXPR typename std::iterator_traits<Outdirected>::value_type
operator()(Outdirected const& x) const {
return calc<IsLeft>(x);
}
};
namespace effects {
//
// pseudo_stereo_holder
//
template<typename T, typename IntType = int>
class pseudo_stereo_holder {
public:
typedef T value_type;
typedef IntType int_type;
private:
value_type delay_;
int_type samples_per_sec_;
public:
pseudo_stereo_holder() = default;
pseudo_stereo_holder(pseudo_stereo_holder const&) = default;
explicit SPROUT_CONSTEXPR pseudo_stereo_holder(
value_type const& delay, int_type samples_per_sec = 44100
)
: delay_(delay), samples_per_sec_(samples_per_sec)
{}
SPROUT_CONSTEXPR value_type const& delay() const {
return delay_;
}
SPROUT_CONSTEXPR int_type const& samples_per_sec() const {
return samples_per_sec_;
}
};
//
// pseudo_stereo_forwarder
//
class pseudo_stereo_forwarder {
public:
template<typename T, typename IntType>
SPROUT_CONSTEXPR sprout::compost::effects::pseudo_stereo_holder<T, IntType>
operator()(T const& delay, IntType samples_per_sec) {
return sprout::compost::effects::pseudo_stereo_holder<T, IntType>(delay, samples_per_sec);
}
template<typename T>
SPROUT_CONSTEXPR sprout::compost::effects::pseudo_stereo_holder<T>
operator()(T const& delay) {
return sprout::compost::effects::pseudo_stereo_holder<T>(delay);
}
};
//
// pseudo_stereo
//
namespace {
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::pseudo_stereo_forwarder pseudo_stereo{};
} // anonymous-namespace
//
// operator|
//
template<typename Range, typename T, typename IntType>
inline SPROUT_CONSTEXPR auto
operator|(Range&& lhs, sprout::compost::effects::pseudo_stereo_holder<T, IntType> const& rhs)
-> decltype(
sprout::lvalue_forward<Range>(lhs)
| sprout::adaptors::indexed | sprout::adaptors::outdirected
| sprout::adaptors::transformed(
sprout::compost::pseudo_stereo_outdirected_value<T, IntType, true>(rhs.delay(), rhs.samples_per_sec())
)
| sprout::compost::formats::stereo(
sprout::lvalue_forward<Range>(lhs)
| sprout::adaptors::indexed | sprout::adaptors::outdirected
| sprout::adaptors::transformed(
sprout::compost::pseudo_stereo_outdirected_value<T, IntType, false>(rhs.delay(), rhs.samples_per_sec())
)
)
)
{
return sprout::lvalue_forward<Range>(lhs)
| sprout::adaptors::indexed | sprout::adaptors::outdirected
| sprout::adaptors::transformed(
sprout::compost::pseudo_stereo_outdirected_value<T, IntType, true>(rhs.delay(), rhs.samples_per_sec())
)
| sprout::compost::formats::stereo(
sprout::lvalue_forward<Range>(lhs)
| sprout::adaptors::indexed | sprout::adaptors::outdirected
| sprout::adaptors::transformed(
sprout::compost::pseudo_stereo_outdirected_value<T, IntType, false>(rhs.delay(), rhs.samples_per_sec())
)
)
;
}
} // namespace effects
using sprout::compost::effects::pseudo_stereo;
} // namespace compost
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_EFFECTS_PSEUDO_STEREO_HPP

View file

@ -6,8 +6,8 @@
#include <sprout/compost/formats/left_channel.hpp>
#include <sprout/compost/formats/right_channel.hpp>
#include <sprout/compost/formats/stereo.hpp>
#include <sprout/compost/formats/effected_each_cannel.hpp>
#include <sprout/compost/formats/effected_left_cannel.hpp>
#include <sprout/compost/formats/effected_right_cannel.hpp>
#include <sprout/compost/formats/effected_each.hpp>
#include <sprout/compost/formats/effected_left.hpp>
#include <sprout/compost/formats/effected_right.hpp>
#endif // #ifndef SPROUT_COMPOST_FORMATS_HPP

View file

@ -1,5 +1,5 @@
#ifndef SPROUT_COMPOST_FORMATS_EFFECTED_EACH_CHANNEL_HPP
#define SPROUT_COMPOST_FORMATS_EFFECTED_EACH_CHANNEL_HPP
#ifndef SPROUT_COMPOST_FORMATS_EFFECTED_EACH_HPP
#define SPROUT_COMPOST_FORMATS_EFFECTED_EACH_HPP
#include <sprout/config.hpp>
#include <sprout/utility/lvalue_forward.hpp>
@ -11,10 +11,10 @@ namespace sprout {
namespace compost {
namespace formats {
//
// effect_each_channel_holder
// effect_each_holder
//
template<typename LAdaptor, typename RAdaptor = void>
class effect_each_channel_holder {
class effect_each_holder {
public:
typedef LAdaptor left_adaptor_type;
typedef RAdaptor right_adaptor_type;
@ -22,7 +22,7 @@ namespace sprout {
left_adaptor_type left_adaptor_;
right_adaptor_type right_adaptor_;
public:
SPROUT_CONSTEXPR effect_each_channel_holder(left_adaptor_type const& left_adaptor, right_adaptor_type const& right_adaptor)
SPROUT_CONSTEXPR effect_each_holder(left_adaptor_type const& left_adaptor, right_adaptor_type const& right_adaptor)
: left_adaptor_(left_adaptor), right_adaptor_(right_adaptor)
{}
SPROUT_CONSTEXPR left_adaptor_type const& left_adaptor() const {
@ -33,13 +33,13 @@ namespace sprout {
}
};
template<typename Adaptor>
class effect_each_channel_holder<Adaptor, void> {
class effect_each_holder<Adaptor, void> {
public:
typedef Adaptor adaptor_type;
private:
adaptor_type adaptor_;
public:
explicit SPROUT_CONSTEXPR effect_each_channel_holder(adaptor_type const& adaptor)
explicit SPROUT_CONSTEXPR effect_each_holder(adaptor_type const& adaptor)
: adaptor_(adaptor)
{}
SPROUT_CONSTEXPR adaptor_type const& adaptor() const {
@ -53,14 +53,14 @@ namespace sprout {
class effected_each_cannel_forwarder {
public:
template<typename LAdaptor, typename RAdaptor>
SPROUT_CONSTEXPR sprout::compost::formats::effect_each_channel_holder<LAdaptor, RAdaptor>
SPROUT_CONSTEXPR sprout::compost::formats::effect_each_holder<LAdaptor, RAdaptor>
operator()(LAdaptor const& left_adaptor, RAdaptor const& right_adaptor) {
return sprout::compost::formats::effect_each_channel_holder<LAdaptor, RAdaptor>(left_adaptor, right_adaptor);
return sprout::compost::formats::effect_each_holder<LAdaptor, RAdaptor>(left_adaptor, right_adaptor);
}
template<typename Adaptor>
SPROUT_CONSTEXPR sprout::compost::formats::effect_each_channel_holder<Adaptor>
SPROUT_CONSTEXPR sprout::compost::formats::effect_each_holder<Adaptor>
operator()(Adaptor const& adaptor) {
return sprout::compost::formats::effect_each_channel_holder<Adaptor>(adaptor);
return sprout::compost::formats::effect_each_holder<Adaptor>(adaptor);
}
};
@ -76,7 +76,7 @@ namespace sprout {
//
template<typename Range, typename LAdaptor, typename RAdaptor>
inline SPROUT_CONSTEXPR auto
operator|(Range&& lhs, sprout::compost::formats::effect_each_channel_holder<LAdaptor, RAdaptor> const& rhs)
operator|(Range&& lhs, sprout::compost::formats::effect_each_holder<LAdaptor, RAdaptor> const& rhs)
-> decltype(
sprout::lvalue_forward<Range>(lhs) | sprout::compost::formats::left_channel | rhs.left_adaptor()
| sprout::compost::formats::stereo(sprout::lvalue_forward<Range>(lhs) | sprout::compost::formats::right_channel | rhs.right_adaptor())
@ -88,7 +88,7 @@ namespace sprout {
}
template<typename Range, typename Adaptor>
inline SPROUT_CONSTEXPR auto
operator|(Range&& lhs, sprout::compost::formats::effect_each_channel_holder<Adaptor> const& rhs)
operator|(Range&& lhs, sprout::compost::formats::effect_each_holder<Adaptor> const& rhs)
-> decltype(
sprout::lvalue_forward<Range>(lhs) | sprout::compost::formats::left_channel | rhs.adaptor()
| sprout::compost::formats::stereo(sprout::lvalue_forward<Range>(lhs) | sprout::compost::formats::right_channel | rhs.adaptor())
@ -104,4 +104,4 @@ namespace sprout {
} // namespace compost
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_FORMATS_EFFECTED_EACH_CHANNEL_HPP
#endif // #ifndef SPROUT_COMPOST_FORMATS_EFFECTED_EACH_HPP

View file

@ -1,5 +1,5 @@
#ifndef SPROUT_COMPOST_FORMATS_EFFECTED_LEFT_CHANNEL_HPP
#define SPROUT_COMPOST_FORMATS_EFFECTED_LEFT_CHANNEL_HPP
#ifndef SPROUT_COMPOST_FORMATS_EFFECTED_LEFT_HPP
#define SPROUT_COMPOST_FORMATS_EFFECTED_LEFT_HPP
#include <sprout/config.hpp>
#include <sprout/utility/lvalue_forward.hpp>
@ -11,16 +11,16 @@ namespace sprout {
namespace compost {
namespace formats {
//
// effect_left_channel_holder
// effect_left_holder
//
template<typename Adaptor>
class effect_left_channel_holder {
class effect_left_holder {
public:
typedef Adaptor adaptor_type;
private:
adaptor_type adaptor_;
public:
explicit SPROUT_CONSTEXPR effect_left_channel_holder(adaptor_type const& adaptor)
explicit SPROUT_CONSTEXPR effect_left_holder(adaptor_type const& adaptor)
: adaptor_(adaptor)
{}
SPROUT_CONSTEXPR adaptor_type const& adaptor() const {
@ -34,9 +34,9 @@ namespace sprout {
class effected_left_cannel_forwarder {
public:
template<typename Adaptor>
SPROUT_CONSTEXPR sprout::compost::formats::effect_left_channel_holder<Adaptor>
SPROUT_CONSTEXPR sprout::compost::formats::effect_left_holder<Adaptor>
operator()(Adaptor const& adaptor) {
return sprout::compost::formats::effect_left_channel_holder<Adaptor>(adaptor);
return sprout::compost::formats::effect_left_holder<Adaptor>(adaptor);
}
};
@ -52,7 +52,7 @@ namespace sprout {
//
template<typename Range, typename Adaptor>
inline SPROUT_CONSTEXPR auto
operator|(Range&& lhs, sprout::compost::formats::effect_left_channel_holder<Adaptor> const& rhs)
operator|(Range&& lhs, sprout::compost::formats::effect_left_holder<Adaptor> const& rhs)
-> decltype(
sprout::lvalue_forward<Range>(lhs) | sprout::compost::formats::left_channel | rhs.adaptor()
| sprout::compost::formats::stereo(sprout::lvalue_forward<Range>(lhs) | sprout::compost::formats::right_channel)
@ -68,4 +68,4 @@ namespace sprout {
} // namespace compost
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_FORMATS_EFFECTED_LEFT_CHANNEL_HPP
#endif // #ifndef SPROUT_COMPOST_FORMATS_EFFECTED_LEFT_HPP

View file

@ -1,5 +1,5 @@
#ifndef SPROUT_COMPOST_FORMATS_EFFECTED_RIGHT_CHANNEL_HPP
#define SPROUT_COMPOST_FORMATS_EFFECTED_RIGHT_CHANNEL_HPP
#ifndef SPROUT_COMPOST_FORMATS_EFFECTED_RIGHT_HPP
#define SPROUT_COMPOST_FORMATS_EFFECTED_RIGHT_HPP
#include <sprout/config.hpp>
#include <sprout/utility/lvalue_forward.hpp>
@ -11,16 +11,16 @@ namespace sprout {
namespace compost {
namespace formats {
//
// effect_right_channel_holder
// effect_right_holder
//
template<typename Adaptor>
class effect_right_channel_holder {
class effect_right_holder {
public:
typedef Adaptor adaptor_type;
private:
adaptor_type adaptor_;
public:
explicit SPROUT_CONSTEXPR effect_right_channel_holder(adaptor_type const& adaptor)
explicit SPROUT_CONSTEXPR effect_right_holder(adaptor_type const& adaptor)
: adaptor_(adaptor)
{}
SPROUT_CONSTEXPR adaptor_type const& adaptor() const {
@ -34,9 +34,9 @@ namespace sprout {
class effected_right_cannel_forwarder {
public:
template<typename Adaptor>
SPROUT_CONSTEXPR sprout::compost::formats::effect_right_channel_holder<Adaptor>
SPROUT_CONSTEXPR sprout::compost::formats::effect_right_holder<Adaptor>
operator()(Adaptor const& adaptor) {
return sprout::compost::formats::effect_right_channel_holder<Adaptor>(adaptor);
return sprout::compost::formats::effect_right_holder<Adaptor>(adaptor);
}
};
@ -52,7 +52,7 @@ namespace sprout {
//
template<typename Range, typename Adaptor>
inline SPROUT_CONSTEXPR auto
operator|(Range&& lhs, sprout::compost::formats::effect_right_channel_holder<Adaptor> const& rhs)
operator|(Range&& lhs, sprout::compost::formats::effect_right_holder<Adaptor> const& rhs)
-> decltype(
sprout::lvalue_forward<Range>(lhs) | sprout::compost::formats::left_channel
| sprout::compost::formats::stereo(sprout::lvalue_forward<Range>(lhs) | sprout::compost::formats::right_channel | rhs.adaptor())
@ -68,4 +68,4 @@ namespace sprout {
} // namespace compost
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_FORMATS_EFFECTED_RIGHT_CHANNEL_HPP
#endif // #ifndef SPROUT_COMPOST_FORMATS_EFFECTED_RIGHT_HPP