Helper to save a buffer to a WAV file
| 12 | |
| 13 | // Helper to save a buffer to a WAV file |
| 14 | bool saveBufferToWAV (const std::string& filename, const choc::buffer::ChannelArrayBuffer<float>& buffer) |
| 15 | { |
| 16 | choc::audio::WAVAudioFileFormat<true> writerFormat; |
| 17 | choc::audio::AudioFileProperties properties; |
| 18 | properties.sampleRate = 44100.0; |
| 19 | properties.numChannels = buffer.getNumChannels(); |
| 20 | properties.numFrames = buffer.getNumFrames(); |
| 21 | properties.bitDepth = choc::audio::BitDepth::int16; |
| 22 | |
| 23 | auto writer = writerFormat.createWriter (filename, properties); |
| 24 | |
| 25 | if (writer == nullptr) |
| 26 | { |
| 27 | std::cout << "Failed to create writer for " << filename << std::endl; |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | if (! writer->appendFrames (buffer.getView())) |
| 32 | { |
| 33 | std::cout << "Failed to write frames to " << filename << std::endl; |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | std::cout << "Successfully wrote " << filename << std::endl; |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | int main() |
| 42 | { |
no test coverage detected