openMSX
WavWriter.hh
Go to the documentation of this file.
1#ifndef WAVWRITER_HH
2#define WAVWRITER_HH
3
4#include "File.hh"
5#include "Mixer.hh"
6#include "one_of.hh"
7#include <cassert>
8#include <cstdint>
9#include <span>
10
11namespace openmsx {
12
13class Filename;
14
18{
19public:
22 [[nodiscard]] bool isEmpty() const { return bytes == 0; }
23
26 [[nodiscard]] uint32_t getBytes() const { return bytes; }
27
31 void flush();
32
33protected:
34 WavWriter(const Filename& filename,
35 unsigned channels, unsigned bits, unsigned frequency);
36 ~WavWriter();
37
38protected:
40 uint32_t bytes = 0;
41};
42
45class Wav8Writer : public WavWriter
46{
47public:
48 Wav8Writer(const Filename& filename, unsigned channels, unsigned frequency)
49 : WavWriter(filename, channels, 8, frequency) {}
50
51 void write(std::span<const uint8_t> buffer);
52};
53
56class Wav16Writer : public WavWriter
57{
58public:
59 Wav16Writer(const Filename& filename, unsigned channels, unsigned frequency)
60 : WavWriter(filename, channels, 16, frequency) {}
61
62 void write(std::span<const int16_t> buffer);
63 void write(std::span<const float> buffer, float amp = 1.0f);
64 void write(std::span<const StereoFloat> buffer, float ampLeft = 1.0f, float ampRight = 1.0f);
65
66 void writeSilence(uint32_t samples);
67};
68
69} // namespace openmsx
70
71#endif
This class represents a filename.
Definition: Filename.hh:18
Writes 16-bit WAV files.
Definition: WavWriter.hh:57
void write(std::span< const int16_t > buffer)
Definition: WavWriter.cc:88
Wav16Writer(const Filename &filename, unsigned channels, unsigned frequency)
Definition: WavWriter.hh:59
void writeSilence(uint32_t samples)
Definition: WavWriter.cc:132
Writes 8-bit WAV files.
Definition: WavWriter.hh:46
Wav8Writer(const Filename &filename, unsigned channels, unsigned frequency)
Definition: WavWriter.hh:48
void write(std::span< const uint8_t > buffer)
Definition: WavWriter.cc:82
Base class for writing WAV files.
Definition: WavWriter.hh:18
void flush()
Flush data to file and update header.
Definition: WavWriter.cc:69
bool isEmpty() const
Returns false if there has been data written to the wav image.
Definition: WavWriter.hh:22
uint32_t getBytes() const
Returns the number of bytes (not samples) written so far.
Definition: WavWriter.hh:26
WavWriter(const Filename &filename, unsigned channels, unsigned bits, unsigned frequency)
Definition: WavWriter.cc:16
This file implemented 3 utility functions:
Definition: Autofire.cc:9