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

Object to hold some number of audio samples. More...

#include <audio.h>

Public Types

using Ptr = SharedPtr< Audio >
 Shared pointer type for Audio.
 
using List = promeki::List< Audio >
 List of Audio values.
 
using PtrList = promeki::List< Ptr >
 List of shared Audio pointers.
 

Public Member Functions

 Audio ()=default
 Constructs an invalid Audio object.
 
 Audio (const AudioDesc &desc, size_t samples, const MemSpace &ms=MemSpace::Default)
 Constructs an Audio object for the given descriptor and sample count.
 
bool isValid () const
 Returns true if the object is valid.
 
bool isNative () const
 Returns true if the audio is in the native float32 format for this system.
 
const AudioDescdesc () const
 Returns the AudioDesc that describes the audio contained in this object.
 
size_t samples () const
 Returns the number of samples, irrespective of the channel count.
 
size_t maxSamples () const
 Returns the maximum number of samples this object can contain.
 
size_t frames () const
 Returns the total number of sample frames (samples times channels).
 
const Buffer::Ptrbuffer () const
 Returns a const reference to the buffer that holds the audio data.
 
Buffer::Ptrbuffer ()
 Returns a mutable reference to the buffer shared pointer.
 
void zero () const
 Zeros out all the audio data in the buffer.
 
Audio convertTo (AudioDesc::DataType format) const
 Converts this Audio to a different sample format.
 
bool resize (size_t val)
 Resizes the sample count to a value between 0 and maxSamples().
 
template<typename T >
Tdata () const
 Returns the audio data pointer cast to the given type.
 

Detailed Description

Object to hold some number of audio samples.

This object is meant to hold some number of audio samples described by an AudioDesc. The sample data is stored in a shared Buffer. When shared ownership is needed, use Audio::Ptr.

Example
AudioDesc desc(48000, 2, AudioDesc::Float32);
Audio audio(desc, 1024); // 1024 samples
// Shared ownership for pipeline passing
Audio::Ptr shared = Audio::Ptr::create(desc, 1024);
Describes an audio format including sample type, rate, and channel count.
Definition audiodesc.h:28
Object to hold some number of audio samples.
Definition audio.h:35
SharedPtr< Audio > Ptr
Shared pointer type for Audio.
Definition audio.h:39
promeki::List< Audio > List
List of Audio values.
Definition audio.h:42
const AudioDesc & desc() const
Returns the AudioDesc that describes the audio contained in this object.
Definition audio.h:79

Constructor & Destructor Documentation

◆ Audio()

Audio::Audio ( const AudioDesc desc,
size_t  samples,
const MemSpace ms = MemSpace::Default 
)

Constructs an Audio object for the given descriptor and sample count.

Parameters
descAudio descriptor specifying format, sample rate, and channels.
samplesNumber of samples to allocate.
msMemory space to allocate the buffer from.

Member Function Documentation

◆ buffer() [1/2]

Buffer::Ptr & Audio::buffer ( )
inline

Returns a mutable reference to the buffer shared pointer.

Returns
A mutable reference to the Buffer shared pointer.

◆ buffer() [2/2]

const Buffer::Ptr & Audio::buffer ( ) const
inline

Returns a const reference to the buffer that holds the audio data.

Returns
A const reference to the Buffer shared pointer.

◆ convertTo()

Audio Audio::convertTo ( AudioDesc::DataType  format) const

Converts this Audio to a different sample format.

Returns a new Audio object with the same sample rate, channel count, and sample count but with audio data converted to the target format. When the source is native float, this is a single-pass conversion.

Parameters
formatThe target AudioDesc::DataType.
Returns
A new Audio object in the target format, or an invalid Audio on failure.

◆ data()

template<typename T >
T * Audio::data ( ) const
inline

Returns the audio data pointer cast to the given type.

Template Parameters
TThe sample data type to cast to (e.g. float, int16_t).
Returns
A typed pointer to the audio sample data.

◆ desc()

const AudioDesc & Audio::desc ( ) const
inline

Returns the AudioDesc that describes the audio contained in this object.

Returns
A const reference to the AudioDesc.

◆ frames()

size_t Audio::frames ( ) const
inline

Returns the total number of sample frames (samples times channels).

Returns
The frame count.

◆ isNative()

bool Audio::isNative ( ) const
inline

Returns true if the audio is in the native float32 format for this system.

Returns
true if the format is native float32.

◆ isValid()

bool Audio::isValid ( ) const
inline

Returns true if the object is valid.

Returns
true if the audio descriptor is valid.

◆ maxSamples()

size_t Audio::maxSamples ( ) const
inline

Returns the maximum number of samples this object can contain.

Returns
The maximum sample count.

◆ resize()

bool Audio::resize ( size_t  val)
inline

Resizes the sample count to a value between 0 and maxSamples().

Parameters
valThe new sample count.
Returns
true if successful, false if val exceeds maxSamples().

◆ samples()

size_t Audio::samples ( ) const
inline

Returns the number of samples, irrespective of the channel count.

Returns
The number of samples.

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