MCPcopy Create free account
hub / github.com/Tracktion/choc / saveBufferToWAV

Function saveBufferToWAV

examples/audio_operations.cpp:14–39  ·  view source on GitHub ↗

Helper to save a buffer to a WAV file

Source from the content-addressed store, hash-verified

12
13// Helper to save a buffer to a WAV file
14bool 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
41int main()
42{

Callers 1

mainFunction · 0.85

Calls 5

getViewMethod · 0.80
getNumChannelsMethod · 0.45
getNumFramesMethod · 0.45
createWriterMethod · 0.45
appendFramesMethod · 0.45

Tested by

no test coverage detected