1 PFC_DECLARE_EXCEPTION(exception_unexpected_audio_format_change, exception_io_data,
"Unexpected audio format change" );
9 sample_rate_min = 1000, sample_rate_max = 2822400
16 channel_front_left = 1<<0,
17 channel_front_right = 1<<1,
18 channel_front_center = 1<<2,
20 channel_back_left = 1<<4,
21 channel_back_right = 1<<5,
22 channel_front_center_left = 1<<6,
23 channel_front_center_right = 1<<7,
24 channel_back_center = 1<<8,
25 channel_side_left = 1<<9,
26 channel_side_right = 1<<10,
27 channel_top_center = 1<<11,
28 channel_top_front_left = 1<<12,
29 channel_top_front_center = 1<<13,
30 channel_top_front_right = 1<<14,
31 channel_top_back_left = 1<<15,
32 channel_top_back_center = 1<<16,
33 channel_top_back_right = 1<<17,
35 channel_config_mono = channel_front_center,
36 channel_config_stereo = channel_front_left | channel_front_right,
37 channel_config_5point1 = channel_front_left | channel_front_right | channel_front_center | channel_lfe | channel_back_left | channel_back_right,
38 channel_config_5point1_side = channel_front_left | channel_front_right | channel_front_center | channel_lfe | channel_side_left | channel_side_right,
39 channel_config_7point1 = channel_config_5point1 | channel_side_left | channel_side_right,
41 defined_channel_count = 18,
45 static unsigned g_guess_channel_config(
unsigned count);
47 static unsigned g_guess_channel_config_xiph(
unsigned count);
50 static uint32_t g_channel_config_to_wfx(
unsigned p_config);
52 static unsigned g_channel_config_from_wfx(uint32_t p_wfx);
55 static unsigned g_extract_channel_flag(
unsigned p_config,
unsigned p_index);
57 static unsigned g_count_channels(
unsigned p_config);
59 static unsigned g_channel_index_from_flag(
unsigned p_config,
unsigned p_flag);
61 static const char * g_channel_name(
unsigned p_flag);
62 static const char * g_channel_name_byidx(
unsigned p_index);
63 static unsigned g_find_channel_idx(
unsigned p_flag);
75 virtual t_size get_data_size()
const = 0;
77 virtual void set_data_size(
t_size p_new_size) = 0;
79 void allocate(
size_t size) { set_data_size( size ); }
82 virtual unsigned get_srate()
const = 0;
84 virtual void set_srate(
unsigned val) = 0;
86 virtual unsigned get_channels()
const = 0;
90 virtual unsigned get_channel_config()
const = 0;
92 virtual void set_channels(
unsigned p_count,
unsigned p_config) = 0;
97 virtual t_size get_sample_count()
const = 0;
100 virtual void set_sample_count(
t_size val) = 0;
112 inline void grow_data_size(
t_size p_requested) {
if (p_requested > get_data_size()) set_data_size(p_requested);}
119 t_size srate = get_srate (), samples = get_sample_count();
120 if (srate>0 && samples>0) rv = (double)samples/(
double)srate;
125 inline bool is_empty()
const {
return get_channels()==0 || get_srate()==0 || get_sample_count()==0;}
128 bool is_valid()
const;
131 bool is_spec_valid()
const;
137 #pragma deprecated( get_data_length ) 148 void set_data(
const audio_sample * src,
t_size samples,
unsigned nch,
unsigned srate,
unsigned channel_config);
153 void set_data_int16(
const int16_t * src,
t_size samples,
unsigned nch,
unsigned srate,
unsigned channel_config);
157 this->set_data_fixedpoint_ms(ptr, bytes, srate, nch, bps, channel_config);
160 void set_data_fixedpoint_signed(
const void * ptr,
t_size bytes,
unsigned srate,
unsigned nch,
unsigned bps,
unsigned channel_config);
164 FLAG_LITTLE_ENDIAN = 1,
174 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);
176 void set_data_fixedpoint_ms(
const void * ptr,
size_t bytes,
unsigned sampleRate,
unsigned channels,
unsigned bps,
unsigned channelConfig);
178 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);
180 inline void set_data_32(
const float * src,
t_size samples,
unsigned nch,
unsigned srate) {
return set_data(src,samples,nch,srate);}
182 void pad_with_silence_ex(
t_size samples,
unsigned hint_nch,
unsigned hint_srate);
183 void pad_with_silence(
t_size samples);
184 void insert_silence_fromstart(
t_size samples);
186 void set_silence(
t_size samples);
187 void set_silence_seconds(
double seconds );
189 bool process_skip(
double & skipDuration);
197 bool toFixedPoint(
class mem_block_container & out, uint32_t bps, uint32_t bpsValid,
bool useUpperBits =
true,
float scale = 1.0)
const;
201 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);
228 bool is_valid()
const;
230 static spec_t makeSpec(uint32_t rate, uint32_t channels);
231 static spec_t makeSpec(uint32_t rate, uint32_t channels, uint32_t chanMask);
234 void set_spec(
const spec_t &);
241 template<
typename container_t = pfc::mem_block_aligned_t<audio_sample, 16> >
250 {set_data(src,samples,nch,srate);}
263 virtual void set_channels(
unsigned val,
unsigned setup) {m_nch = val;m_setup = setup;}
270 const t_self &
operator=(
const t_self & p_source) {
copy(p_source);
return *
this;}
280 m_data(p_data), m_samples(p_samples), m_sample_rate(p_sample_rate), m_channels(p_channels), m_channel_config(p_channel_config)
282 PFC_ASSERT(is_valid());
291 void set_srate(
unsigned val) {
throw pfc::exception_not_implemented();}
294 void set_channels(
unsigned p_count,
unsigned p_config) {
throw pfc::exception_not_implemented();}
318 m_sampleCounts.remove_all();
325 void add(
double v) {m_offset += v;}
328 double query()
const;
329 uint64_t queryAsSampleCount( uint32_t rate );
335 PFC_ASSERT( sampleRate > 0 );
336 if (sampleRate > 0 && sampleCount > 0) {
337 m_sampleCounts.find_or_add(sampleRate) += sampleCount;
343 add(walk->m_value, walk->m_key);
349 subtract(walk->m_value, walk->m_key);
353 PFC_ASSERT( sampleRate > 0 );
354 if (sampleRate > 0 && sampleCount > 0) {
355 t_uint64 * val = m_sampleCounts.query_ptr(sampleRate);
356 if (val == NULL)
throw pfc::exception_invalid_params();
357 if (*val < sampleCount)
throw pfc::exception_invalid_params();
358 else if (*val == sampleCount) {
359 m_sampleCounts.remove(sampleRate);
virtual t_size get_data_size() const
Retrieves size of allocated buffer space, in audio_samples.
audio_chunk_memref_impl(const audio_sample *p_data, t_size p_samples, t_uint32 p_sample_rate, t_uint32 p_channels, t_uint32 p_channel_config)
Implementation of audio_chunk. Takes pfc allocator template as template parameter.
duration_counter & operator-=(const t_source &source)
audio_chunk_memref_impl audio_chunk_temp_impl
void set_data_32(const float *src, t_size samples, unsigned nch, unsigned srate)
void SHARED_EXPORT scale(const audio_sample *p_source, t_size p_count, audio_sample *p_output, audio_sample p_scale)
p_source/p_output can point to same buffer
void add(const duration_counter &other)
void reset()
Resets all audio_chunk data.
pfc::map_t< t_uint32, t_uint64 > t_map
void allocate(size_t size)
Sanity helper, same as set_data_size.
unsigned get_sample_rate() const
Helper, same as get_srate().
virtual void set_srate(unsigned val)
Sets sample rate of contained audio data.
void set_sample_count(t_size val)
Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be abo...
const audio_sample * m_data
Interface to container of a chunk of audio data. See audio_chunk_impl for an implementation.
audio_chunk_impl_t audio_chunk_impl
size_t get_data_length() const
Same as get_used_size(); old confusingly named version.
Implements const methods of audio_chunk only, referring to an external buffer. For temporary use only...
audio_chunk_impl_t(const audio_chunk &p_source)
Duration counter class - accumulates duration using sample values, without any kind of rounding error...
virtual unsigned get_channel_config() const
Retrieves channel map of contained audio data. Conditions where number of channels specified by chann...
static const bool byte_order_is_big_endian
virtual unsigned get_channels() const =0
Retrieves channel count of contained audio data.
audio_sample * get_data()
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
unsigned get_srate() const
Retrieves sample rate of contained audio data.
virtual unsigned get_srate() const =0
Retrieves sample rate of contained audio data.
void set_data(const audio_sample *src, t_size samples, unsigned nch, unsigned srate)
Helper, sets chunk data to contents of specified buffer, with specified number of channels / sample r...
void set_channels(unsigned p_count, unsigned p_config)
Sets channel count / channel map.
virtual void set_channels(unsigned val, unsigned setup)
Sets channel count / channel map.
void copy(const audio_chunk &p_source)
Helper; copies content of another audio chunk to this chunk.
bool operator==(const spec_t &other) const
audio_chunk_impl_t< pfc::mem_block_aligned_incremental_t< audio_sample, 16 > > audio_chunk_fast_impl
duration_counter & operator=(const t_source &source)
audio_chunk_impl_t< container_t > t_self
PFC_DECLARE_EXCEPTION(exception_unexpected_audio_format_change, exception_io_data,"Unexpected audio format change")
Thrown when audio_chunk sample rate or channel mapping changes in mid-stream and the code receiving a...
virtual unsigned get_channel_config() const =0
Retrieves channel map of contained audio data. Conditions where number of channels specified by chann...
audio_chunk_fast_impl audio_chunk_impl_temporary
static unsigned flags_autoendian()
t_size get_data_size() const
Retrieves size of allocated buffer space, in audio_samples.
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
void subtract(const duration_counter &other)
virtual t_size get_sample_count() const
Retrieves number of valid samples in the buffer. Note that a "sample" means a unit of interleaved PC...
virtual void set_sample_count(t_size val)
Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be abo...
virtual unsigned get_srate() const
Retrieves sample rate of contained audio data.
void add(const audio_chunk &c)
void add(t_uint64 sampleCount, t_uint32 sampleRate)
audio_chunk_partial_ref(const audio_chunk &chunk, t_size base, t_size count)
void set_data_fixedpoint(const void *ptr, t_size bytes, unsigned srate, unsigned nch, unsigned bps, unsigned channel_config)
Helper, sets chunk data to contents of specified buffer, using default win32/wav conventions for sign...
audio_chunk_impl audio_chunk_i
audio_chunk_impl_t(const t_self &p_source)
audio_chunk_impl_t(const audio_sample *src, unsigned samples, unsigned nch, unsigned srate)
void set_data_size(t_size p_new_size)
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
unsigned get_channels() const
Retrieves channel count of contained audio data.
duration_counter & operator+=(const t_source &source)
void subtract(t_uint64 sampleCount, t_uint32 sampleRate)
void subtract(const audio_chunk &c)
bool operator!=(const spec_t &other) const
virtual void set_data_size(t_size new_size)
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
const t_self & operator=(const t_self &p_source)
virtual audio_sample * get_data()
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
virtual unsigned get_channels() const
Retrieves channel count of contained audio data.
t_size get_sample_count() const
Retrieves number of valid samples in the buffer. Note that a "sample" means a unit of interleaved PC...
Generic interface for a memory block; used by various other interfaces to return memory blocks while ...
bool is_empty() const
Returns whether the chunk is empty (contains no audio data).
static bool g_is_valid_sample_rate(t_uint32 p_val)
void grow_data_size(t_size p_requested)
Helper; resizes audio data buffer when its current size is smaller than requested.
double get_duration() const
Retrieves duration of contained audio data, in seconds.
virtual const audio_sample * get_data() const
Retrieves audio data buffer pointer (const version). Returned pointer is for temporary use only; it i...
void set_srate(unsigned val)
Sets sample rate of contained audio data.
const audio_sample * get_data() const
Retrieves audio data buffer pointer (const version). Returned pointer is for temporary use only; it i...
unsigned get_channel_config() const
Retrieves channel map of contained audio data. Conditions where number of channels specified by chann...
This is free and unencumbered software released into the public domain Anyone is free to copy
const t_self & operator=(const audio_chunk &p_source)
unsigned get_channel_count() const
Helper - for consistency - same as get_channels().
void set_channels(unsigned val)
virtual t_size get_sample_count() const =0
Retrieves number of valid samples in the buffer. Note that a "sample" means a unit of interleaved PC...
void set_channels(unsigned val)
Helper; sets channel count to specified value and uses default channel map for this channel count...
void set_sample_rate(unsigned val)
Helper, same as set_srate().
size_t get_used_size() const
Returns actual amount of audio data contained in the buffer (sample count * channel count)...
const audio_chunk & operator=(const audio_chunk &p_source)
bool equals(const t1 &v1, const t2 &v2)