18 unsigned channels,
unsigned bits,
unsigned frequency)
19 : file(filename,
"wb")
23 std::array<char, 4> chunkID;
25 std::array<char, 4>
format;
26 std::array<char, 4> subChunk1ID;
34 std::array<char, 4> subChunk2ID;
41 ranges::copy(std::string_view(
"fmt "), header.subChunk1ID);
42 header.subChunk1Size = 16;
43 header.audioFormat = 1;
44 header.numChannels = narrow<uint16_t>(channels);
45 header.sampleRate = frequency;
46 header.byteRate = (channels * frequency * bits) / 8;
47 header.blockAlign = narrow<uint16_t>((channels * bits) / 8);
48 header.bitsPerSample = narrow<uint16_t>(bits);
49 ranges::copy(std::string_view(
"data"), header.subChunk2ID);
50 header.subChunk2Size = 0;
60 std::array<uint8_t, 1> pad = {0};
86 bytes += narrow<uint32_t>(buffer.size_bytes());
99 std::vector<Endian::L16> buf(buffer.begin(), buffer.end());
104 bytes += narrow<uint32_t>(buffer.size_bytes());
107static int16_t float2int16(
float f)
114 std::vector<Endian::L16> buf_(buffer.size());
116 ranges::transform(buffer, buf.data(), [=](
float f) { return float2int16(f * amp); });
118 bytes += narrow<uint32_t>(buf.size_bytes());
123 std::vector<Endian::L16> buf(buffer.size() * 2);
125 buf[2 * i + 0] = float2int16(s.left * ampLeft);
126 buf[2 * i + 1] = float2int16(s.right * ampRight);
130 bytes += narrow<uint32_t>(s.size_bytes());
135 VLA(int16_t, buf, samples);
138 bytes += narrow<uint32_t>(buf.size_bytes());
void seek(size_t pos)
Move read/write pointer to the specified position.
void write(std::span< const uint8_t > buffer)
Write to file.
size_t getSize()
Returns the size of this file.
void flush()
Force a write of all buffered data to disk.
This class represents a filename.
void write(std::span< const int16_t > buffer)
void writeSilence(uint32_t samples)
void write(std::span< const uint8_t > buffer)
void flush()
Flush data to file and update header.
WavWriter(const Filename &filename, unsigned channels, unsigned bits, unsigned frequency)
constexpr auto enumerate(Iterable &&iterable)
Heavily inspired by Nathan Reed's blog post: Python-Like enumerate() In C++17 http://reedbeta....
int16_t clipToInt16(T x)
Clip x to range [-32768,32767].
void format(SectorAccessibleDisk &disk, MSXBootSectorType bootType)
Format the given disk (= a single partition).
This file implemented 3 utility functions:
constexpr void fill(ForwardRange &&range, const T &value)
auto transform(InputRange &&range, OutputIter out, UnaryOperation op)
constexpr auto copy(InputRange &&range, OutputIter out)
#define VLA(TYPE, NAME, LENGTH)