3#include <ossia/dataflow/nodes/media.hpp> 
   28template <
typename SampleFormat, 
int N>
 
   32constexpr uint8_t float_to_sample<uint8_t, 8>(ossia::audio_sample sample) 
noexcept 
   35  if constexpr(std::is_same_v<ossia::audio_sample, float>)
 
   37    return (sample + 1.f) * 127.5f;
 
   41    return (sample + 1.) * 127.5;
 
   46constexpr int16_t float_to_sample<int16_t, 16>(ossia::audio_sample sample) 
noexcept 
   49  if constexpr(std::is_same_v<ossia::audio_sample, float>)
 
   51    return sample * (0x7FFF + .5f) - 0.5f;
 
   55    return sample * (0x7FFF + .5) - 0.5;
 
   61constexpr int32_t float_to_sample<int32_t, 24>(ossia::audio_sample sample) 
noexcept 
   63  const constexpr ossia::audio_sample int24_max
 
   64      = std::numeric_limits<int32_t>::max() / 256.;
 
   65  return int32_t(sample * int24_max);
 
   83constexpr int32_t float_to_sample<int32_t, 32>(audio_sample x) 
noexcept 
   85  return x * (audio_sample)std::numeric_limits<int32_t>::max();
 
   89constexpr float float_to_sample<float, 32>(
float sample) 
noexcept 
   95#define OSSIA_RESTRICT __restrict 
   97#define OSSIA_RESTRICT __restrict__ 
  100template <
typename SampleFormat, 
int N, 
int ByteIncrement, 
typename InputFormat>
 
  101  requires(
sizeof(SampleFormat) == ByteIncrement)
 
  102inline void interleave(
 
  103    const InputFormat* 
const* OSSIA_RESTRICT in, SampleFormat* OSSIA_RESTRICT out,
 
  104    int channels, 
int bs)
 
  106  for(
int c = 0; c < channels; c++)
 
  108    auto* in_channel = in[c];
 
  109    for(
int k = 0; k < bs; k++)
 
  111      out[k * channels + c] = float_to_sample<SampleFormat, N>(in_channel[k]);
 
  116template <
typename SampleFormat, 
int N, 
int ByteIncrement, 
typename InputFormat>
 
  117  requires(
sizeof(SampleFormat) != ByteIncrement)
 
  118inline void interleave(
 
  119    const InputFormat* 
const* OSSIA_RESTRICT in, SampleFormat* out, 
int channels, 
int bs)
 
  121  for(
int c = 0; c < channels; c++)
 
  123    auto* in_channel = in[c];
 
  124    for(
int k = 0; k < bs; k++)
 
  127      char* out_raw = 
reinterpret_cast<char*
>(out);
 
  129          = 
reinterpret_cast<SampleFormat*
>(out_raw[(k * channels + c) * ByteIncrement]);
 
  130      *mem = float_to_sample<SampleFormat, N>(in_channel[k]);
 
  135template <
typename SampleFormat, 
int N, 
typename InputFormat>
 
  137    const InputFormat* 
const* OSSIA_RESTRICT in, SampleFormat* OSSIA_RESTRICT out,
 
  138    int channels, 
int bs)
 
  140  for(
int c = 0; c < channels; c++)
 
  142    auto* in_channel = in[c];
 
  143    auto* out_channel = out + c * bs;
 
  144    for(
int k = 0; k < bs; k++)
 
  146      out_channel[k] = float_to_sample<SampleFormat, N>(in_channel[k]);
 
constexpr SampleFormat float_to_sample(ossia::audio_sample sample) noexcept