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 "one_of.hh"
6 #include <cassert>
7 #include <cstdint>
8 
9 namespace openmsx {
10 
11 class Filename;
12 
15 class WavWriter
16 {
17 public:
20  [[nodiscard]] bool isEmpty() const { return bytes == 0; }
21 
25  void flush();
26 
27 protected:
29  unsigned channels, unsigned bits, unsigned frequency);
30  ~WavWriter();
31 
32 protected:
34  unsigned bytes;
35 };
36 
39 class Wav8Writer : public WavWriter
40 {
41 public:
42  Wav8Writer(const Filename& filename, unsigned channels, unsigned frequency)
43  : WavWriter(filename, channels, 8, frequency) {}
44 
45  void write(const uint8_t* buffer, unsigned stereo, unsigned samples) {
46  assert(stereo == one_of(1u, 2u));
47  write(buffer, stereo * samples);
48  }
49 
50 private:
51  void write(const uint8_t* buffer, unsigned samples);
52 };
53 
56 class Wav16Writer : public WavWriter
57 {
58 public:
59  Wav16Writer(const Filename& filename, unsigned channels, unsigned frequency)
60  : WavWriter(filename, channels, 16, frequency) {}
61 
62  void write(const int16_t* buffer, unsigned stereo, unsigned samples) {
63  assert(stereo == one_of(1u, 2u));
64  write(buffer, stereo * samples);
65  }
66  void write(const float* buffer, unsigned stereo, unsigned samples,
67  float ampLeft, float ampRight);
68  void writeSilence(unsigned stereo, unsigned samples) {
69  assert(stereo == one_of(1u, 2u));
70  writeSilence(stereo * samples);
71  }
72 
73 private:
74  void write(const int16_t* buffer, unsigned samples);
75  void writeSilence(unsigned samples);
76 };
77 
78 } // namespace openmsx
79 
80 #endif
one_of.hh
openmsx::WavWriter::flush
void flush()
Flush data to file and update header.
Definition: WavWriter.cc:66
openmsx::Wav8Writer
Writes 8-bit WAV files.
Definition: WavWriter.hh:40
openmsx::Wav8Writer::write
void write(const uint8_t *buffer, unsigned stereo, unsigned samples)
Definition: WavWriter.hh:45
openmsx::WavWriter::~WavWriter
~WavWriter()
Definition: WavWriter.cc:51
openmsx::Wav8Writer::Wav8Writer
Wav8Writer(const Filename &filename, unsigned channels, unsigned frequency)
Definition: WavWriter.hh:42
openmsx::WavWriter::isEmpty
bool isEmpty() const
Returns false if there has been data written to the wav image.
Definition: WavWriter.hh:20
openmsx::Wav16Writer::writeSilence
void writeSilence(unsigned stereo, unsigned samples)
Definition: WavWriter.hh:68
openmsx::Wav16Writer::write
void write(const int16_t *buffer, unsigned stereo, unsigned samples)
Definition: WavWriter.hh:62
File.hh
one_of
Definition: one_of.hh:7
openmsx::filename
constexpr const char *const filename
Definition: FirmwareSwitch.cc:10
openmsx::WavWriter
Base class for writing WAV files.
Definition: WavWriter.hh:16
openmsx::Wav16Writer
Writes 16-bit WAV files.
Definition: WavWriter.hh:57
openmsx::WavWriter::WavWriter
WavWriter(const Filename &filename, unsigned channels, unsigned bits, unsigned frequency)
Definition: WavWriter.cc:12
openmsx::File
Definition: File.hh:16
openmsx::Filename
Filename
Definition: Filename.cc:50
openmsx::WavWriter::bytes
unsigned bytes
Definition: WavWriter.hh:34
openmsx::Filename
This class represents a filename.
Definition: Filename.hh:18
openmsx::WavWriter::file
File file
Definition: WavWriter.hh:33
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::Wav16Writer::Wav16Writer
Wav16Writer(const Filename &filename, unsigned channels, unsigned frequency)
Definition: WavWriter.hh:59