Loading...
Searching...
No Matches
sf::SoundFileWriter Class Referenceabstract

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

#include <SFML/Audio/SoundFileWriter.hpp>

Public Member Functions

virtual ~SoundFileWriter ()=default
 Virtual destructor.
 
virtual bool open (const std::filesystem::path &filename, unsigned int sampleRate, unsigned int channelCount, const std::vector< SoundChannel > &channelMap)=0
 Open a sound file for writing.
 
virtual void write (const std::int16_t *samples, std::uint64_t count)=0
 Write audio samples to the open file.
 

Detailed Description

Abstract base class for sound file encoding.

This class allows users to write audio file formats not natively supported by SFML, 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 SFML to find a suitable writer for a given filename.

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

Usage example:

class MySoundFileWriter : public sf::SoundFileWriter
{
public:
[[nodiscard]] static bool check(const std::filesystem::path& filename)
{
// typically, check the extension
// return true if the writer can handle the format
}
[[nodiscard]] bool open(const std::filesystem::path& filename, unsigned int sampleRate, unsigned int channelCount, const std::vector<SoundChannel>& channelMap) override
{
// open the file 'filename' for writing,
// write the given sample rate and channel count to the file header
// return true on success
}
void write(const std::int16_t* samples, std::uint64_t count) override
{
// write 'count' samples stored at address 'samples',
// convert them (for example to normalized float) if the format requires it
}
};
static void registerWriter()
Register a new writer.
Abstract base class for sound file encoding.
virtual bool open(const std::filesystem::path &filename, unsigned int sampleRate, unsigned int channelCount, const std::vector< SoundChannel > &channelMap)=0
Open a sound file for writing.
virtual void write(const std::int16_t *samples, std::uint64_t count)=0
Write audio samples to the open file.
See also
sf::OutputSoundFile, sf::SoundFileFactory, sf::SoundFileReader

Definition at line 46 of file SoundFileWriter.hpp.

Constructor & Destructor Documentation

◆ ~SoundFileWriter()

virtual sf::SoundFileWriter::~SoundFileWriter ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ open()

virtual bool sf::SoundFileWriter::open ( const std::filesystem::path & filename,
unsigned int sampleRate,
unsigned int channelCount,
const std::vector< SoundChannel > & channelMap )
nodiscardpure 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
channelMapMap of position in sample frame to sound channel
Returns
true if the file was successfully opened

◆ write()

virtual void sf::SoundFileWriter::write ( const std::int16_t * samples,
std::uint64_t 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: