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 x)
noexcept
63 if constexpr(std::is_same_v<ossia::audio_sample, float>)
65 return (x * (0x7FFFFF + 0.5f)) - 0.5f;
69 return (x * (0x7FFFFF + 0.5)) - 0.5;
74constexpr int32_t float_to_sample<int32_t, 32>(audio_sample x)
noexcept
79 return (
double(x) * (0x7FFFFFFF + 0.5)) - 0.5;
83constexpr float float_to_sample<float, 32>(
float sample)
noexcept
89#define OSSIA_RESTRICT __restrict
91#define OSSIA_RESTRICT __restrict__
94template <
typename SampleFormat,
int N,
int ByteIncrement,
typename InputFormat>
95 requires(
sizeof(SampleFormat) == ByteIncrement)
96inline void interleave(
97 const InputFormat*
const* OSSIA_RESTRICT in, SampleFormat* OSSIA_RESTRICT out,
100 for(
int c = 0; c < channels; c++)
102 auto* in_channel = in[c];
103 for(
int k = 0; k < bs; k++)
105 out[k * channels + c] = float_to_sample<SampleFormat, N>(in_channel[k]);
110template <
typename SampleFormat,
int N,
int ByteIncrement,
typename InputFormat>
111 requires(
sizeof(SampleFormat) != ByteIncrement)
112inline void interleave(
113 const InputFormat*
const* OSSIA_RESTRICT in, SampleFormat* out,
int channels,
int bs)
115 for(
int c = 0; c < channels; c++)
117 auto* in_channel = in[c];
118 for(
int k = 0; k < bs; k++)
121 char* out_raw =
reinterpret_cast<char*
>(out);
123 =
reinterpret_cast<SampleFormat*
>(out_raw[(k * channels + c) * ByteIncrement]);
124 *mem = float_to_sample<SampleFormat, N>(in_channel[k]);
129template <
typename SampleFormat,
int N,
typename InputFormat>
131 const InputFormat*
const* OSSIA_RESTRICT in, SampleFormat* OSSIA_RESTRICT out,
132 int channels,
int bs)
134 for(
int c = 0; c < channels; c++)
136 auto* in_channel = in[c];
137 auto* out_channel = out + c * bs;
138 for(
int k = 0; k < bs; k++)
140 out_channel[k] = float_to_sample<SampleFormat, N>(in_channel[k]);
constexpr SampleFormat float_to_sample(ossia::audio_sample sample) noexcept