/*============================================================================= Copyright (c) 2011-2019 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #ifndef SPROUT_COMPOST_FORMATS_AS_PCM_WAVE_HPP #define SPROUT_COMPOST_FORMATS_AS_PCM_WAVE_HPP #include #include #include #include #include #include #include #include #include namespace sprout { namespace compost { namespace detail { template struct normalized_to_pcm_wave; template struct normalized_to_pcm_wave< IntType, typename std::enable_if::value>::type > { public: typedef IntType result_type; public: template SPROUT_CONSTEXPR result_type operator()(T const& x) const { return static_cast(sprout::clamp(x, -1, 1) * sprout::numeric_limits::max()); } }; template struct normalized_to_pcm_wave< IntType, typename std::enable_if::value>::type > { public: typedef IntType result_type; public: template SPROUT_CONSTEXPR result_type operator()(T const& x) const { return static_cast(sprout::clamp((x + 1) / 2, 0, 1) * sprout::numeric_limits::max()); } }; } // namespace detail // // normalized_to_pcm_wave // template struct normalized_to_pcm_wave : public sprout::compost::detail::normalized_to_pcm_wave {}; namespace formats { // // as_pcm_wave_forwarder // template class as_pcm_wave_forwarder {}; // // as_pcm_wave // template inline SPROUT_CONSTEXPR sprout::compost::formats::as_pcm_wave_forwarder as_pcm_wave() { return sprout::compost::formats::as_pcm_wave_forwarder(); } // // operator| // template inline SPROUT_CONSTEXPR auto operator|(Range&& lhs, sprout::compost::formats::as_pcm_wave_forwarder const&) -> decltype( SPROUT_FORWARD(Range, lhs) | sprout::adaptors::transformed(sprout::compost::normalized_to_pcm_wave()) ) { return SPROUT_FORWARD(Range, lhs) | sprout::adaptors::transformed(sprout::compost::normalized_to_pcm_wave()) ; } // // as_pcm_wave8 // as_pcm_wave16 // namespace { SPROUT_STATIC_CONSTEXPR sprout::compost::formats::as_pcm_wave_forwarder as_pcm_wave8 = {}; SPROUT_STATIC_CONSTEXPR sprout::compost::formats::as_pcm_wave_forwarder as_pcm_wave16 = {}; } // anonymous-namespace } // namespace formats using sprout::compost::formats::as_pcm_wave; using sprout::compost::formats::as_pcm_wave8; using sprout::compost::formats::as_pcm_wave16; } // namespace compost } // namespace sprout #endif // #ifndef SPROUT_COMPOST_FORMATS_AS_PCM_WAVE_HPP