Public Member Functions | List of all members
cpp3ds::SoundFileWriter Class Referenceabstract

Abstract base class for sound file encoding. More...

#include <SoundFileWriter.hpp>

Inherited by cpp3ds::priv::SoundFileWriterOgg, and cpp3ds::priv::SoundFileWriterWav.

Public Member Functions

virtual ~SoundFileWriter ()
 Virtual destructor. More...
 
virtual bool open (const std::string &filename, unsigned int sampleRate, unsigned int channelCount)=0
 Open a sound file for writing. More...
 
virtual void write (const Int16 *samples, Uint64 count)=0
 Write audio samples to the open file. More...
 

Detailed Description

Abstract base class for sound file encoding.

This class allows users to write audio file formats not natively supported by cpp3ds, and thus extend the set of supported writable audio formats.

A valid sound file writer must override the open and write functions, as well as providing a static check function; the latter is used by cpp3ds to find a suitable writer for a given filename.

To register a new writer, use the cpp3ds::SoundFileFactory::registerWriter template function.

Usage example:

class MySoundFileWriter : public cpp3ds::SoundFileWriter
{
public:
static bool check(const std::string& filename)
{
// typically, check the extension
// return true if the writer can handle the format
}
virtual bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount)
{
// open the file 'filename' for writing,
// write the given sample rate and channel count to the file header
// return true on success
}
virtual void write(const cpp3ds::Int16* samples, cpp3ds::Uint64 count)
{
// write 'count' samples stored at address 'samples',
// convert them (for example to normalized float) if the format requires it
}
};
cpp3ds::SoundFileFactory::registerWriter<MySoundFileWriter>();
See also
cpp3ds::OutputSoundFile, cpp3ds::SoundFileFactory, cpp3ds::SoundFileReader

Definition at line 41 of file SoundFileWriter.hpp.

Constructor & Destructor Documentation

virtual cpp3ds::SoundFileWriter::~SoundFileWriter ( )
inlinevirtual

Virtual destructor.

Definition at line 49 of file SoundFileWriter.hpp.

Member Function Documentation

virtual bool cpp3ds::SoundFileWriter::open ( const std::string &  filename,
unsigned int  sampleRate,
unsigned int  channelCount 
)
pure virtual

Open a sound file for writing.

Parameters
filenamePath of the file to open
sampleRateSample rate of the sound
channelCountNumber of channels of the sound
Returns
True if the file was successfully opened
virtual void cpp3ds::SoundFileWriter::write ( const Int16 *  samples,
Uint64  count 
)
pure virtual

Write audio samples to the open 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: