19 unsigned channels,
unsigned bits,
unsigned frequency)
20 : file(filename,
"wb")
24 std::array<char, 4> chunkID;
26 std::array<char, 4>
format;
27 std::array<char, 4> subChunk1ID;
35 std::array<char, 4> subChunk2ID;
42 ranges::copy(std::string_view(
"fmt "), header.subChunk1ID);
43 header.subChunk1Size = 16;
44 header.audioFormat = 1;
45 header.numChannels = narrow<uint16_t>(channels);
46 header.sampleRate = frequency;
47 header.byteRate = (channels * frequency * bits) / 8;
48 header.blockAlign = narrow<uint16_t>((channels * bits) / 8);
49 header.bitsPerSample = narrow<uint16_t>(bits);
50 ranges::copy(std::string_view(
"data"), header.subChunk2ID);
51 header.subChunk2Size = 0;
61 std::array<uint8_t, 1> pad = {0};
87 bytes += narrow<uint32_t>(buffer.size_bytes());
98 bytes += narrow<uint32_t>(buffer.size_bytes());
101static int16_t float2int16(
float f)
108 std::vector<Endian::L16> buf_(buffer.size());
110 ranges::transform(buffer, buf.data(), [=](
float f) { return float2int16(f * amp); });
112 bytes += narrow<uint32_t>(buf.size_bytes());
117 std::vector<Endian::L16> buf(buffer.size() * 2);
119 buf[2 * i + 0] = float2int16(s.left * ampLeft);
120 buf[2 * i + 1] = float2int16(s.right * ampRight);
124 bytes += narrow<uint32_t>(s.size_bytes());
132 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:
auto transform(InputRange &&range, OutputIter out, UnaryOperation op)
constexpr auto copy(InputRange &&range, OutputIter out)