#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 formats { // // normalized_to_pcm_wave // 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) * std::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) * std::numeric_limits::max()); } }; // // 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& rhs) -> decltype( sprout::forward(lhs) | sprout::adaptors::transformed(sprout::compost::formats::normalized_to_pcm_wave()) ) { return sprout::forward(lhs) | sprout::adaptors::transformed(sprout::compost::formats::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 } // namespace compost } // namespace sprout #endif // #ifndef SPROUT_COMPOST_FORMATS_AS_PCM_WAVE_HPP