1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00
Sprout/sprout/compost/effects/noise_gated.hpp

119 lines
3.1 KiB
C++
Raw Normal View History

2012-11-17 09:44:24 +00:00
#ifndef SPROUT_COMPOST_EFFECTS_NOISE_GATED_HPP
#define SPROUT_COMPOST_EFFECTS_NOISE_GATED_HPP
2012-11-09 13:33:11 +00:00
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/range/adaptor/transformed.hpp>
namespace sprout {
namespace compost {
namespace detail {
template<typename Value, typename T>
SPROUT_CONSTEXPR T
noise_gate_value(T const& x, Value const& threshold) {
return x <= threshold && x >= -threshold ? 0
: x
;
}
} // namespace detail
//
// noise_gate_value
//
template<typename Value, typename T = void>
struct noise_gate_value {
public:
typedef Value value_type;
typedef T argument_type;
typedef T result_type;
private:
value_type threshold_;
public:
explicit SPROUT_CONSTEXPR noise_gate_value(Value const& threshold)
: threshold_(threshold)
{}
SPROUT_CONSTEXPR result_type
operator()(T const& x) const {
return sprout::compost::detail::noise_gate_value(x, threshold_);
}
};
template<typename Value>
struct noise_gate_value<Value, void> {
public:
typedef Value value_type;
private:
value_type threshold_;
public:
explicit SPROUT_CONSTEXPR noise_gate_value(Value const& threshold)
: threshold_(threshold)
{}
template<typename T>
SPROUT_CONSTEXPR T
operator()(T const& x) const {
return sprout::compost::detail::noise_gate_value(x, threshold_);
}
};
namespace effects {
//
// noise_gate_holder
//
template<typename T>
class noise_gate_holder {
public:
typedef T value_type;
private:
value_type threshold_;
public:
noise_gate_holder() = default;
noise_gate_holder(noise_gate_holder const&) = default;
explicit SPROUT_CONSTEXPR noise_gate_holder(value_type const& threshold)
: threshold_(threshold)
{}
SPROUT_CONSTEXPR value_type const& threshold() const {
return threshold_;
}
};
//
// noise_gated_forwarder
//
class noise_gated_forwarder {
public:
template<typename T>
SPROUT_CONSTEXPR sprout::compost::effects::noise_gate_holder<T>
operator()(T const& threshold) {
return sprout::compost::effects::noise_gate_holder<T>(threshold);
}
};
//
// noise_gated
//
namespace {
2012-12-17 14:10:23 +00:00
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::noise_gated_forwarder noise_gated = {};
2012-11-09 13:33:11 +00:00
} // anonymous-namespace
//
// operator|
//
template<typename Range, typename T>
inline SPROUT_CONSTEXPR auto
operator|(Range&& lhs, sprout::compost::effects::noise_gate_holder<T> const& rhs)
-> decltype(
sprout::forward<Range>(lhs)
| sprout::adaptors::transformed(sprout::compost::noise_gate_value<T>(rhs.threshold()))
)
{
return sprout::forward<Range>(lhs)
| sprout::adaptors::transformed(sprout::compost::noise_gate_value<T>(rhs.threshold()))
;
}
} // namespace effects
using sprout::compost::effects::noise_gated;
2012-11-09 13:33:11 +00:00
} // namespace compost
} // namespace sprout
2012-11-17 09:44:24 +00:00
#endif // #ifndef SPROUT_COMPOST_EFFECTS_NOISE_GATED_HPP