Describes an audio format including sample type, rate, and channel count. More...
#include <audiodesc.h>
Classes | |
| struct | Format |
| Descriptor for a specific audio sample format. More... | |
Public Types | |
| enum | DataType { Invalid = 0 , PCMI_Float32LE , PCMI_Float32BE , PCMI_S8 , PCMI_U8 , PCMI_S16LE , PCMI_U16LE , PCMI_S16BE , PCMI_U16BE , PCMI_S24LE , PCMI_U24LE , PCMI_S24BE , PCMI_U24BE , PCMI_S32LE , PCMI_U32LE , PCMI_S32BE , PCMI_U32BE } |
| Enumeration of supported audio sample data types. More... | |
| using | Ptr = SharedPtr< AudioDesc > |
| Shared pointer type for AudioDesc. | |
Public Member Functions | |
| AudioDesc () | |
| Constructs an invalid (default) audio description. | |
| AudioDesc (float sr, unsigned int ch) | |
| Constructs an audio description with the native float format. | |
| AudioDesc (DataType dt, float sr, unsigned int ch) | |
| Constructs an audio description with the specified data type, sample rate, and channels. | |
| bool | formatEquals (const AudioDesc &other) const |
| Returns true if both audio descriptions have equal format (type, rate, channels). | |
| bool | operator== (const AudioDesc &other) const |
| Returns true if both audio descriptions are fully equal, including metadata. | |
| bool | isValid () const |
| Returns true if this audio description has a valid data type, sample rate, and channel count. | |
| bool | isNative () const |
| Returns true if the data type is the platform's native float format. | |
| AudioDesc | workingDesc () const |
| Returns a new AudioDesc with the same sample rate and channels but using the native float format. | |
| String | toString () const |
| Returns a human-readable string representation of this audio description. | |
| JsonObject | toJson () const |
| Serializes this audio description to a JSON object. | |
| size_t | bytesPerSample () const |
| Returns the number of bytes per single sample. | |
| size_t | bytesPerSampleStride () const |
| Returns the byte stride between consecutive samples of the same channel. | |
| size_t | channelBufferOffset (unsigned int chan, size_t bufferSamples) const |
| Returns the byte offset to a specific channel within a sample buffer. | |
| size_t | bufferSize (size_t samples) const |
| Returns the total buffer size in bytes needed to store the given number of samples. | |
| DataType | dataType () const |
| Returns the data type of this audio description. | |
| void | setDataType (DataType val) |
| Sets the data type. | |
| float | sampleRate () const |
| Returns the sample rate in Hz. | |
| void | setSampleRate (float val) |
| Sets the sample rate. | |
| unsigned int | channels () const |
| Returns the number of audio channels. | |
| void | setChannels (unsigned int val) |
| Sets the number of audio channels. | |
| const Metadata & | metadata () const |
| Returns a const reference to the metadata. | |
| Metadata & | metadata () |
| Returns a mutable reference to the metadata. | |
| void | samplesToFloat (float *out, const uint8_t *in, size_t samples) const |
| Converts samples from this description's format to normalized floats. | |
| void | floatToSamples (uint8_t *out, const float *in, size_t samples) const |
| Converts normalized floats to samples in this description's format. | |
Static Public Member Functions | |
| template<typename IntegerType , IntegerType Min, IntegerType Max> | |
| static float | integerToFloat (IntegerType value) |
| Converts an integer sample value to a normalized float in [-1, 1]. | |
| template<typename IntegerType > | |
| static float | integerToFloat (IntegerType value) |
| Converts an integer sample value to a normalized float using the type's full range. | |
| template<typename IntegerType , IntegerType Min, IntegerType Max> | |
| static IntegerType | floatToInteger (float value) |
| Converts a normalized float in [-1, 1] to an integer sample value. | |
| template<typename IntegerType > | |
| static IntegerType | floatToInteger (float value) |
| Converts a normalized float to an integer sample using the type's full range. | |
| template<typename IntegerType , bool InputIsBigEndian> | |
| static void | samplesToFloat (float *out, const uint8_t *inbuf, size_t samples) |
| Converts a buffer of integer samples to normalized floats. | |
| template<typename IntegerType , bool OutputIsBigEndian> | |
| static void | floatToSamples (uint8_t *outbuf, const float *in, size_t samples) |
| Converts a buffer of normalized floats to integer samples. | |
| static const Format * | lookupFormat (int id) |
| Looks up a Format descriptor by its DataType id. | |
| static DataType | stringToDataType (const String &val) |
| Converts a string name to its corresponding DataType enum value. | |
| static AudioDesc | fromJson (const JsonObject &json, Error *err=nullptr) |
| Constructs an AudioDesc from a JSON object. | |
Static Public Attributes | |
| static const int32_t | MinS24 = -8388608 |
| Minimum value of a signed 24-bit integer. | |
| static const int32_t | MaxS24 = 8388607 |
| Maximum value of a signed 24-bit integer. | |
| static const int32_t | MinU24 = 0 |
| Minimum value of an unsigned 24-bit integer. | |
| static const int32_t | MaxU24 = 16777215 |
| Maximum value of an unsigned 24-bit integer. | |
| static constexpr DataType | NativeType = System::isLittleEndian() ? PCMI_Float32LE : PCMI_Float32BE |
| The native float format for the current platform's endianness. | |
Describes an audio format including sample type, rate, and channel count.
AudioDesc encapsulates the complete description of an audio format: the sample data type (e.g. PCM signed 16-bit little-endian), sample rate, and number of channels. It also provides static utility methods for converting between integer sample representations and normalized floating-point values in the range [-1, 1].
Enumeration of supported audio sample data types.
PCMI = PCM audio with interleaved channels. PCMP = PCM audio with planar channels.
Constructs an audio description with the native float format.
If the resulting description is not valid, all fields are reset to invalid.
| sr | Sample rate in Hz. |
| ch | Number of audio channels. |
Constructs an audio description with the specified data type, sample rate, and channels.
If the resulting description is not valid, all fields are reset to invalid.
| dt | Data type (sample format). |
| sr | Sample rate in Hz. |
| ch | Number of audio channels. |
Returns the total buffer size in bytes needed to store the given number of samples.
| samples | Number of samples per channel. |
|
inline |
Returns the number of bytes per single sample.
|
inline |
Returns the byte stride between consecutive samples of the same channel.
For planar formats this is the single sample size; for interleaved formats it is the sample size multiplied by the number of channels.
Returns the byte offset to a specific channel within a sample buffer.
For planar formats, the offset is channel * bytesPerSample * bufferSamples. For interleaved formats, it is channel * bytesPerSample.
| chan | The channel index (zero-based). |
| bufferSamples | Total number of samples per channel in the buffer. |
|
inline |
Returns the number of audio channels.
|
inline |
Returns the data type of this audio description.
|
inlinestatic |
Converts a normalized float in [-1, 1] to an integer sample value.
Maps the float range [-1.0, 1.0] linearly onto the integer range [Min, Max]. Values outside [-1, 1] are clamped.
| IntegerType | The integer sample type. |
| Min | The minimum value of the integer range. |
| Max | The maximum value of the integer range. |
| value | The normalized float sample to convert. |
|
inlinestatic |
Converts a normalized float to an integer sample using the type's full range.
| IntegerType | The integer sample type whose numeric_limits define the range. |
| value | The normalized float sample to convert. |
Converts normalized floats to samples in this description's format.
| out | Destination buffer for raw sample bytes. |
| in | Source buffer of float samples. |
| samples | Number of samples per channel to convert. |
|
inlinestatic |
Converts a buffer of normalized floats to integer samples.
Handles endian conversion if the output byte order differs from the host.
| IntegerType | The integer sample type. |
| OutputIsBigEndian | True if the output buffer should be big-endian. |
| outbuf | Destination buffer for raw integer sample bytes. |
| in | Source buffer of float samples. |
| samples | Number of samples to convert. |
Returns true if both audio descriptions have equal format (type, rate, channels).
| other | The AudioDesc to compare against. |
|
inlinestatic |
Converts an integer sample value to a normalized float in [-1, 1].
Maps the integer range [Min, Max] linearly onto the float range [-1.0, 1.0].
| IntegerType | The integer sample type. |
| Min | The minimum value of the integer range. |
| Max | The maximum value of the integer range. |
| value | The integer sample to convert. |
|
inlinestatic |
Converts an integer sample value to a normalized float using the type's full range.
| IntegerType | The integer sample type whose numeric_limits define the range. |
| value | The integer sample to convert. |
|
inline |
Returns true if the data type is the platform's native float format.
|
inline |
Returns true if this audio description has a valid data type, sample rate, and channel count.
Returns true if both audio descriptions are fully equal, including metadata.
| other | The AudioDesc to compare against. |
|
inline |
Returns the sample rate in Hz.
Converts samples from this description's format to normalized floats.
| out | Destination buffer for float samples. |
| in | Source buffer of raw sample bytes. |
| samples | Number of samples per channel to convert. |
|
inlinestatic |
Converts a buffer of integer samples to normalized floats.
Handles endian conversion if the input byte order differs from the host.
| IntegerType | The integer sample type. |
| InputIsBigEndian | True if the input buffer is big-endian. |
| out | Destination buffer for float samples. |
| inbuf | Source buffer of raw integer sample bytes. |
| samples | Number of samples to convert. |
Sets the number of audio channels.
| val | The new channel count. |
Sets the data type.
| val | The new DataType value. |
Sets the sample rate.
| val | The new sample rate in Hz. |
Converts a string name to its corresponding DataType enum value.
| val | The format name string (e.g. "PCMI_S16LE"). |
|
inline |
Serializes this audio description to a JSON object.
|
inline |
Returns a human-readable string representation of this audio description.
|
inline |