Skip to content
Igor Zinken edited this page Dec 21, 2018 · 3 revisions

See <utilities/wavewriter.h>

WaveWriter is a class with static methods allowing you to save the contents of an AudioBuffer as a .WAV file on the filesystem.

Public static methods

size_t bufferToWAV( std::string outputFile, AudioBuffer* buffer, int sampleRate );

Saves the contents of given buffer as a .WAV file and store it at given (absolute) path outputFile on the Android filesystem. sampleRate should describe the sample rate in Hz, which is likely to be equal to the sample rate of the MWEngine (see AudioEngineProps::SAMPLE_RATE). The returned value is the size of the .WAV files data (that is, raw PCM audio without the WAV header).

static short int* bufferToPCM( AudioBuffer* buffer );

Allocates a buffer that contains a PCM compliant representation of the samples in given AudioBuffer. When done using the returned PCM buffer, be sure to delete[] its allocated memory.

static std::ofstream createWAVStream( const char* outFile, size_t totalBufSizeToWrite,
                                      int sampleRate, int channels )

Creates and returns an output stream to write data to a single WAV file in iterations. This can be used to write successive buffers into a single file. The one requirement is that totalBufSizeToWrite describes the sum of all written WAV snippets data (raw PCM audio without the WAV header). This is used by the DiskWriter to combine several temporary snippets into one final file after recording stops (at which point totalBufSizeToWrite can be deduced by summing the return values of all invocations to bufferToWAV).

void appendBufferToStream( std::ofstream& stream, SampleType* buf, size_t bufSize )

Appends the contents of given buf (raw PCM array, see bufferToPCM()) for given length bufSize to the .WAV file referenced by given stream (created by createWAVStream).

Clone this wiki locally