| 43 | |
| 44 | public: |
| 45 | struct Result { |
| 46 | enum class Code { |
| 47 | OK = 0, |
| 48 | IO_ERROR, |
| 49 | FORMAT_ERROR, |
| 50 | UNSUPPORTED, |
| 51 | WEIRD_CONFIG |
| 52 | }; |
| 53 | Code code = Code::OK; |
| 54 | std::string reason; |
| 55 | |
| 56 | Result(Code code, std::string reason="") : code(code), reason(reason) {}; |
| 57 | Result(const Result &other) : code(other.code), reason(other.reason) {}; |
| 58 | Result & operator=(const Result &other) { |
| 59 | // TODO: what is this? Why do we only copy if it's _not_ OK? |
| 60 | if (code == Code::OK) { |
| 61 | code = other.code; |
| 62 | reason = other.reason; |
| 63 | } |
| 64 | return *this; |
| 65 | } |
| 66 | // Used to neatly test for success |
| 67 | explicit operator bool () const { |
| 68 | return code == Code::OK; |
| 69 | }; |
| 70 | const Result & warn(std::ostream& output=std::cerr) const { |
| 71 | if (!(bool)*this) { |
| 72 | output << "WAV error: " << reason << std::endl; |
| 73 | } |
| 74 | return *this; |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | unsigned int sampleRate = 48000; |
| 79 | unsigned int channels = 1; |