2#include <ossia/dataflow/float_to_sample.hpp>
4#include <boost/container/vector.hpp>
8#include <ossia-config.hpp>
12struct drwav_write_handle
14 drwav_data_format format;
15 static constexpr auto static_cutoff = 4096 * 2;
29 void open(std::string_view path,
int channels,
int rate,
int bits)
40 format.container = drwav_container_riff;
41 format.format = DR_WAVE_FORMAT_PCM;
42 format.channels = channels;
43 format.sampleRate = rate;
44 format.bitsPerSample = bits;
46 bool ok = drwav_init_file_write(impl, path.data(), &format,
nullptr);
48 buffer.reserve(channels * 8192 * (bits / 8));
66 drwav_uint64 write_pcm_frames(drwav_uint64 frames,
const double*
const* in)
73 frames * format.channels * (format.bitsPerSample / 8),
74 boost::container::default_init);
76 switch(format.bitsPerSample)
79 m_written_frames += frames;
80 interleave<int16_t, 16, 2>(
81 in,
reinterpret_cast<int16_t*
>(buffer.data()), format.channels, frames);
83 return drwav_write_raw(impl, frames * 2 * format.channels, buffer.data());
85 m_written_frames += frames;
86 interleave<int32_t, 24, 3>(
87 in,
reinterpret_cast<int32_t*
>(buffer.data()), format.channels, frames);
89 return drwav_write_raw(impl, frames * 3 * format.channels, buffer.data());
91 m_written_frames += frames;
92 interleave<int32_t, 32, 4>(
93 in,
reinterpret_cast<int32_t*
>(buffer.data()), format.channels, frames);
95 return drwav_write_raw(impl, frames * 4 * format.channels, buffer.data());
101 bool is_open() const noexcept {
return m_started; }
102 int64_t written_frames() const noexcept {
return m_written_frames; }
106 ossia::pod_vector<char> buffer;
108 int64_t m_written_frames = 0;