class EE::Audio::OutputSoundFile

Overview

Provide write access to sound files. More…

#include <outputsoundfile.hpp>

class OutputSoundFile: private EE::NonCopyable {
public:
    // construction

    ~OutputSoundFile();

    // methods

    bool openFromFile(const std::string& filename, unsigned int sampleRate, unsigned int channelCount);
    void write(const Int16* samples, Uint64 count);
};

Detailed Documentation

Provide write access to sound files.

This class encodes audio samples to a sound file. It is used internally by higher-level classes such as SoundBuffer, but can also be useful if you want to create audio files from custom data sources, like generated audio samples.

Usage example:

// Create a sound file, ogg/vorbis format, 44100 Hz, stereo
OutputSoundFile file;
if (!file.openFromFile("music.ogg", 44100, 2))
 /* error */;

while (...)
{
 // Read or generate audio samples from your custom source
 std::vector<Int16> samples = ...;

 // Write them to the file
 file.write(samples.data(), samples.size());
}

See also:

SoundFileWriter, InputSoundFile

Methods

bool openFromFile(const std::string& filename, unsigned int sampleRate, unsigned int channelCount)

Open the sound file from the disk for writing.

The supported audio formats are: WAV, OGG/Vorbis, FLAC.

Parameters:

filename

Path of the sound file to write

sampleRate

Sample rate of the sound

channelCount

Number of channels in the sound

Returns:

True if the file was successfully opened

void write(const Int16* samples, Uint64 count)

Write audio samples to the file.

Parameters:

samples

Pointer to the sample array to write

count

Number of samples to write