libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
AudioFile Class Reference

Audio file reader and writer. More...

#include <audiofile.h>

Classes

class  Impl
 Abstract implementation backend for AudioFile. More...
 

Public Types

enum  Operation { InvalidOperation = 0 , Reader , Writer }
 The type of operation to perform on an audio file. More...
 
using Ptr = SharedPtr< AudioFile >
 Shared pointer type for AudioFile.
 

Public Member Functions

 AudioFile ()
 Default constructor. Creates an invalid AudioFile.
 
 AudioFile (Impl *impl)
 Constructs an AudioFile from an Impl pointer, taking ownership.
 
bool isValid () const
 Returns true if this AudioFile has a valid operation.
 
Operation operation () const
 Returns the operation type (Reader or Writer).
 
const Stringfilename () const
 Returns the filename associated with this audio file.
 
void setFilename (const String &val)
 Sets the filename for this audio file.
 
AudioDesc desc () const
 Returns the audio description.
 
void setDesc (const AudioDesc &val)
 Sets the audio description for writing.
 
IODevicedevice () const
 Returns the IODevice associated with this audio file.
 
Error open ()
 Opens the audio file.
 
void close ()
 Closes the audio file.
 
Error read (Audio &audio, size_t maxSamples)
 Reads audio samples from the file.
 
Error write (const Audio &audio)
 Writes audio samples to the file.
 
Error seekToSample (size_t sample)
 Seeks to a specific sample position in the file.
 
size_t sampleCount () const
 Returns the total number of samples in the file.
 

Static Public Member Functions

static AudioFile createForOperation (Operation op, const String &filename)
 Creates an AudioFile for the given operation and filename.
 
static Result< AudioFilecreateForOperation (Operation op, IODevice *device, const String &formatHint="")
 Creates an AudioFile for the given operation using an IODevice.
 
static AudioFile createReader (const String &filename)
 Creates an AudioFile reader for the given filename.
 
static AudioFile createWriter (const String &filename)
 Creates an AudioFile writer for the given filename.
 

Detailed Description

Audio file reader and writer.

Provides a high-level interface for reading and writing audio files. The actual file format handling is delegated to an Impl subclass, which is selected automatically via AudioFileFactory based on the filename extension, format hint, or IODevice probe.

All code paths use sf_open_virtual() internally. When a filename is provided without an explicit IODevice, the backend creates an internal File IODevice automatically. An external IODevice can be supplied for non-file backends (e.g. BufferIODevice for in-memory operation).

IODevice lifetime
When a caller provides an IODevice, that device must outlive the AudioFile. Caller-provided devices are non-owning (not deleted on close). Internally-created devices are owned and deleted on close.

Member Enumeration Documentation

◆ Operation

The type of operation to perform on an audio file.

Enumerator
InvalidOperation 

No valid operation.

Reader 

Open the file for reading.

Writer 

Open the file for writing.

Constructor & Destructor Documentation

◆ AudioFile()

AudioFile::AudioFile ( Impl impl)
inline

Constructs an AudioFile from an Impl pointer, taking ownership.

Parameters
implPointer to the implementation object.

Member Function Documentation

◆ createForOperation() [1/2]

static AudioFile AudioFile::createForOperation ( Operation  op,
const String filename 
)
static

Creates an AudioFile for the given operation and filename.

Uses AudioFileFactory to find an appropriate backend implementation.

Parameters
opThe operation (Reader or Writer).
filenameThe path to the audio file.
Returns
An AudioFile configured for the requested operation.

◆ createForOperation() [2/2]

static Result< AudioFile > AudioFile::createForOperation ( Operation  op,
IODevice device,
const String formatHint = "" 
)
static

Creates an AudioFile for the given operation using an IODevice.

Uses AudioFileFactory to find an appropriate backend. The device must be seekable (non-sequential) and must outlive the AudioFile.

Parameters
opThe operation (Reader or Writer).
deviceThe IODevice to read from or write to.
formatHintExtension hint (e.g. "wav"), no dot.
Returns
A Result containing the AudioFile, or an error.

◆ createReader()

static AudioFile AudioFile::createReader ( const String filename)
inlinestatic

Creates an AudioFile reader for the given filename.

Parameters
filenameThe path to the audio file to read.
Returns
An AudioFile configured for reading.

◆ createWriter()

static AudioFile AudioFile::createWriter ( const String filename)
inlinestatic

Creates an AudioFile writer for the given filename.

Parameters
filenameThe path to the audio file to write.
Returns
An AudioFile configured for writing.

◆ desc()

AudioDesc AudioFile::desc ( ) const
inline

Returns the audio description.

Returns
The AudioDesc for this file.

◆ device()

IODevice * AudioFile::device ( ) const
inline

Returns the IODevice associated with this audio file.

Returns
The device pointer, or nullptr.

◆ filename()

const String & AudioFile::filename ( ) const
inline

Returns the filename associated with this audio file.

Returns
A const reference to the filename string.

◆ isValid()

bool AudioFile::isValid ( ) const
inline

Returns true if this AudioFile has a valid operation.

Returns
true if the underlying implementation is valid.

◆ open()

Error AudioFile::open ( )
inline

Opens the audio file.

Returns
Error::Ok on success, or an error on failure.

◆ operation()

Operation AudioFile::operation ( ) const
inline

Returns the operation type (Reader or Writer).

Returns
The Operation value.

◆ read()

Error AudioFile::read ( Audio audio,
size_t  maxSamples 
)
inline

Reads audio samples from the file.

Parameters
audioThe Audio object to read into.
maxSamplesMaximum number of samples to read.
Returns
Error::Ok on success, or an error on failure.

◆ sampleCount()

size_t AudioFile::sampleCount ( ) const
inline

Returns the total number of samples in the file.

Returns
The sample count.

◆ seekToSample()

Error AudioFile::seekToSample ( size_t  sample)
inline

Seeks to a specific sample position in the file.

Parameters
sampleThe sample index to seek to.
Returns
Error::Ok on success, or an error on failure.

◆ setDesc()

void AudioFile::setDesc ( const AudioDesc val)
inline

Sets the audio description for writing.

Parameters
valThe AudioDesc to set.

◆ setFilename()

void AudioFile::setFilename ( const String val)
inline

Sets the filename for this audio file.

Parameters
valThe filename to set.

◆ write()

Error AudioFile::write ( const Audio audio)
inline

Writes audio samples to the file.

Parameters
audioThe Audio object containing samples to write.
Returns
Error::Ok on success, or an error on failure.

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