1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-10-05 13:00:00 +00:00

fix weed warnings.

add compost library.
This commit is contained in:
bolero-MURAKAMI 2012-11-09 01:09:49 +09:00
commit d01ee064e2
31 changed files with 1566 additions and 120 deletions

View file

@ -0,0 +1,10 @@
#ifndef SPROUT_COMPOST_EFFECTS_HPP
#define SPROUT_COMPOST_EFFECTS_HPP
#include <sprout/config.hpp>
#include <sprout/compost/effects/clip.hpp>
#include <sprout/compost/effects/change_volume.hpp>
#include <sprout/compost/effects/distort.hpp>
#include <sprout/compost/effects/synthesize.hpp>
#endif // #ifndef SPROUT_COMPOST_EFFECTS_HPP

View file

@ -0,0 +1,71 @@
#ifndef SPROUT_COMPOST_EFFECTS_CHANGE_VOLUME_HPP
#define SPROUT_COMPOST_EFFECTS_CHANGE_VOLUME_HPP
#include <sprout/config.hpp>
#include <sprout/functional/multiplies.hpp>
#include <sprout/functional/bind2nd.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/range/adaptor/transformed.hpp>
namespace sprout {
namespace compost {
namespace effects {
//
// change_volume_holder
//
template<typename T>
class change_volume_holder {
public:
typedef T value_type;
private:
value_type value_;
public:
change_volume_holder() = default;
change_volume_holder(change_volume_holder const&) = default;
explicit SPROUT_CONSTEXPR change_volume_holder(value_type const& value)
: value_(value)
{}
SPROUT_CONSTEXPR value_type const& value() const {
return value_;
}
};
//
// changed_volume_forwarder
//
class changed_volume_forwarder {
public:
template<typename T>
SPROUT_CONSTEXPR sprout::compost::effects::change_volume_holder<T>
operator()(T const& value) {
return sprout::compost::effects::change_volume_holder<T>(value);
}
};
//
// changed_volume
//
namespace {
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::changed_volume_forwarder changed_volume{};
} // anonymous-namespace
//
// operator|
//
template<typename Range, typename T>
inline SPROUT_CONSTEXPR auto
operator|(Range&& lhs, sprout::compost::effects::change_volume_holder<T> const& rhs)
-> decltype(
sprout::forward<Range>(lhs)
| sprout::adaptors::transformed(sprout::bind2nd(sprout::multiplies<>(), rhs.value()))
)
{
return sprout::forward<Range>(lhs)
| sprout::adaptors::transformed(sprout::bind2nd(sprout::multiplies<>(), rhs.value()))
;
}
} // namespace effects
} // namespace compost
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_EFFECTS_CHANGE_VOLUME_HPP

View file

@ -0,0 +1,85 @@
#ifndef SPROUT_COMPOST_EFFECTS_CLIP_HPP
#define SPROUT_COMPOST_EFFECTS_CLIP_HPP
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/range/adaptor/clamped.hpp>
namespace sprout {
namespace compost {
namespace effects {
//
// clip_holder
//
template<typename T>
class clip_holder {
public:
typedef T value_type;
private:
value_type low_;
value_type up_;
public:
clip_holder() = default;
clip_holder(clip_holder const&) = default;
explicit SPROUT_CONSTEXPR clip_holder(value_type const& low = -1, value_type const& up = 1)
: low_(low), up_(up)
{}
SPROUT_CONSTEXPR value_type const& lower() const {
return low_;
}
SPROUT_CONSTEXPR value_type const& upper() const {
return up_;
}
};
//
// clipped_forwarder
//
class clipped_forwarder {
public:
template<typename T = double>
SPROUT_CONSTEXPR sprout::compost::effects::clip_holder<T>
operator()(T const& low = -1, T const& up = 1) {
return sprout::compost::effects::clip_holder<T>(low, up);
}
};
//
// clipped
//
namespace {
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::clipped_forwarder clipped{};
} // anonymous-namespace
//
// operator|
//
template<typename Range, typename T>
inline SPROUT_CONSTEXPR auto
operator|(Range&& lhs, sprout::compost::effects::clip_holder<T> const& rhs)
-> decltype(
sprout::forward<Range>(lhs)
| sprout::adaptors::clamped(rhs.lower(), rhs.upper())
)
{
return sprout::forward<Range>(lhs)
| sprout::adaptors::clamped(rhs.lower(), rhs.upper())
;
}
template<typename Range>
inline SPROUT_CONSTEXPR auto
operator|(Range&& lhs, sprout::compost::effects::clipped_forwarder const& rhs)
-> decltype(
sprout::forward<Range>(lhs)
| sprout::adaptors::clamped(-1., 1.)
)
{
return sprout::forward<Range>(lhs)
| sprout::adaptors::clamped(-1., 1.)
;
}
} // namespace effects
} // namespace compost
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_EFFECTS_CLIP_HPP

View file

@ -0,0 +1,78 @@
#ifndef SPROUT_COMPOST_EFFECTS_DISTORT_HPP
#define SPROUT_COMPOST_EFFECTS_DISTORT_HPP
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/compost/effects/clip.hpp>
#include <sprout/compost/effects/change_volume.hpp>
namespace sprout {
namespace compost {
namespace effects {
//
// distort_holder
//
template<typename T>
class distort_holder {
public:
typedef T value_type;
private:
value_type gain_;
value_type level_;
public:
distort_holder() = default;
distort_holder(distort_holder const&) = default;
SPROUT_CONSTEXPR distort_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_;
}
};
//
// distorted_forwarder
//
class distorted_forwarder {
public:
template<typename T>
SPROUT_CONSTEXPR sprout::compost::effects::distort_holder<T>
operator()(T const& gain, T const& level) {
return sprout::compost::effects::distort_holder<T>(gain, level);
}
};
//
// distorted
//
namespace {
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::distorted_forwarder distorted{};
} // anonymous-namespace
//
// operator|
//
template<typename Range, typename T>
inline SPROUT_CONSTEXPR auto
operator|(Range&& lhs, sprout::compost::effects::distort_holder<T> const& rhs)
-> decltype(
sprout::forward<Range>(lhs)
| sprout::compost::effects::changed_volume(rhs.gain())
| sprout::compost::effects::clipped()
| sprout::compost::effects::changed_volume(rhs.level())
)
{
return sprout::forward<Range>(lhs)
| sprout::compost::effects::changed_volume(rhs.gain())
| sprout::compost::effects::clipped()
| sprout::compost::effects::changed_volume(rhs.level())
;
}
} // namespace effects
} // namespace compost
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_EFFECTS_DISTORT_HPP

View file

@ -0,0 +1,77 @@
#ifndef SPROUT_COMPOST_EFFECTS_SYNTHESIZED_HPP
#define SPROUT_COMPOST_EFFECTS_SYNTHESIZED_HPP
#include <sprout/config.hpp>
#include <sprout/functional/plus.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/utility/value_holder.hpp>
#include <sprout/range/adaptor/transformed.hpp>
namespace sprout {
namespace compost {
namespace effects {
//
// synthesize_holder
//
template<typename RRange>
class synthesize_holder {
public:
typedef RRange range2_type;
private:
sprout::value_holder<range2_type&> range_;
public:
synthesize_holder() = default;
synthesize_holder(synthesize_holder const&) = default;
explicit SPROUT_CONSTEXPR synthesize_holder(range2_type& range)
: range_(range)
{}
SPROUT_CONSTEXPR range2_type& range() const {
return range_;
}
};
//
// synthesized_forwarder
//
class synthesized_forwarder {
public:
template<typename RRange>
SPROUT_CONSTEXPR sprout::compost::effects::synthesize_holder<
typename std::remove_reference<typename sprout::lvalue_reference<RRange>::type>::type
>
operator()(RRange&& range) {
return sprout::compost::effects::synthesize_holder<
typename std::remove_reference<typename sprout::lvalue_reference<RRange>::type>::type
>(
sprout::lvalue_forward<RRange>(range)
);
}
};
//
// synthesized
//
namespace {
SPROUT_STATIC_CONSTEXPR sprout::compost::effects::synthesized_forwarder synthesized{};
} // anonymous-namespace
//
// operator|
//
template<typename Range, typename T>
inline SPROUT_CONSTEXPR auto
operator|(Range&& lhs, sprout::compost::effects::synthesize_holder<T> const& rhs)
-> decltype(
sprout::forward<Range>(lhs)
| sprout::adaptors::transformed(rhs.range(), sprout::plus<>())
)
{
return sprout::forward<Range>(lhs)
| sprout::adaptors::transformed(rhs.range(), sprout::plus<>())
;
}
} // namespace effects
} // namespace compost
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_EFFECTS_SYNTHESIZED_HPP

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_COMPOST_FORMATS_HPP
#define SPROUT_COMPOST_FORMATS_HPP
#include <sprout/config.hpp>
#include <sprout/compost/formats/as_pcm_wave.hpp>
#endif // #ifndef SPROUT_COMPOST_FORMATS_HPP

View file

@ -0,0 +1,92 @@
#ifndef SPROUT_COMPOST_FORMATS_AS_PCM_WAVE_HPP
#define SPROUT_COMPOST_FORMATS_AS_PCM_WAVE_HPP
#include <cstdint>
#include <limits>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/algorithm/clamp.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/type_traits/is_int.hpp>
#include <sprout/type_traits/is_uint.hpp>
#include <sprout/range/adaptor/transformed.hpp>
namespace sprout {
namespace compost {
namespace formats {
//
// normalized_to_pcm_wave
//
template<typename IntType, typename = void>
struct normalized_to_pcm_wave;
template<typename IntType>
struct normalized_to_pcm_wave<
IntType,
typename std::enable_if<sprout::is_int<IntType>::value>::type
> {
public:
typedef IntType result_type;
public:
template<typename T>
SPROUT_CONSTEXPR result_type operator()(T const& x) const {
return static_cast<result_type>(sprout::clamp(x, -1, 1) * std::numeric_limits<result_type>::max());
}
};
template<typename IntType>
struct normalized_to_pcm_wave<
IntType,
typename std::enable_if<sprout::is_uint<IntType>::value>::type
> {
public:
typedef IntType result_type;
public:
template<typename T>
SPROUT_CONSTEXPR result_type operator()(T const& x) const {
return static_cast<result_type>(sprout::clamp((x + 1) / 2, 0, 1) * std::numeric_limits<result_type>::max());
}
};
//
// as_pcm_wave_forwarder
//
template<typename IntType>
class as_pcm_wave_forwarder {};
//
// as_pcm_wave
//
template<typename IntType>
inline SPROUT_CONSTEXPR sprout::compost::formats::as_pcm_wave_forwarder<IntType>
as_pcm_wave() {
return sprout::compost::formats::as_pcm_wave_forwarder<IntType>();
}
//
// operator|
//
template<typename Range, typename IntType>
inline SPROUT_CONSTEXPR auto
operator|(Range&& lhs, sprout::compost::formats::as_pcm_wave_forwarder<IntType> const& rhs)
-> decltype(
sprout::forward<Range>(lhs)
| sprout::adaptors::transformed(sprout::compost::formats::normalized_to_pcm_wave<IntType>())
)
{
return sprout::forward<Range>(lhs)
| sprout::adaptors::transformed(sprout::compost::formats::normalized_to_pcm_wave<IntType>())
;
}
//
// as_pcm_wave8
// as_pcm_wave16
//
namespace {
SPROUT_STATIC_CONSTEXPR sprout::compost::formats::as_pcm_wave_forwarder<std::uint8_t> as_pcm_wave8{};
SPROUT_STATIC_CONSTEXPR sprout::compost::formats::as_pcm_wave_forwarder<std::int16_t> as_pcm_wave16{};
} // anonymous-namespace
} // namespace formats
} // namespace compost
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_FORMATS_AS_PCM_WAVE_HPP

View file

@ -0,0 +1,68 @@
#ifndef COMPOST_DEF_LOAD_SOURCE_IDENTIFIER
# error should define COMPOST_DEF_LOAD_SOURCE_IDENTIFIER.
#endif
#ifndef COMPOST_DEF_LOAD_SOURCE_FILE
# error should define COMPOST_DEF_LOAD_SOURCE_FILE.
#endif
#ifndef COMPOST_DEF_LOAD_SOURCE_DATA_INDEX
# define COMPOST_DEF_LOAD_SOURCE_DATA_INDEX -1
#endif
#define COMPOST_LOAD_IDENTIFIER_DETAIL_CAT(id, suffix) COMPOST_LOAD_IDENTIFIER_DETAIL_CAT_I(id, suffix)
#define COMPOST_LOAD_IDENTIFIER_DETAIL_CAT_I(id, suffix) COMPOST_LOAD_IDENTIFIER_DETAIL_CAT_II(id ## suffix)
#define COMPOST_LOAD_IDENTIFIER_DETAIL_CAT_II(res) res
#define COMPOST_LOAD_DETAIL_IDENTIFIER(id) COMPOST_LOAD_IDENTIFIER_DETAIL_CAT( \
COMPOST_LOAD_IDENTIFIER_DETAIL_CAT(COMPOST_DEF_LOAD_SOURCE_IDENTIFIER, id), \
_compost_load_source_detail \
)
#define COMPOST_LOAD_IDENTIFIER COMPOST_DEF_LOAD_SOURCE_IDENTIFIER
#ifdef COMPOST_DEF_LOAD_INFO_IDENTIFIER
# define COMPOST_LOAD_INFO_IDENTIFIER COMPOST_DEF_LOAD_INFO_IDENTIFIER
#else
# define COMPOST_LOAD_INFO_IDENTIFIER COMPOST_LOAD_DETAIL_IDENTIFIER(info)
#endif
SPROUT_STATIC_CONSTEXPR sprout::compost::sources::version_type COMPOST_LOAD_DETAIL_IDENTIFIER(version) =
# define COMPOST_LOADING_SOURCE_VERSION
# include COMPOST_DEF_LOAD_SOURCE_FILE
# undef COMPOST_LOADING_SOURCE_VERSION
;
static_assert(COMPOST_LOAD_DETAIL_IDENTIFIER(version) <= 0, "Unsupported compost src version");
SPROUT_STATIC_CONSTEXPR sprout::compost::sources::info_type COMPOST_LOAD_INFO_IDENTIFIER = {
# define COMPOST_LOADING_SOURCE_INFO
# include COMPOST_DEF_LOAD_SOURCE_FILE
# undef COMPOST_LOADING_SOURCE_INFO
};
SPROUT_STATIC_CONSTEXPR sprout::compost::sources::sound_type<
COMPOST_LOAD_INFO_IDENTIFIER.size
> COMPOST_LOAD_IDENTIFIER(
COMPOST_LOAD_INFO_IDENTIFIER,
# define COMPOST_LOADING_SOURCE_DATA
# define COMPOST_LOADING_SOURCE_DATA_INDEX COMPOST_DEF_LOAD_SOURCE_DATA_INDEX
# include COMPOST_DEF_LOAD_SOURCE_FILE
# undef COMPOST_LOADING_SOURCE_DATA_INDEX
# undef COMPOST_LOADING_SOURCE_DATA
);
#undef COMPOST_LOAD_IDENTIFIER
#undef COMPOST_LOAD_INFO_IDENTIFIER
#undef COMPOST_LOAD_DETAIL_IDENTIFIER
#undef COMPOST_LOAD_IDENTIFIER_DETAIL_CAT
#undef COMPOST_LOAD_IDENTIFIER_DETAIL_CAT_I
#undef COMPOST_LOAD_IDENTIFIER_DETAIL_CAT_II
#undef COMPOST_DEF_LOAD_SOURCE_IDENTIFIER
#undef COMPOST_DEF_LOAD_SOURCE_FILE
#ifdef COMPOST_DEF_LOAD_INFO_IDENTIFIER
# undef COMPOST_DEF_LOAD_INFO_IDENTIFIER
#endif

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_COMPOST_SOURCES_HPP
#define SPROUT_COMPOST_SOURCES_HPP
#include <sprout/config.hpp>
#include <sprout/compost/sources/source.hpp>
#endif // #ifndef SPROUT_COMPOST_SOURCES_HPP

View file

@ -0,0 +1,80 @@
#ifndef SPROUT_COMPOST_SOURCES_SOURCE_HPP
#define SPROUT_COMPOST_SOURCES_SOURCE_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/array.hpp>
//
// COMPOST_LOAD_SOURCE
//
#define COMPOST_LOAD_SOURCE <sprout/compost/load/source.hpp>
//
// COMPOST_SRC_VERSION
//
#define COMPOST_SRC_VERSION(NUM) NUM
namespace sprout {
namespace compost {
namespace sources {
//
// version_type
//
typedef unsigned long version_type;
//
// info_type
//
struct info_type {
public:
std::uint16_t format_tag; // フォーマットID
std::uint16_t channels; // チャンネル数
std::uint32_t samples_per_sec; // サンプリングレート
std::uint32_t bytes_per_sec; // データ速度 (Byte/sec)
std::uint16_t block_size; // ブロックサイズ (Byte/sample*チャンネル数)
std::uint16_t bits_per_sample; // サンプルあたりのビット数 (bit/sample)
std::size_t size; // 要素数
};
//
// sound_type
//
template<std::size_t Size, typename Elem = double>
struct sound_type {
public:
typedef Elem element_type;
typedef element_type value_type;
typedef std::size_t size_type;
SPROUT_STATIC_CONSTEXPR size_type static_size = Size;
typedef sprout::array<value_type, static_size> elements_type;
private:
elements_type elements_;
public:
template<typename... Elems>
SPROUT_CONSTEXPR sound_type(info_type const& info, Elems const&... elems)
: elements_{{
(static_cast<typename std::make_signed<Elems>::type>(elems) / static_cast<value_type>(32768.0))...
}}
{
static_assert(sizeof...(Elems) == static_size, "sound_type<>: unmatch source size");
}
SPROUT_CONSTEXPR value_type const&
operator()(size_type x) const {
return elements_[x];
}
SPROUT_CONSTEXPR size_type
size() const {
return static_size;
}
SPROUT_CONSTEXPR elements_type const&
elements() const {
return elements_;
}
};
template<std::size_t Size, typename Elem>
SPROUT_CONSTEXPR_OR_CONST typename sprout::compost::sources::sound_type<Size, Elem>::size_type
sprout::compost::sources::sound_type<Size, Elem>::static_size;
} // namespace sources
} // namespace compost
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_SOURCES_SOURCE_HPP

11
sprout/compost/waves.hpp Normal file
View file

@ -0,0 +1,11 @@
#ifndef SPROUT_COMPOST_WAVES_HPP
#define SPROUT_COMPOST_WAVES_HPP
#include <sprout/config.hpp>
#include <sprout/compost/waves/sinusoidal.hpp>
#include <sprout/compost/waves/sawtooth_wave.hpp>
#include <sprout/compost/waves/triangle_wave.hpp>
#include <sprout/compost/waves/square_wave.hpp>
#include <sprout/compost/waves/white_noise.hpp>
#endif // #ifndef SPROUT_COMPOST_WAVES_HPP

View file

@ -0,0 +1,20 @@
#ifndef SPROUT_COMPOST_WAVES_SAWTOOTH_WAVE_HPP
#define SPROUT_COMPOST_WAVES_SAWTOOTH_WAVE_HPP
#include <sprout/config.hpp>
#include <sprout/range/adaptor/sawtooth_wave.hpp>
namespace sprout {
namespace compost {
namespace waves {
//
// sawtooth_wave
//
namespace {
SPROUT_STATIC_CONSTEXPR sprout::adaptors::sawtooth_wave_forwarder sawtooth_wave{};
} // anonymous-namespace
} // namespace waves
} // namespace compost
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_WAVES_SAWTOOTH_WAVE_HPP

View file

@ -0,0 +1,20 @@
#ifndef SPROUT_COMPOST_WAVES_SINUSOIDAL_HPP
#define SPROUT_COMPOST_WAVES_SINUSOIDAL_HPP
#include <sprout/config.hpp>
#include <sprout/range/adaptor/sinusoidal.hpp>
namespace sprout {
namespace compost {
namespace waves {
//
// sinusoidal
//
namespace {
SPROUT_STATIC_CONSTEXPR sprout::adaptors::sinusoidal_forwarder sinusoidal{};
} // anonymous-namespace
} // namespace waves
} // namespace compost
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_WAVES_SINUSOIDAL_HPP

View file

@ -0,0 +1,20 @@
#ifndef SPROUT_COMPOST_WAVES_SQUARE_WAVE_HPP
#define SPROUT_COMPOST_WAVES_SQUARE_WAVE_HPP
#include <sprout/config.hpp>
#include <sprout/range/adaptor/square_wave.hpp>
namespace sprout {
namespace compost {
namespace waves {
//
// square_wave
//
namespace {
SPROUT_STATIC_CONSTEXPR sprout::adaptors::square_wave_forwarder square_wave{};
} // anonymous-namespace
} // namespace waves
} // namespace compost
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_WAVES_SQUARE_WAVE_HPP

View file

@ -0,0 +1,20 @@
#ifndef SPROUT_COMPOST_WAVES_TRIANGLE_WAVE_HPP
#define SPROUT_COMPOST_WAVES_TRIANGLE_WAVE_HPP
#include <sprout/config.hpp>
#include <sprout/range/adaptor/triangle_wave.hpp>
namespace sprout {
namespace compost {
namespace waves {
//
// triangle_wave
//
namespace {
SPROUT_STATIC_CONSTEXPR sprout::adaptors::triangle_wave_forwarder triangle_wave{};
} // anonymous-namespace
} // namespace waves
} // namespace compost
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_WAVES_TRIANGLE_WAVE_HPP

View file

@ -0,0 +1,179 @@
#ifndef SPROUT_COMPOST_WAVES_WHITE_NOISE_HPP
#define SPROUT_COMPOST_WAVES_WHITE_NOISE_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/pit.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/generator_iterator.hpp>
#include <sprout/range/range_container.hpp>
#include <sprout/range/algorithm/copy.hpp>
#include <sprout/type_traits/lvalue_reference.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/utility/lvalue_forward.hpp>
#include <sprout/random/normal_distribution.hpp>
#include <sprout/random/random_result.hpp>
namespace sprout {
namespace compost {
namespace waves {
//
// white_noise_range
//
template<typename Value, typename UniformRandomNumberGenerator, typename Range = void>
class white_noise_range
: public sprout::range::range_container<
sprout::generator_iterator<
sprout::random::random_result<UniformRandomNumberGenerator, sprout::random::normal_distribution<Value> >
>
>
, public sprout::detail::container_nosy_static_size<Range>
, public sprout::detail::container_nosy_fixed_size<Range>
{
public:
typedef Range range_type;
typedef sprout::range::range_container<
sprout::generator_iterator<
sprout::random::random_result<UniformRandomNumberGenerator, sprout::random::normal_distribution<Value> >
>
> base_type;
typedef typename base_type::iterator iterator;
typedef typename base_type::value_type value_type;
typedef typename base_type::difference_type difference_type;
typedef typename iterator::generator_type generator_type;
typedef typename generator_type::engine_type engine_type;
typedef typename generator_type::distribution_type distribution_type;
public:
white_noise_range() = default;
white_noise_range(white_noise_range const&) = default;
explicit SPROUT_CONSTEXPR white_noise_range(
range_type& range,
engine_type const& gen,
value_type const& sigma = 1
)
: base_type(
iterator(distribution_type(0, sigma)(gen), sprout::size(range)),
iterator()
)
{}
SPROUT_CONSTEXPR engine_type const& engine() const {
return base_type::begin().generator().engine();
}
SPROUT_CONSTEXPR value_type const& sigma() const {
return base_type::begin().generator().distribution().sigma();
}
};
template<typename Value, typename UniformRandomNumberGenerator>
class white_noise_range<Value, UniformRandomNumberGenerator, void>
: public sprout::range::range_container<
sprout::generator_iterator<
sprout::random::random_result<UniformRandomNumberGenerator, sprout::random::normal_distribution<Value> >
>
>
{
public:
typedef sprout::range::range_container<
sprout::generator_iterator<
sprout::random::random_result<UniformRandomNumberGenerator, sprout::random::normal_distribution<Value> >
>
> base_type;
typedef typename base_type::iterator iterator;
typedef typename base_type::value_type value_type;
typedef typename base_type::difference_type difference_type;
typedef typename iterator::generator_type generator_type;
typedef typename generator_type::engine_type engine_type;
typedef typename generator_type::distribution_type distribution_type;
public:
white_noise_range() = default;
white_noise_range(white_noise_range const&) = default;
explicit SPROUT_CONSTEXPR white_noise_range(
engine_type const& gen,
value_type const& sigma = 1
)
: base_type(
iterator(distribution_type(0, sigma)(gen)),
iterator()
)
{}
SPROUT_CONSTEXPR engine_type const& engine() const {
return base_type::begin().generator().engine();
}
SPROUT_CONSTEXPR value_type const& sigma() const {
return base_type::begin().generator().distribution().sigma();
}
};
//
// white_noise_forwarder
//
class white_noise_forwarder {
public:
template<typename UniformRandomNumberGenerator, typename Value = double>
SPROUT_CONSTEXPR sprout::compost::waves::white_noise_range<Value, UniformRandomNumberGenerator>
operator()(
UniformRandomNumberGenerator const& gen,
Value const& sigma = 1
) const
{
return sprout::compost::waves::white_noise_range<Value, UniformRandomNumberGenerator>(gen, sigma);
}
};
//
// white_noise
//
namespace {
SPROUT_STATIC_CONSTEXPR sprout::compost::waves::white_noise_forwarder white_noise{};
} // anonymous-namespace
//
// operator|
//
template<typename Range, typename Value, typename UniformRandomNumberGenerator>
inline SPROUT_CONSTEXPR sprout::compost::waves::white_noise_range<
Value, UniformRandomNumberGenerator,
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
>
operator|(Range&& lhs, sprout::compost::waves::white_noise_range<Value, UniformRandomNumberGenerator> const& rhs) {
return sprout::compost::waves::white_noise_range<
Value, UniformRandomNumberGenerator,
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
>(
sprout::lvalue_forward<Range>(lhs),
rhs.engine(), rhs.sigma()
);
}
} // namespace waves
} // namespace compost
//
// container_construct_traits
//
template<typename Value, typename UniformRandomNumberGenerator, typename Range>
struct container_construct_traits<sprout::compost::waves::white_noise_range<Value, UniformRandomNumberGenerator, Range> > {
public:
typedef typename sprout::container_construct_traits<Range>::copied_type copied_type;
public:
template<typename Cont>
static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) {
return sprout::range::fixed::copy(sprout::forward<Cont>(cont), sprout::pit<copied_type>());
}
template<typename... Args>
static SPROUT_CONSTEXPR copied_type make(Args&&... args) {
return sprout::make<copied_type>(sprout::forward<Args>(args)...);
}
template<typename Cont, typename... Args>
static SPROUT_CONSTEXPR copied_type remake(
Cont&& cont,
typename sprout::container_traits<sprout::compost::waves::white_noise_range<Value, UniformRandomNumberGenerator, Range> >::difference_type size,
Args&&... args
)
{
return sprout::remake<copied_type>(sprout::forward<Cont>(cont), size, sprout::forward<Args>(args)...);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_WAVES_WHITE_NOISE_HPP