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 <cassert>
6 #include <cstdint>
7 
8 namespace openmsx {
9 
10 class Filename;
11 
14 class WavWriter
15 {
16 public:
19  bool isEmpty() const { return bytes == 0; }
20 
24  void flush();
25 
26 protected:
27  WavWriter(const Filename& filename,
28  unsigned channels, unsigned bits, unsigned frequency);
29  ~WavWriter();
30 
32  unsigned bytes;
33 };
34 
37 class Wav8Writer : public WavWriter
38 {
39 public:
40  Wav8Writer(const Filename& filename, unsigned channels, unsigned frequency)
41  : WavWriter(filename, channels, 8, frequency) {}
42 
43  void write(const uint8_t* buffer, unsigned stereo, unsigned samples) {
44  assert(stereo == 1 || stereo == 2);
45  write(buffer, stereo * samples);
46  }
47 
48 private:
49  void write(const uint8_t* buffer, unsigned samples);
50 };
51 
54 class Wav16Writer : public WavWriter
55 {
56 public:
57  Wav16Writer(const Filename& filename, unsigned channels, unsigned frequency)
58  : WavWriter(filename, channels, 16, frequency) {}
59 
60  void write(const int16_t* buffer, unsigned stereo, unsigned samples) {
61  assert(stereo == 1 || stereo == 2);
62  write(buffer, stereo * samples);
63  }
64  void write(const int* buffer, unsigned stereo, unsigned samples,
65  float ampLeft, float ampRight);
66  void writeSilence(unsigned stereo, unsigned samples) {
67  assert(stereo == 1 || stereo == 2);
68  writeSilence(stereo * samples);
69  }
70 
71 private:
72  void write(const int16_t* buffer, unsigned samples);
73  void writeSilence(unsigned samples);
74 };
75 
76 } // namespace openmsx
77 
78 #endif
void writeSilence(unsigned stereo, unsigned samples)
Definition: WavWriter.hh:66
Base class for writing WAV files.
Definition: WavWriter.hh:14
bool isEmpty() const
Returns false if there has been data written to the wav image.
Definition: WavWriter.hh:19
Wav8Writer(const Filename &filename, unsigned channels, unsigned frequency)
Definition: WavWriter.hh:40
void flush()
Flush data to file and update header.
Definition: WavWriter.cc:65
Writes 8-bit WAV files.
Definition: WavWriter.hh:37
WavWriter(const Filename &filename, unsigned channels, unsigned bits, unsigned frequency)
Definition: WavWriter.cc:11
Writes 16-bit WAV files.
Definition: WavWriter.hh:54
This class represents a filename.
Definition: Filename.hh:17
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void write(const uint8_t *buffer, unsigned stereo, unsigned samples)
Definition: WavWriter.hh:43
Wav16Writer(const Filename &filename, unsigned channels, unsigned frequency)
Definition: WavWriter.hh:57
void write(const int16_t *buffer, unsigned stereo, unsigned samples)
Definition: WavWriter.hh:60