From b6edaae8e33adb11c4a3b86bda6ff6c10370c0a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Tue, 23 Jan 2024 23:01:03 -0500 Subject: [PATCH] [float / sample] move things to the correct file --- src/ossia/dataflow/float_to_sample.hpp | 20 ++++++++++++---- src/ossia/dataflow/sample_to_float.hpp | 32 -------------------------- 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/src/ossia/dataflow/float_to_sample.hpp b/src/ossia/dataflow/float_to_sample.hpp index 60d3c536ba5..77e6f2aedd9 100644 --- a/src/ossia/dataflow/float_to_sample.hpp +++ b/src/ossia/dataflow/float_to_sample.hpp @@ -65,12 +65,24 @@ constexpr int32_t float_to_sample(ossia::audio_sample sample) noexc return int32_t(sample * int24_max); } +/* template <> -constexpr int32_t float_to_sample(ossia::audio_sample sample) noexcept +constexpr int32_t float_to_sample(audio_sample x) noexcept { - const constexpr ossia::audio_sample int32_max - = ossia::audio_sample(std::numeric_limits::max()); - return sample * int32_max; + // TODO division -> multiplication + if constexpr(std::is_same_v) + { + return (x * (0x7FFFFF + 0.5f)) - 0.5f; + } + else + return (x * (0x7FFFFF + 0.5)) - 0.5; +} +*/ + +template <> +constexpr int32_t float_to_sample(audio_sample x) noexcept +{ + return x * (audio_sample)std::numeric_limits::max(); } template <> diff --git a/src/ossia/dataflow/sample_to_float.hpp b/src/ossia/dataflow/sample_to_float.hpp index 9eb0c5bb5aa..03cf3651e97 100644 --- a/src/ossia/dataflow/sample_to_float.hpp +++ b/src/ossia/dataflow/sample_to_float.hpp @@ -9,8 +9,6 @@ namespace ossia { template constexpr audio_sample sample_to_float(SampleFormat i); -template -constexpr SampleFormat float_to_sample(audio_sample f); template <> constexpr audio_sample sample_to_float(uint8_t i) @@ -61,36 +59,6 @@ constexpr audio_sample sample_to_float(double i) return i; } -template <> -constexpr int16_t float_to_sample(audio_sample x) -{ - // TODO division -> multiplication - if constexpr(std::is_same_v) - { - return (x * (0x7FFF + 0.5f)) - 0.5f; - } - else - return (x * (0x7FFF + 0.5)) - 0.5; -} - -template <> -constexpr int32_t float_to_sample(audio_sample x) -{ - // TODO division -> multiplication - if constexpr(std::is_same_v) - { - return (x * (0x7FFFFF + 0.5f)) - 0.5f; - } - else - return (x * (0x7FFFFF + 0.5)) - 0.5; -} - -template <> -constexpr int32_t float_to_sample(audio_sample x) -{ - return x * (audio_sample)std::numeric_limits::max(); -} - inline void read_u8(ossia::mutable_audio_span& ap, void* data, int64_t samples) { const auto channels = ap.size();