Public Member Functions | List of all members
cpp3ds::OutputSoundFile Class Reference

Provide write access to sound files. More...

#include <OutputSoundFile.hpp>

Inheritance diagram for cpp3ds::OutputSoundFile:
cpp3ds::NonCopyable

Public Member Functions

 OutputSoundFile ()
 Default constructor. More...
 
 ~OutputSoundFile ()
 Destructor. More...
 
bool openFromFile (const std::string &filename, unsigned int sampleRate, unsigned int channelCount)
 Open the sound file from the disk for writing. More...
 
void write (const Int16 *samples, Uint64 count)
 Write audio samples to the file. More...
 

Detailed Description

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 cpp3ds::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
if (!file.openFromFile("music.ogg", 44100, 2))
/* error */;
while (...)
{
// Read or generate audio samples from your custom source
std::vector<cpp3ds::Int16> samples = ...;
// Write them to the file
file.write(samples.data(), samples.size());
}
See also
cpp3ds::SoundFileWriter, cpp3ds::InputSoundFile

Definition at line 44 of file OutputSoundFile.hpp.

Constructor & Destructor Documentation

cpp3ds::OutputSoundFile::OutputSoundFile ( )

Default constructor.

cpp3ds::OutputSoundFile::~OutputSoundFile ( )

Destructor.

Closes the file if it was still open.

Member Function Documentation

bool cpp3ds::OutputSoundFile::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
filenamePath of the sound file to write
sampleRateSample rate of the sound
channelCountNumber of channels in the sound
Returns
True if the file was successfully opened
void cpp3ds::OutputSoundFile::write ( const Int16 *  samples,
Uint64  count 
)

Write audio samples to the file.

Parameters
samplesPointer to the sample array to write
countNumber of samples to write

The documentation for this class was generated from the following file: