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  bool isEmpty() const { return bytes == 0; }
21 
25  void flush();
26 
27 protected:
29  unsigned channels, unsigned bits, unsigned frequency);
30  ~WavWriter();
31 
33  unsigned bytes;
34 };
35 
38 class Wav8Writer : public WavWriter
39 {
40 public:
41  Wav8Writer(const Filename& filename, unsigned channels, unsigned frequency)
42  : WavWriter(filename, channels, 8, frequency) {}
43 
44  void write(const uint8_t* buffer, unsigned stereo, unsigned samples) {
45  assert(stereo == one_of(1u, 2u));
46  write(buffer, stereo * samples);
47  }
48 
49 private:
50  void write(const uint8_t* buffer, unsigned samples);
51 };
52 
55 class Wav16Writer : public WavWriter
56 {
57 public:
58  Wav16Writer(const Filename& filename, unsigned channels, unsigned frequency)
59  : WavWriter(filename, channels, 16, frequency) {}
60 
61  void write(const int16_t* buffer, unsigned stereo, unsigned samples) {
62  assert(stereo == one_of(1u, 2u));
63  write(buffer, stereo * samples);
64  }
65  void write(const float* buffer, unsigned stereo, unsigned samples,
66  float ampLeft, float ampRight);
67  void writeSilence(unsigned stereo, unsigned samples) {
68  assert(stereo == one_of(1u, 2u));
69  writeSilence(stereo * samples);
70  }
71 
72 private:
73  void write(const int16_t* buffer, unsigned samples);
74  void writeSilence(unsigned samples);
75 };
76 
77 } // namespace openmsx
78 
79 #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:38
openmsx::Wav8Writer::write
void write(const uint8_t *buffer, unsigned stereo, unsigned samples)
Definition: WavWriter.hh:44
openmsx::WavWriter::~WavWriter
~WavWriter()
Definition: WavWriter.cc:51
openmsx::Wav8Writer::Wav8Writer
Wav8Writer(const Filename &filename, unsigned channels, unsigned frequency)
Definition: WavWriter.hh:41
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:67
openmsx::Wav16Writer::write
void write(const int16_t *buffer, unsigned stereo, unsigned samples)
Definition: WavWriter.hh:61
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:15
openmsx::Wav16Writer
Writes 16-bit WAV files.
Definition: WavWriter.hh:55
openmsx::WavWriter::WavWriter
WavWriter(const Filename &filename, unsigned channels, unsigned bits, unsigned frequency)
Definition: WavWriter.cc:12
openmsx::File
Definition: File.hh:15
openmsx::Filename
Filename
Definition: Filename.cc:50
openmsx::WavWriter::bytes
unsigned bytes
Definition: WavWriter.hh:33
openmsx::Filename
This class represents a filename.
Definition: Filename.hh:17
openmsx::WavWriter::file
File file
Definition: WavWriter.hh:32
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::Wav16Writer::Wav16Writer
Wav16Writer(const Filename &filename, unsigned channels, unsigned frequency)
Definition: WavWriter.hh:58