| e8555c89 Andy McCall |
1 |
#ifndef WAVWRITER_HH |
| 2 |
#define WAVWRITER_HH |
| 3 |
|
| 4 |
#include "File.hh" |
| 5 |
#include "Mixer.hh" |
| 6 |
|
| 7 |
#include <cassert> |
| 8 |
#include <cstdint> |
| 9 |
#include <span> |
| 10 |
#include <string> |
| 11 |
|
| 12 |
namespace openmsx { |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
class WavWriter |
| 17 |
{ |
| 18 |
public: |
| 19 |
|
| 20 |
|
| 21 |
[[nodiscard]] bool isEmpty() const { return bytes == 0; } |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
[[nodiscard]] uint32_t getBytes() const { return bytes; } |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
void flush(); |
| 31 |
|
| 32 |
protected: |
| 33 |
WavWriter(const std::string& filename, |
| 34 |
unsigned channels, unsigned bits, unsigned frequency); |
| 35 |
~WavWriter(); |
| 36 |
|
| 37 |
protected: |
| 38 |
File file; |
| 39 |
uint32_t bytes = 0; |
| 40 |
}; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
class Wav8Writer : public WavWriter |
| 45 |
{ |
| 46 |
public: |
| 47 |
Wav8Writer(const std::string& filename, unsigned channels, unsigned frequency) |
| 48 |
: WavWriter(filename, channels, 8, frequency) {} |
| 49 |
|
| 50 |
void write(std::span<const uint8_t> buffer); |
| 51 |
}; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
class Wav16Writer : public WavWriter |
| 56 |
{ |
| 57 |
public: |
| 58 |
Wav16Writer(const std::string& filename, unsigned channels, unsigned frequency) |
| 59 |
: WavWriter(filename, channels, 16, frequency) {} |
| 60 |
|
| 61 |
void write(std::span<const int16_t> buffer); |
| 62 |
void write(std::span<const float> buffer, float amp = 1.0f); |
| 63 |
void write(std::span<const StereoFloat> buffer, float ampLeft = 1.0f, float ampRight = 1.0f); |
| 64 |
|
| 65 |
void writeSilence(uint32_t samples); |
| 66 |
}; |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
#endif |