Go to the documentation of this file.
14 unsigned channels,
unsigned bits,
unsigned frequency)
35 memcpy(header.chunkID,
"RIFF",
sizeof(header.chunkID));
37 memcpy(header.format,
"WAVE",
sizeof(header.format));
38 memcpy(header.subChunk1ID,
"fmt ",
sizeof(header.subChunk1ID));
39 header.subChunk1Size = 16;
40 header.audioFormat = 1;
41 header.numChannels = channels;
42 header.sampleRate = frequency;
43 header.byteRate = (channels * frequency * bits) / 8;
44 header.blockAlign = (channels * bits) / 8;
45 header.bitsPerSample = bits;
46 memcpy(header.subChunk2ID,
"data",
sizeof(header.subChunk2ID));
47 header.subChunk2Size = 0;
88 unsigned size =
sizeof(int16_t) * samples;
89 if (OPENMSX_BIGENDIAN) {
97 std::vector<Endian::L16> buf(buffer, buffer + samples);
105 static int16_t float2int16(
float f)
111 float ampLeft,
float ampRight)
113 assert(stereo ==
one_of(1u, 2u));
114 std::vector<Endian::L16> buf(samples * stereo);
116 assert(ampLeft == ampRight);
117 for (
auto i :
xrange(samples)) {
118 buf[i] = float2int16(buffer[i] * ampLeft);
121 for (
auto i :
xrange(samples)) {
122 buf[2 * i + 0] = float2int16(buffer[2 * i + 0] * ampLeft);
123 buf[2 * i + 1] = float2int16(buffer[2 * i + 1] * ampRight);
126 unsigned size =
sizeof(int16_t) * samples * stereo;
133 VLA(int16_t, buf, samples);
134 unsigned size =
sizeof(int16_t) * samples;
135 memset(buf, 0,
size);
void flush()
Flush data to file and update header.
void format(SectorAccessibleDisk &disk, bool dos1)
Format the given disk (= a single partition).
constexpr auto xrange(T e)
size_t getSize()
Returns the size of this file.
size_t size(std::string_view utf8)
void write(const uint8_t *buffer, unsigned stereo, unsigned samples)
void writeSilence(unsigned stereo, unsigned samples)
void write(const int16_t *buffer, unsigned stereo, unsigned samples)
void write(const void *buffer, size_t num)
Write to file.
constexpr const char *const filename
void flush()
Force a write of all buffered data to disk.
WavWriter(const Filename &filename, unsigned channels, unsigned bits, unsigned frequency)
void seek(size_t pos)
Move read/write pointer to the specified position.
int16_t clipIntToShort(int x)
Clip x to range [-32768,32767].
This class represents a filename.
#define VLA(TYPE, NAME, LENGTH)
This file implemented 3 utility functions: