mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
add some compost effects.
This commit is contained in:
parent
d01ee064e2
commit
c7e6be98bb
20 changed files with 1815 additions and 6 deletions
126
sprout/compost/effects/compress.hpp
Normal file
126
sprout/compost/effects/compress.hpp
Normal file
|
@ -0,0 +1,126 @@
|
|||
#ifndef SPROUT_COMPOST_EFFECTS_COMPRESS_HPP
|
||||
#define SPROUT_COMPOST_EFFECTS_COMPRESS_HPP
|
||||
|
||||
#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
|
||||
compress_value(T const& x, Value const& threshold, Value const& ratio, Value const& gain) {
|
||||
return (x > threshold ? threshold + (x - threshold) * ratio
|
||||
: x < -threshold ? -threshold + (x + threshold) * ratio
|
||||
: x
|
||||
) * gain
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// compress_value
|
||||
//
|
||||
template<typename Value, typename T = void>
|
||||
struct compress_value {
|
||||
public:
|
||||
typedef Value value_type;
|
||||
typedef T argument_type;
|
||||
typedef T result_type;
|
||||
private:
|
||||
value_type threshold_;
|
||||
value_type ratio_;
|
||||
value_type gain_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR compress_value(Value const& threshold, Value const& ratio)
|
||||
: threshold_(threshold), ratio_(ratio), gain_(1 / (threshold + (1 - threshold) * ratio))
|
||||
{}
|
||||
SPROUT_CONSTEXPR result_type
|
||||
operator()(T const& x) const {
|
||||
return sprout::compost::detail::compress_value(x, threshold_, ratio_, gain_);
|
||||
}
|
||||
};
|
||||
template<typename Value>
|
||||
struct compress_value<Value, void> {
|
||||
public:
|
||||
typedef Value value_type;
|
||||
private:
|
||||
value_type threshold_;
|
||||
value_type ratio_;
|
||||
value_type gain_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR compress_value(Value const& threshold, Value const& ratio)
|
||||
: threshold_(threshold), ratio_(ratio), gain_(1 / (threshold + (1 - threshold) * ratio))
|
||||
{}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR T
|
||||
operator()(T const& x) const {
|
||||
return sprout::compost::detail::compress_value(x, threshold_, ratio_, gain_);
|
||||
}
|
||||
};
|
||||
|
||||
namespace effects {
|
||||
//
|
||||
// compress_holder
|
||||
//
|
||||
template<typename T>
|
||||
class compress_holder {
|
||||
public:
|
||||
typedef T value_type;
|
||||
private:
|
||||
value_type threshold_;
|
||||
value_type ratio_;
|
||||
public:
|
||||
compress_holder() = default;
|
||||
compress_holder(compress_holder const&) = default;
|
||||
SPROUT_CONSTEXPR compress_holder(value_type const& threshold, value_type const& ratio)
|
||||
: threshold_(threshold), ratio_(ratio)
|
||||
{}
|
||||
SPROUT_CONSTEXPR value_type const& threshold() const {
|
||||
return threshold_;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& ratio() const {
|
||||
return ratio_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// compressed_forwarder
|
||||
//
|
||||
class compressed_forwarder {
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::compost::effects::compress_holder<T>
|
||||
operator()(T const& threshold, T const& ratio) {
|
||||
return sprout::compost::effects::compress_holder<T>(threshold, ratio);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// compressed
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::compressed_forwarder compressed{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename T>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::effects::compress_holder<T> const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(sprout::compost::compress_value<T>(rhs.threshold(), rhs.ratio()))
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(sprout::compost::compress_value<T>(rhs.threshold(), rhs.ratio()))
|
||||
;
|
||||
}
|
||||
} // namespace effects
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_EFFECTS_COMPRESS_HPP
|
77
sprout/compost/effects/fuzz.hpp
Normal file
77
sprout/compost/effects/fuzz.hpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
#ifndef SPROUT_COMPOST_EFFECTS_FUZZ_HPP
|
||||
#define SPROUT_COMPOST_EFFECTS_FUZZ_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/range/adaptor/transformed.hpp>
|
||||
#include <sprout/compost/effects/rectify.hpp>
|
||||
#include <sprout/compost/effects/distort.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace effects {
|
||||
//
|
||||
// fuzz_holder
|
||||
//
|
||||
template<typename T>
|
||||
class fuzz_holder {
|
||||
public:
|
||||
typedef T value_type;
|
||||
private:
|
||||
value_type gain_;
|
||||
value_type level_;
|
||||
public:
|
||||
fuzz_holder() = default;
|
||||
fuzz_holder(fuzz_holder const&) = default;
|
||||
SPROUT_CONSTEXPR fuzz_holder(value_type const& gain, value_type const& level)
|
||||
: gain_(gain) , level_(level)
|
||||
{}
|
||||
SPROUT_CONSTEXPR value_type const& gain() const {
|
||||
return gain_;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& level() const {
|
||||
return level_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// fuzzed_forwarder
|
||||
//
|
||||
class fuzzed_forwarder {
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::compost::effects::fuzz_holder<T>
|
||||
operator()(T const& gain, T const& level) {
|
||||
return sprout::compost::effects::fuzz_holder<T>(gain, level);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// fuzzed
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::fuzzed_forwarder fuzzed{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename T>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::effects::fuzz_holder<T> const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::compost::effects::rectified
|
||||
| sprout::compost::effects::distorted(rhs.gain(), rhs.level())
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::compost::effects::rectified
|
||||
| sprout::compost::effects::distorted(rhs.gain(), rhs.level())
|
||||
;
|
||||
}
|
||||
} // namespace effects
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_EFFECTS_FUZZ_HPP
|
116
sprout/compost/effects/noise_gate.hpp
Normal file
116
sprout/compost/effects/noise_gate.hpp
Normal file
|
@ -0,0 +1,116 @@
|
|||
#ifndef SPROUT_COMPOST_EFFECTS_NOISE_GATE_HPP
|
||||
#define SPROUT_COMPOST_EFFECTS_NOISE_GATE_HPP
|
||||
|
||||
#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 {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::noise_gated_forwarder noise_gated{};
|
||||
} // 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
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_EFFECTS_NOISE_GATE_HPP
|
106
sprout/compost/effects/overdrive.hpp
Normal file
106
sprout/compost/effects/overdrive.hpp
Normal file
|
@ -0,0 +1,106 @@
|
|||
#ifndef SPROUT_COMPOST_EFFECTS_OVERDRIVE_HPP
|
||||
#define SPROUT_COMPOST_EFFECTS_OVERDRIVE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/math/constants.hpp>
|
||||
#include <sprout/math/atan.hpp>
|
||||
#include <sprout/range/adaptor/transformed.hpp>
|
||||
#include <sprout/compost/effects/change_volume.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
//
|
||||
// overdrive_clip_value
|
||||
//
|
||||
template<typename T = void>
|
||||
struct overdrive_clip_value {
|
||||
public:
|
||||
typedef T argument_type;
|
||||
typedef T result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR T
|
||||
operator()(T const& x) const {
|
||||
return x >= 0 ? sprout::math::atan(x) / sprout::math::half_pi<T>()
|
||||
: sprout::math::atan(x) / sprout::math::half_pi<T>() / 10
|
||||
;
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct overdrive_clip_value<void> {
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR T
|
||||
operator()(T const& x) const {
|
||||
return sprout::compost::overdrive_clip_value<T>()(x);
|
||||
}
|
||||
};
|
||||
|
||||
namespace effects {
|
||||
//
|
||||
// overdrive_holder
|
||||
//
|
||||
template<typename T>
|
||||
class overdrive_holder {
|
||||
public:
|
||||
typedef T value_type;
|
||||
private:
|
||||
value_type gain_;
|
||||
value_type level_;
|
||||
public:
|
||||
overdrive_holder() = default;
|
||||
overdrive_holder(overdrive_holder const&) = default;
|
||||
SPROUT_CONSTEXPR overdrive_holder(value_type const& gain, value_type const& level)
|
||||
: gain_(gain) , level_(level)
|
||||
{}
|
||||
SPROUT_CONSTEXPR value_type const& gain() const {
|
||||
return gain_;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& level() const {
|
||||
return level_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// overdriven_forwarder
|
||||
//
|
||||
class overdriven_forwarder {
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::compost::effects::overdrive_holder<T>
|
||||
operator()(T const& gain, T const& level) {
|
||||
return sprout::compost::effects::overdrive_holder<T>(gain, level);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// overdriven
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::overdriven_forwarder overdriven{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename T>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::effects::overdrive_holder<T> const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::compost::effects::changed_volume(rhs.gain())
|
||||
| sprout::adaptors::transformed(sprout::compost::overdrive_clip_value<>())
|
||||
| sprout::compost::effects::changed_volume(rhs.level())
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::compost::effects::changed_volume(rhs.gain())
|
||||
| sprout::adaptors::transformed(sprout::compost::overdrive_clip_value<>())
|
||||
| sprout::compost::effects::changed_volume(rhs.level())
|
||||
;
|
||||
}
|
||||
} // namespace effects
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_EFFECTS_OVERDRIVE_HPP
|
66
sprout/compost/effects/rectify.hpp
Normal file
66
sprout/compost/effects/rectify.hpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
#ifndef SPROUT_COMPOST_EFFECTS_RECTIFY_HPP
|
||||
#define SPROUT_COMPOST_EFFECTS_RECTIFY_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/range/adaptor/transformed.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
//
|
||||
// rectify_value
|
||||
//
|
||||
template<typename T = void>
|
||||
struct rectify_value {
|
||||
public:
|
||||
typedef T argument_type;
|
||||
typedef T result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR T
|
||||
operator()(T const& x) const {
|
||||
return x < 0 ? -x : x;
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct rectify_value<void> {
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR T
|
||||
operator()(T const& x) const {
|
||||
return sprout::compost::rectify_value<T>()(x);
|
||||
}
|
||||
};
|
||||
|
||||
namespace effects {
|
||||
//
|
||||
// rectified_forwarder
|
||||
//
|
||||
class rectified_forwarder {};
|
||||
|
||||
//
|
||||
// rectified
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::rectified_forwarder rectified{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::effects::rectified_forwarder const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(sprout::compost::rectify_value<>())
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(sprout::compost::rectify_value<>())
|
||||
;
|
||||
}
|
||||
} // namespace effects
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_EFFECTS_RECTIFY_HPP
|
149
sprout/compost/effects/reverb.hpp
Normal file
149
sprout/compost/effects/reverb.hpp
Normal file
|
@ -0,0 +1,149 @@
|
|||
#ifndef SPROUT_COMPOST_EFFECTS_REVERB_HPP
|
||||
#define SPROUT_COMPOST_EFFECTS_REVERB_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/math/constants.hpp>
|
||||
#include <sprout/math/pow.hpp>
|
||||
#include <sprout/range/adaptor/transformed.hpp>
|
||||
#include <sprout/range/adaptor/outdirected.hpp>
|
||||
#include <sprout/range/adaptor/indexed.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
//
|
||||
// reverb_outdirected_value
|
||||
//
|
||||
template<typename Value, typename IntType>
|
||||
struct reverb_outdirected_value {
|
||||
public:
|
||||
typedef Value value_type;
|
||||
typedef IntType int_type;
|
||||
private:
|
||||
value_type attenuation_;
|
||||
value_type delay_;
|
||||
std::size_t repeat_;
|
||||
int_type samples_per_sec_;
|
||||
private:
|
||||
template<typename Outdirected>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Outdirected>::value_type
|
||||
calc_1(Outdirected const& x, std::size_t i, typename Outdirected::index_type m) const {
|
||||
return m >= 0 ? sprout::math::pow(attenuation_, i) * x[m - x.index()]
|
||||
: 0
|
||||
;
|
||||
}
|
||||
template<typename Outdirected>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Outdirected>::value_type
|
||||
calc(Outdirected const& x, std::size_t i = 1) const {
|
||||
return i <= repeat_
|
||||
? calc_1(x, i, static_cast<typename Outdirected::index_type>(x.index() - i * delay_ * samples_per_sec_)) + calc(x, i + 1)
|
||||
: 0
|
||||
;
|
||||
}
|
||||
public:
|
||||
SPROUT_CONSTEXPR reverb_outdirected_value(
|
||||
value_type const& attenuation, value_type const& delay,
|
||||
std::size_t repeat = 2, int_type samples_per_sec = 44100
|
||||
)
|
||||
: attenuation_(attenuation), delay_(delay), repeat_(repeat), samples_per_sec_(samples_per_sec)
|
||||
{}
|
||||
template<typename Outdirected>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Outdirected>::value_type
|
||||
operator()(Outdirected const& x) const {
|
||||
return *x + calc(x);
|
||||
}
|
||||
};
|
||||
|
||||
namespace effects {
|
||||
//
|
||||
// reverb_holder
|
||||
//
|
||||
template<typename T, typename IntType = int>
|
||||
class reverb_holder {
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef IntType int_type;
|
||||
private:
|
||||
value_type attenuation_;
|
||||
value_type delay_;
|
||||
std::size_t repeat_;
|
||||
int_type samples_per_sec_;
|
||||
public:
|
||||
reverb_holder() = default;
|
||||
reverb_holder(reverb_holder const&) = default;
|
||||
SPROUT_CONSTEXPR reverb_holder(
|
||||
value_type const& attenuation, value_type const& delay,
|
||||
std::size_t repeat = 2, int_type samples_per_sec = 44100
|
||||
)
|
||||
: attenuation_(attenuation), delay_(delay), repeat_(repeat), samples_per_sec_(samples_per_sec)
|
||||
{}
|
||||
SPROUT_CONSTEXPR value_type const& attenuation() const {
|
||||
return attenuation_;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& delay() const {
|
||||
return delay_;
|
||||
}
|
||||
SPROUT_CONSTEXPR std::size_t const& repeat() const {
|
||||
return repeat_;
|
||||
}
|
||||
SPROUT_CONSTEXPR int_type const& samples_per_sec() const {
|
||||
return samples_per_sec_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// reverbed_forwarder
|
||||
//
|
||||
class reverbed_forwarder {
|
||||
public:
|
||||
template<typename T, typename IntType>
|
||||
SPROUT_CONSTEXPR sprout::compost::effects::reverb_holder<T, IntType>
|
||||
operator()(T const& attenuation, T const& delay, std::size_t repeat, IntType samples_per_sec) {
|
||||
return sprout::compost::effects::reverb_holder<T, IntType>(attenuation, delay, repeat, samples_per_sec);
|
||||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::compost::effects::reverb_holder<T>
|
||||
operator()(T const& attenuation, T const& delay, std::size_t repeat = 2) {
|
||||
return sprout::compost::effects::reverb_holder<T>(attenuation, delay, repeat);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// reverbed
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::reverbed_forwarder reverbed{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename T, typename IntType>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::effects::reverb_holder<T, IntType> const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::indexed | sprout::adaptors::outdirected
|
||||
| sprout::adaptors::transformed(
|
||||
sprout::compost::reverb_outdirected_value<T, IntType>(
|
||||
rhs.attenuation(), rhs.delay(), rhs.repeat(), rhs.samples_per_sec()
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::indexed | sprout::adaptors::outdirected
|
||||
| sprout::adaptors::transformed(
|
||||
sprout::compost::reverb_outdirected_value<T, IntType>(
|
||||
rhs.attenuation(), rhs.delay(), rhs.repeat(), rhs.samples_per_sec()
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
} // namespace effects
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_EFFECTS_REVERB_HPP
|
117
sprout/compost/effects/tremolo.hpp
Normal file
117
sprout/compost/effects/tremolo.hpp
Normal file
|
@ -0,0 +1,117 @@
|
|||
#ifndef SPROUT_COMPOST_EFFECTS_TREMOLO_HPP
|
||||
#define SPROUT_COMPOST_EFFECTS_TREMOLO_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/math/constants.hpp>
|
||||
#include <sprout/math/sin.hpp>
|
||||
#include <sprout/range/adaptor/transformed.hpp>
|
||||
#include <sprout/range/adaptor/outdirected.hpp>
|
||||
#include <sprout/range/adaptor/indexed.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
//
|
||||
// tremolo_outdirected_value
|
||||
//
|
||||
template<typename Value, typename IntType>
|
||||
struct tremolo_outdirected_value {
|
||||
public:
|
||||
typedef Value value_type;
|
||||
typedef IntType int_type;
|
||||
private:
|
||||
value_type depth_;
|
||||
value_type rate_;
|
||||
int_type samples_per_sec_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR tremolo_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<typename Outdirected>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Outdirected>::value_type
|
||||
operator()(Outdirected const& x) const {
|
||||
return (1 + depth_ * sprout::math::sin(2 * sprout::math::pi<Value>() * rate_ * x.index() / samples_per_sec_)) * *x;
|
||||
}
|
||||
};
|
||||
|
||||
namespace effects {
|
||||
//
|
||||
// tremolo_holder
|
||||
//
|
||||
template<typename T, typename IntType = int>
|
||||
class tremolo_holder {
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef IntType int_type;
|
||||
private:
|
||||
value_type depth_;
|
||||
value_type rate_;
|
||||
int_type samples_per_sec_;
|
||||
public:
|
||||
tremolo_holder() = default;
|
||||
tremolo_holder(tremolo_holder const&) = default;
|
||||
SPROUT_CONSTEXPR tremolo_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_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// tremolo_forwarder
|
||||
//
|
||||
class tremolo_forwarder {
|
||||
public:
|
||||
template<typename T, typename IntType>
|
||||
SPROUT_CONSTEXPR sprout::compost::effects::tremolo_holder<T, IntType>
|
||||
operator()(T const& depth, T const& rate, IntType samples_per_sec) {
|
||||
return sprout::compost::effects::tremolo_holder<T, IntType>(depth, rate, samples_per_sec);
|
||||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::compost::effects::tremolo_holder<T>
|
||||
operator()(T const& depth, T const& rate) {
|
||||
return sprout::compost::effects::tremolo_holder<T>(depth, rate);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// tremolo
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::tremolo_forwarder tremolo{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename T, typename IntType>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::effects::tremolo_holder<T, IntType> const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::indexed | sprout::adaptors::outdirected
|
||||
| sprout::adaptors::transformed(
|
||||
sprout::compost::tremolo_outdirected_value<T, IntType>(rhs.depth(), rhs.rate(), rhs.samples_per_sec())
|
||||
)
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::indexed | sprout::adaptors::outdirected
|
||||
| sprout::adaptors::transformed(
|
||||
sprout::compost::tremolo_outdirected_value<T, IntType>(rhs.depth(), rhs.rate(), rhs.samples_per_sec())
|
||||
)
|
||||
;
|
||||
}
|
||||
} // namespace effects
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_EFFECTS_TREMOLO_HPP
|
155
sprout/compost/effects/vibrato.hpp
Normal file
155
sprout/compost/effects/vibrato.hpp
Normal file
|
@ -0,0 +1,155 @@
|
|||
#ifndef SPROUT_COMPOST_EFFECTS_VIBRATO_HPP
|
||||
#define SPROUT_COMPOST_EFFECTS_VIBRATO_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/math/constants.hpp>
|
||||
#include <sprout/math/sin.hpp>
|
||||
#include <sprout/range/adaptor/transformed.hpp>
|
||||
#include <sprout/range/adaptor/outdirected.hpp>
|
||||
#include <sprout/range/adaptor/indexed.hpp>
|
||||
#include <sprout/range/adaptor/valued.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
//
|
||||
// vibrato_outdirected_value
|
||||
//
|
||||
template<typename Value, typename IntType>
|
||||
struct vibrato_outdirected_value {
|
||||
public:
|
||||
typedef Value value_type;
|
||||
typedef IntType int_type;
|
||||
private:
|
||||
value_type d_;
|
||||
value_type depth_;
|
||||
value_type rate_;
|
||||
int_type samples_per_sec_;
|
||||
private:
|
||||
template<typename Outdirected>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Outdirected>::value_type
|
||||
calc_2(Outdirected const& x, typename Outdirected::index_type m, value_type const& delta) const {
|
||||
return m >= 0 && (m + 1 < x.base().get() || x.base().get() < 0)
|
||||
? delta * x[m + 1 - x.index()] + (1 - delta) * x[m - x.index()]
|
||||
: *x
|
||||
;
|
||||
}
|
||||
template<typename Outdirected>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Outdirected>::value_type
|
||||
calc_1(Outdirected const& x, value_type const& tau, value_type const& t) const {
|
||||
return calc_2(x, static_cast<typename Outdirected::index_type>(t), t - static_cast<typename Outdirected::index_type>(t));
|
||||
}
|
||||
template<typename Outdirected>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Outdirected>::value_type
|
||||
calc(Outdirected const& x, value_type const& tau) const {
|
||||
return calc_1(x, tau, x.index() - tau);
|
||||
}
|
||||
public:
|
||||
SPROUT_CONSTEXPR vibrato_outdirected_value(
|
||||
value_type const& d, value_type const& depth, value_type const& rate,
|
||||
int_type samples_per_sec = 44100
|
||||
)
|
||||
: d_(d), depth_(depth), rate_(rate), samples_per_sec_(samples_per_sec)
|
||||
{}
|
||||
template<typename Outdirected>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Outdirected>::value_type
|
||||
operator()(Outdirected const& x) const {
|
||||
return calc(x, d_ + depth_ * sprout::math::sin(2 * sprout::math::pi<Value>() * rate_ * x.index() / samples_per_sec_));
|
||||
}
|
||||
};
|
||||
|
||||
namespace effects {
|
||||
//
|
||||
// vibrato_holder
|
||||
//
|
||||
template<typename T, typename IntType = int>
|
||||
class vibrato_holder {
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef IntType int_type;
|
||||
private:
|
||||
value_type d_;
|
||||
value_type depth_;
|
||||
value_type rate_;
|
||||
int_type samples_per_sec_;
|
||||
public:
|
||||
vibrato_holder() = default;
|
||||
vibrato_holder(vibrato_holder const&) = default;
|
||||
SPROUT_CONSTEXPR vibrato_holder(
|
||||
value_type const& d, value_type const& depth, value_type const& rate,
|
||||
int_type samples_per_sec = 44100
|
||||
)
|
||||
: d_(d), depth_(depth), rate_(rate), samples_per_sec_(samples_per_sec)
|
||||
{}
|
||||
SPROUT_CONSTEXPR value_type const& d() const {
|
||||
return d_;
|
||||
}
|
||||
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_;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// vibrato_forwarder
|
||||
//
|
||||
class vibrato_forwarder {
|
||||
public:
|
||||
template<typename T, typename IntType>
|
||||
SPROUT_CONSTEXPR sprout::compost::effects::vibrato_holder<T, IntType>
|
||||
operator()(T const& d, T const& depth, T const& rate, IntType samples_per_sec) {
|
||||
return sprout::compost::effects::vibrato_holder<T, IntType>(d, depth, rate, samples_per_sec);
|
||||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::compost::effects::vibrato_holder<T>
|
||||
operator()(T const& d, T const& depth, T const& rate) {
|
||||
return sprout::compost::effects::vibrato_holder<T>(d, depth, rate);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// vibrato
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::vibrato_forwarder vibrato{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range, typename T, typename IntType>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::effects::vibrato_holder<T, IntType> const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::valued(sprout::size(sprout::forward<Range>(lhs)))
|
||||
| sprout::adaptors::indexed | sprout::adaptors::outdirected
|
||||
| sprout::adaptors::transformed(
|
||||
sprout::compost::vibrato_outdirected_value<T, IntType>(
|
||||
rhs.d(), rhs.depth(), rhs.rate(), rhs.samples_per_sec()
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::valued(sprout::size(sprout::forward<Range>(lhs)))
|
||||
| sprout::adaptors::indexed | sprout::adaptors::outdirected
|
||||
| sprout::adaptors::transformed(
|
||||
sprout::compost::vibrato_outdirected_value<T, IntType>(
|
||||
rhs.d(), rhs.depth(), rhs.rate(), rhs.samples_per_sec()
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
} // namespace effects
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_EFFECTS_VIBRATO_HPP
|
Loading…
Add table
Add a link
Reference in a new issue