diff --git a/src/ossia/audio/pipewire_protocol.hpp b/src/ossia/audio/pipewire_protocol.hpp index e228a3fc42c..7afed427d57 100644 --- a/src/ossia/audio/pipewire_protocol.hpp +++ b/src/ossia/audio/pipewire_protocol.hpp @@ -556,7 +556,7 @@ class pipewire_audio_protocol : public audio_engine PW_KEY_NODE_FORCE_QUANTUM, fmt::format("{}", setup.buffer_size).c_str(), PW_KEY_NODE_LOCK_QUANTUM, "true", PW_KEY_NODE_RATE, fmt::format("{}/{}", 1, setup.rate).c_str(), - PW_KEY_NODE_FORCE_RATE, fmt::format("{}", setup.rate).c_str(), + PW_KEY_NODE_FORCE_RATE, fmt::format("{}/{}", 1, setup.rate).c_str(), PW_KEY_NODE_LOCK_RATE, "true", PW_KEY_NODE_ALWAYS_PROCESS, "true", PW_KEY_NODE_PAUSE_ON_IDLE, "false", diff --git a/src/ossia/dataflow/sample_to_float.hpp b/src/ossia/dataflow/sample_to_float.hpp index 1f45e549926..9eb0c5bb5aa 100644 --- a/src/ossia/dataflow/sample_to_float.hpp +++ b/src/ossia/dataflow/sample_to_float.hpp @@ -7,9 +7,10 @@ namespace ossia { -// TODO refactor with AudioDecoder 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) @@ -54,6 +55,42 @@ constexpr audio_sample sample_to_float(float i) return i; } +template <> +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();