Skip to content

Commit

Permalink
[audio] Minor improvements, a pipewire fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Jan 23, 2024
1 parent 09f85e4 commit 7255c11
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ossia/audio/pipewire_protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
39 changes: 38 additions & 1 deletion src/ossia/dataflow/sample_to_float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

namespace ossia
{
// TODO refactor with AudioDecoder
template <typename SampleFormat, int N>
constexpr audio_sample sample_to_float(SampleFormat i);
template <typename SampleFormat, int N>
constexpr SampleFormat float_to_sample(audio_sample f);

template <>
constexpr audio_sample sample_to_float<uint8_t, 8>(uint8_t i)
Expand Down Expand Up @@ -54,6 +55,42 @@ constexpr audio_sample sample_to_float<float, 32>(float i)
return i;
}

template <>
constexpr audio_sample sample_to_float<double, 64>(double i)
{
return i;
}

template <>
constexpr int16_t float_to_sample<int16_t, 16>(audio_sample x)
{
// TODO division -> multiplication
if constexpr(std::is_same_v<ossia::audio_sample, float>)
{
return (x * (0x7FFF + 0.5f)) - 0.5f;
}
else
return (x * (0x7FFF + 0.5)) - 0.5;
}

template <>
constexpr int32_t float_to_sample<int32_t, 24>(audio_sample x)
{
// TODO division -> multiplication
if constexpr(std::is_same_v<ossia::audio_sample, float>)
{
return (x * (0x7FFFFF + 0.5f)) - 0.5f;
}
else
return (x * (0x7FFFFF + 0.5)) - 0.5;
}

template <>
constexpr int32_t float_to_sample<int32_t, 32>(audio_sample x)
{
return x * (audio_sample)std::numeric_limits<int32_t>::max();
}

inline void read_u8(ossia::mutable_audio_span<float>& ap, void* data, int64_t samples)
{
const auto channels = ap.size();
Expand Down

0 comments on commit 7255c11

Please sign in to comment.