foobar2000 SDK
2015-08-03
|
#include <audio_chunk.h>
Data Structures | |
struct | spec_t |
Public Types | |
enum | { sample_rate_min = 1000, sample_rate_max = 2822400 } |
enum | { channel_front_left = 1<<0, channel_front_right = 1<<1, channel_front_center = 1<<2, channel_lfe = 1<<3, channel_back_left = 1<<4, channel_back_right = 1<<5, channel_front_center_left = 1<<6, channel_front_center_right = 1<<7, channel_back_center = 1<<8, channel_side_left = 1<<9, channel_side_right = 1<<10, channel_top_center = 1<<11, channel_top_front_left = 1<<12, channel_top_front_center = 1<<13, channel_top_front_right = 1<<14, channel_top_back_left = 1<<15, channel_top_back_center = 1<<16, channel_top_back_right = 1<<17, channel_config_mono = channel_front_center, channel_config_stereo = channel_front_left | channel_front_right, channel_config_5point1 = channel_front_left | channel_front_right | channel_front_center | channel_lfe | channel_back_left | channel_back_right, channel_config_5point1_side = channel_front_left | channel_front_right | channel_front_center | channel_lfe | channel_side_left | channel_side_right, channel_config_7point1 = channel_config_5point1 | channel_side_left | channel_side_right, defined_channel_count = 18 } |
enum | { FLAG_LITTLE_ENDIAN = 1, FLAG_BIG_ENDIAN = 2, FLAG_SIGNED = 4, FLAG_UNSIGNED = 8 } |
Public Member Functions | |
void | allocate (size_t size) |
void | copy (const audio_chunk &p_source) |
virtual unsigned | get_channel_config () const =0 |
unsigned | get_channel_count () const |
virtual unsigned | get_channels () const =0 |
virtual audio_sample * | get_data ()=0 |
virtual const audio_sample * | get_data () const =0 |
size_t | get_data_length () const |
virtual t_size | get_data_size () const =0 |
double | get_duration () const |
audio_sample | get_peak (audio_sample p_peak) const |
audio_sample | get_peak () const |
virtual t_size | get_sample_count () const =0 |
unsigned | get_sample_rate () const |
spec_t | get_spec () const |
virtual unsigned | get_srate () const =0 |
size_t | get_used_size () const |
void | grow_data_size (t_size p_requested) |
void | insert_silence_fromstart (t_size samples) |
bool | is_empty () const |
bool | is_spec_valid () const |
bool | is_valid () const |
const audio_chunk & | operator= (const audio_chunk &p_source) |
void | pad_with_silence (t_size samples) |
void | pad_with_silence_ex (t_size samples, unsigned hint_nch, unsigned hint_srate) |
bool | process_skip (double &skipDuration) |
void | reset () |
void | scale (audio_sample p_value) |
virtual void | set_channels (unsigned p_count, unsigned p_config)=0 |
void | set_channels (unsigned val) |
void | set_data (const audio_sample *src, t_size samples, unsigned nch, unsigned srate, unsigned channel_config) |
void | set_data (const audio_sample *src, t_size samples, unsigned nch, unsigned srate) |
void | set_data_32 (const float *src, t_size samples, unsigned nch, unsigned srate) |
void | set_data_fixedpoint (const void *ptr, t_size bytes, unsigned srate, unsigned nch, unsigned bps, unsigned channel_config) |
void | set_data_fixedpoint_ex (const void *ptr, t_size bytes, unsigned p_sample_rate, unsigned p_channels, unsigned p_bits_per_sample, unsigned p_flags, unsigned p_channel_config) |
void | set_data_fixedpoint_ms (const void *ptr, size_t bytes, unsigned sampleRate, unsigned channels, unsigned bps, unsigned channelConfig) |
void | set_data_fixedpoint_signed (const void *ptr, t_size bytes, unsigned srate, unsigned nch, unsigned bps, unsigned channel_config) |
void | set_data_floatingpoint_ex (const void *ptr, t_size bytes, unsigned p_sample_rate, unsigned p_channels, unsigned p_bits_per_sample, unsigned p_flags, unsigned p_channel_config) |
void | set_data_int16 (const int16_t *src, t_size samples, unsigned nch, unsigned srate, unsigned channel_config) |
virtual void | set_data_size (t_size p_new_size)=0 |
virtual void | set_sample_count (t_size val)=0 |
void | set_sample_rate (unsigned val) |
void | set_silence (t_size samples) |
void | set_silence_seconds (double seconds) |
void | set_spec (const spec_t &) |
virtual void | set_srate (unsigned val)=0 |
t_size | skip_first_samples (t_size samples) |
bool | to_raw_data (class mem_block_container &out, t_uint32 bps, bool useUpperBits=true, float scale=1.0) const |
bool | toFixedPoint (class mem_block_container &out, uint32_t bps, uint32_t bpsValid, bool useUpperBits=true, float scale=1.0) const |
Static Public Member Functions | |
static unsigned | flags_autoendian () |
static unsigned | g_channel_config_from_wfx (uint32_t p_wfx) |
static uint32_t | g_channel_config_to_wfx (unsigned p_config) |
static unsigned | g_channel_index_from_flag (unsigned p_config, unsigned p_flag) |
static const char * | g_channel_name (unsigned p_flag) |
static const char * | g_channel_name_byidx (unsigned p_index) |
static unsigned | g_count_channels (unsigned p_config) |
static unsigned | g_extract_channel_flag (unsigned p_config, unsigned p_index) |
static unsigned | g_find_channel_idx (unsigned p_flag) |
static void | g_formatChannelMaskDesc (unsigned flags, pfc::string_base &out) |
static unsigned | g_guess_channel_config (unsigned count) |
static unsigned | g_guess_channel_config_xiph (unsigned count) |
static bool | g_is_valid_sample_rate (t_uint32 p_val) |
static bool | g_toFixedPoint (const audio_sample *in, void *out, size_t count, uint32_t bps, uint32_t bpsValid, bool useUpperBits=true, float scale=1.0) |
static spec_t | makeSpec (uint32_t rate, uint32_t channels) |
static spec_t | makeSpec (uint32_t rate, uint32_t channels, uint32_t chanMask) |
Protected Member Functions | |
audio_chunk () | |
~audio_chunk () | |
Interface to container of a chunk of audio data. See audio_chunk_impl for an implementation.
Definition at line 5 of file audio_chunk.h.
anonymous enum |
Enumerator | |
---|---|
sample_rate_min | |
sample_rate_max |
Definition at line 8 of file audio_chunk.h.
anonymous enum |
Channel map flag declarations. Note that order of interleaved channel data in the stream is same as order of these flags.
Definition at line 14 of file audio_chunk.h.
anonymous enum |
Enumerator | |
---|---|
FLAG_LITTLE_ENDIAN | |
FLAG_BIG_ENDIAN | |
FLAG_SIGNED | |
FLAG_UNSIGNED |
Definition at line 162 of file audio_chunk.h.
|
inlineprotected |
Definition at line 236 of file audio_chunk.h.
|
inlineprotected |
Definition at line 237 of file audio_chunk.h.
|
inline |
Sanity helper, same as set_data_size.
Definition at line 79 of file audio_chunk.h.
|
inline |
Helper; copies content of another audio chunk to this chunk.
Definition at line 212 of file audio_chunk.h.
|
inlinestatic |
Definition at line 170 of file audio_chunk.h.
|
static |
Helper function; translates WAVEFORMATEXTENSIBLE channel map to audio_chunk channel map.
Definition at line 67 of file audio_chunk_channel_config.cpp.
|
static |
Helper function; translates audio_chunk channel map to WAVEFORMATEXTENSIBLE channel map.
Definition at line 53 of file audio_chunk_channel_config.cpp.
|
static |
Calculates index of a channel specified by p_flag in a stream where channel map is described by p_config.
Definition at line 119 of file audio_chunk_channel_config.cpp.
|
static |
Definition at line 192 of file audio_chunk_channel_config.cpp.
|
static |
Definition at line 196 of file audio_chunk_channel_config.cpp.
|
static |
Counts channels specified by channel map.
Definition at line 145 of file audio_chunk_channel_config.cpp.
|
static |
Extracts flag describing Nth channel from specified map. Usable to figure what specific channel in a stream means.
Definition at line 129 of file audio_chunk_channel_config.cpp.
|
static |
Definition at line 171 of file audio_chunk_channel_config.cpp.
|
static |
Definition at line 201 of file audio_chunk_channel_config.cpp.
|
static |
Helper function; guesses default channel map for the specified channel count. Returns 0 on failure.
Definition at line 108 of file audio_chunk_channel_config.cpp.
|
static |
Helper function; determines channel map for the specified channel count according to Xiph specs. Throws exception_io_data on failure.
Definition at line 114 of file audio_chunk_channel_config.cpp.
|
inlinestatic |
Definition at line 11 of file audio_chunk.h.
|
static |
Convert a buffer of audio_samples to fixed-point PCM format.
useUpperBits | relevant if bps != bpsValid, signals whether upper or lower bits of each sample should be used. |
Definition at line 517 of file audio_chunk.cpp.
|
pure virtual |
Retrieves channel map of contained audio data. Conditions where number of channels specified by channel map don't match get_channels() return value should not be possible.
Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.
|
inline |
Helper - for consistency - same as get_channels().
Definition at line 88 of file audio_chunk.h.
|
pure virtual |
Retrieves channel count of contained audio data.
Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.
|
pure virtual |
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; it is valid until next set_data_size call, or until the object is destroyed.
Size of returned buffer is equal to get_data_size() return value (in audio_samples). Amount of actual data may be smaller, depending on sample count and channel count. Conditions where sample count * channel count are greater than data size should not be possible.
Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.
|
pure virtual |
Retrieves audio data buffer pointer (const version). Returned pointer is for temporary use only; it is valid until next set_data_size call, or until the object is destroyed.
Size of returned buffer is equal to get_data_size() return value (in audio_samples). Amount of actual data may be smaller, depending on sample count and channel count. Conditions where sample count * channel count are greater than data size should not be possible.
Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.
|
inline |
Same as get_used_size(); old confusingly named version.
Definition at line 136 of file audio_chunk.h.
|
pure virtual |
Retrieves size of allocated buffer space, in audio_samples.
Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.
|
inline |
Retrieves duration of contained audio data, in seconds.
Definition at line 116 of file audio_chunk.h.
audio_sample audio_chunk::get_peak | ( | audio_sample | p_peak | ) | const |
Helper, calculates peak value of data in the chunk. The optional parameter specifies initial peak value, to simplify calling code.
Definition at line 437 of file audio_chunk.cpp.
audio_sample audio_chunk::get_peak | ( | ) | const |
Definition at line 441 of file audio_chunk.cpp.
|
pure virtual |
Retrieves number of valid samples in the buffer.
Note that a "sample" means a unit of interleaved PCM data representing states of each channel at given point of time, not a single PCM value.
For an example, duration of contained audio data is equal to sample count / sample rate, while actual size of contained data is equal to sample count * channel count.
Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.
|
inline |
Helper, same as get_srate().
Definition at line 103 of file audio_chunk.h.
audio_chunk::spec_t audio_chunk::get_spec | ( | ) | const |
Definition at line 580 of file audio_chunk.cpp.
|
pure virtual |
Retrieves sample rate of contained audio data.
Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.
|
inline |
Returns actual amount of audio data contained in the buffer (sample count * channel count). Must not be greater than data size (see get_data_size()).
Definition at line 134 of file audio_chunk.h.
|
inline |
Helper; resizes audio data buffer when its current size is smaller than requested.
Definition at line 112 of file audio_chunk.h.
void audio_chunk::insert_silence_fromstart | ( | t_size | samples | ) |
Definition at line 388 of file audio_chunk.cpp.
|
inline |
Returns whether the chunk is empty (contains no audio data).
Definition at line 125 of file audio_chunk.h.
bool audio_chunk::is_spec_valid | ( | ) | const |
Returns whether the chunk contains valid sample rate & channel info (but allows an empty chunk).
Definition at line 341 of file audio_chunk.cpp.
bool audio_chunk::is_valid | ( | ) | const |
Returns whether the chunk contents are valid (for bug check purposes).
Definition at line 328 of file audio_chunk.cpp.
|
static |
Definition at line 566 of file audio_chunk.cpp.
|
static |
Definition at line 570 of file audio_chunk.cpp.
|
inline |
Definition at line 216 of file audio_chunk.h.
void audio_chunk::pad_with_silence | ( | t_size | samples | ) |
Definition at line 366 of file audio_chunk.cpp.
void audio_chunk::pad_with_silence_ex | ( | t_size | samples, |
unsigned | hint_nch, | ||
unsigned | hint_srate | ||
) |
Definition at line 345 of file audio_chunk.cpp.
bool audio_chunk::process_skip | ( | double & | skipDuration | ) |
Definition at line 399 of file audio_chunk.cpp.
|
inline |
Resets all audio_chunk data.
Definition at line 140 of file audio_chunk.h.
void audio_chunk::scale | ( | audio_sample | p_value | ) |
Helper function; scales entire chunk content by specified value.
Definition at line 445 of file audio_chunk.cpp.
|
pure virtual |
Sets channel count / channel map.
Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.
|
inline |
Helper; sets channel count to specified value and uses default channel map for this channel count.
Definition at line 108 of file audio_chunk.h.
void audio_chunk::set_data | ( | const audio_sample * | src, |
t_size | samples, | ||
unsigned | nch, | ||
unsigned | srate, | ||
unsigned | channel_config | ||
) |
Helper, sets chunk data to contents of specified buffer, with specified number of channels / sample rate / channel map.
Definition at line 3 of file audio_chunk.cpp.
|
inline |
Helper, sets chunk data to contents of specified buffer, with specified number of channels / sample rate, using default channel map for specified channel count.
Definition at line 151 of file audio_chunk.h.
|
inline |
Definition at line 180 of file audio_chunk.h.
|
inline |
Helper, sets chunk data to contents of specified buffer, using default win32/wav conventions for signed/unsigned switch.
Definition at line 156 of file audio_chunk.h.
void audio_chunk::set_data_fixedpoint_ex | ( | const void * | ptr, |
t_size | bytes, | ||
unsigned | p_sample_rate, | ||
unsigned | p_channels, | ||
unsigned | p_bits_per_sample, | ||
unsigned | p_flags, | ||
unsigned | p_channel_config | ||
) |
Definition at line 123 of file audio_chunk.cpp.
void audio_chunk::set_data_fixedpoint_ms | ( | const void * | ptr, |
size_t | bytes, | ||
unsigned | sampleRate, | ||
unsigned | channels, | ||
unsigned | bps, | ||
unsigned | channelConfig | ||
) |
Definition at line 200 of file audio_chunk.cpp.
void audio_chunk::set_data_fixedpoint_signed | ( | const void * | ptr, |
t_size | bytes, | ||
unsigned | srate, | ||
unsigned | nch, | ||
unsigned | bps, | ||
unsigned | channel_config | ||
) |
Definition at line 229 of file audio_chunk.cpp.
void audio_chunk::set_data_floatingpoint_ex | ( | const void * | ptr, |
t_size | bytes, | ||
unsigned | p_sample_rate, | ||
unsigned | p_channels, | ||
unsigned | p_bits_per_sample, | ||
unsigned | p_flags, | ||
unsigned | p_channel_config | ||
) |
Definition at line 282 of file audio_chunk.cpp.
void audio_chunk::set_data_int16 | ( | const int16_t * | src, |
t_size | samples, | ||
unsigned | nch, | ||
unsigned | srate, | ||
unsigned | channel_config | ||
) |
Definition at line 257 of file audio_chunk.cpp.
|
pure virtual |
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.
|
pure virtual |
Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be above allocated buffer size.
Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.
|
inline |
Helper, same as set_srate().
Definition at line 105 of file audio_chunk.h.
void audio_chunk::set_silence | ( | t_size | samples | ) |
Definition at line 377 of file audio_chunk.cpp.
void audio_chunk::set_silence_seconds | ( | double | seconds | ) |
Definition at line 384 of file audio_chunk.cpp.
void audio_chunk::set_spec | ( | const spec_t & | spec | ) |
Definition at line 587 of file audio_chunk.cpp.
|
pure virtual |
Sets sample rate of contained audio data.
Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.
Definition at line 416 of file audio_chunk.cpp.
bool audio_chunk::to_raw_data | ( | class mem_block_container & | out, |
t_uint32 | bps, | ||
bool | useUpperBits = true , |
||
float | scale = 1.0 |
||
) | const |
Simple function to get original PCM stream back. Assumes host's endianness, integers are signed - including the 8bit mode; 32bit mode assumed to be float.
Definition at line 550 of file audio_chunk.cpp.
bool audio_chunk::toFixedPoint | ( | class mem_block_container & | out, |
uint32_t | bps, | ||
uint32_t | bpsValid, | ||
bool | useUpperBits = true , |
||
float | scale = 1.0 |
||
) | const |
Convert audio_chunk contents to fixed-point PCM format.
useUpperBits | relevant if bps != bpsValid, signals whether upper or lower bits of each sample should be used. |
Definition at line 542 of file audio_chunk.cpp.