Skip to content

Commit

Permalink
[float / sample] move things to the correct file
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Jan 24, 2024
1 parent 7255c11 commit b6edaae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 36 deletions.
20 changes: 16 additions & 4 deletions src/ossia/dataflow/float_to_sample.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,24 @@ constexpr int32_t float_to_sample<int32_t, 24>(ossia::audio_sample sample) noexc
return int32_t(sample * int24_max);
}

/*
template <>
constexpr int32_t float_to_sample<int32_t, 32>(ossia::audio_sample sample) noexcept
constexpr int32_t float_to_sample<int32_t, 24>(audio_sample x) noexcept
{
const constexpr ossia::audio_sample int32_max
= ossia::audio_sample(std::numeric_limits<int32_t>::max());
return sample * int32_max;
// 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) noexcept
{
return x * (audio_sample)std::numeric_limits<int32_t>::max();
}

template <>
Expand Down
32 changes: 0 additions & 32 deletions src/ossia/dataflow/sample_to_float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace ossia
{
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 @@ -61,36 +59,6 @@ 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 b6edaae

Please sign in to comment.