foobar2000 SDK  2015-01-14
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
audio_chunkabstract

#include <audio_chunk.h>

+ Inheritance diagram for audio_chunk:

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_sampleget_data ()=0
 
virtual const audio_sampleget_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_chunkoperator= (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 ()
 

Detailed Description

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.

Member Enumeration Documentation

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.

Enumerator
channel_front_left 
channel_front_right 
channel_front_center 
channel_lfe 
channel_back_left 
channel_back_right 
channel_front_center_left 
channel_front_center_right 
channel_back_center 
channel_side_left 
channel_side_right 
channel_top_center 
channel_top_front_left 
channel_top_front_center 
channel_top_front_right 
channel_top_back_left 
channel_top_back_center 
channel_top_back_right 
channel_config_mono 
channel_config_stereo 
channel_config_5point1 
channel_config_5point1_side 
channel_config_7point1 
defined_channel_count 

Definition at line 14 of file audio_chunk.h.

15  {
16  channel_front_left = 1<<0,
17  channel_front_right = 1<<1,
18  channel_front_center = 1<<2,
19  channel_lfe = 1<<3,
20  channel_back_left = 1<<4,
21  channel_back_right = 1<<5,
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,
31  channel_top_back_left = 1<<15,
33  channel_top_back_right = 1<<17,
34 
39  channel_config_7point1 = channel_config_5point1 | channel_side_left | channel_side_right,
40 
42  };
anonymous enum
Enumerator
FLAG_LITTLE_ENDIAN 
FLAG_BIG_ENDIAN 
FLAG_SIGNED 
FLAG_UNSIGNED 

Definition at line 162 of file audio_chunk.h.

Constructor & Destructor Documentation

audio_chunk::audio_chunk ( )
inlineprotected

Definition at line 236 of file audio_chunk.h.

236 {}
audio_chunk::~audio_chunk ( )
inlineprotected

Definition at line 237 of file audio_chunk.h.

237 {}

Member Function Documentation

void audio_chunk::allocate ( size_t  size)
inline

Sanity helper, same as set_data_size.

Definition at line 79 of file audio_chunk.h.

79 { set_data_size( size ); }
virtual void set_data_size(t_size p_new_size)=0
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
void audio_chunk::copy ( const audio_chunk p_source)
inline

Helper; copies content of another audio chunk to this chunk.

Definition at line 212 of file audio_chunk.h.

212  {
213  set_data(p_source.get_data(),p_source.get_sample_count(),p_source.get_channels(),p_source.get_srate(),p_source.get_channel_config());
214  }
virtual unsigned get_channels() const =0
Retrieves channel count of contained audio data.
virtual unsigned get_srate() const =0
Retrieves sample rate of contained audio data.
virtual unsigned get_channel_config() const =0
Retrieves channel map of contained audio data. Conditions where number of channels specified by chann...
void 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 r...
Definition: audio_chunk.cpp:3
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
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...
static unsigned audio_chunk::flags_autoendian ( )
inlinestatic

Definition at line 170 of file audio_chunk.h.

unsigned audio_chunk::g_channel_config_from_wfx ( uint32_t  p_wfx)
static

Helper function; translates WAVEFORMATEXTENSIBLE channel map to audio_chunk channel map.

Definition at line 67 of file audio_chunk_channel_config.cpp.

68 {
69  return p_wfx;
70 #if 0
71  unsigned ret = 0;
72  unsigned n;
73  for(n=0;n<PFC_TABSIZE(g_translation_table);n++)
74  {
75  if (p_wfx & g_translation_table[n].m_wfx) ret |= g_translation_table[n].m_native;
76  }
77  return ret;
78 #endif
79 }
static struct @29 g_translation_table[]
uint32_t audio_chunk::g_channel_config_to_wfx ( unsigned  p_config)
static

Helper function; translates audio_chunk channel map to WAVEFORMATEXTENSIBLE channel map.

Definition at line 53 of file audio_chunk_channel_config.cpp.

54 {
55  return p_config;
56 #if 0
57  DWORD ret = 0;
58  unsigned n;
59  for(n=0;n<PFC_TABSIZE(g_translation_table);n++)
60  {
61  if (p_config & g_translation_table[n].m_native) ret |= g_translation_table[n].m_wfx;
62  }
63  return ret;
64 #endif
65 }
static struct @29 g_translation_table[]
unsigned audio_chunk::g_channel_index_from_flag ( unsigned  p_config,
unsigned  p_flag 
)
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.

119  {
120  unsigned index = 0;
121  for(unsigned walk = 0; walk < 32; walk++) {
122  unsigned query = 1 << walk;
123  if (p_flag & query) return index;
124  if (p_config & query) index++;
125  }
126  return ~0;
127 }
const char * audio_chunk::g_channel_name ( unsigned  p_flag)
static

Definition at line 192 of file audio_chunk_channel_config.cpp.

192  {
194 }
static const char * g_channel_name_byidx(unsigned p_index)
static unsigned g_find_channel_idx(unsigned p_flag)
const char * audio_chunk::g_channel_name_byidx ( unsigned  p_index)
static

Definition at line 196 of file audio_chunk_channel_config.cpp.

196  {
197  if (p_index < PFC_TABSIZE(chanNames)) return chanNames[p_index];
198  else return "?";
199 }
static const char *const chanNames[]
unsigned audio_chunk::g_count_channels ( unsigned  p_config)
static

Counts channels specified by channel map.

Definition at line 145 of file audio_chunk_channel_config.cpp.

146 {
147  return pfc::countBits32(p_config);
148 }
unsigned countBits32(uint32_t i)
Definition: primitives.h:850
unsigned audio_chunk::g_extract_channel_flag ( unsigned  p_config,
unsigned  p_index 
)
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.

130 {
131  unsigned toskip = p_index;
132  unsigned flag = 1;
133  while(flag)
134  {
135  if (p_config & flag)
136  {
137  if (toskip == 0) break;
138  toskip--;
139  }
140  flag <<= 1;
141  }
142  return flag;
143 }
unsigned audio_chunk::g_find_channel_idx ( unsigned  p_flag)
static

Definition at line 171 of file audio_chunk_channel_config.cpp.

171  {
172  unsigned rv = 0;
173  if ((p_flag & 0xFFFF) == 0) {
174  rv += 16; p_flag >>= 16;
175  }
176  if ((p_flag & 0xFF) == 0) {
177  rv += 8; p_flag >>= 8;
178  }
179  if ((p_flag & 0xF) == 0) {
180  rv += 4; p_flag >>= 4;
181  }
182  if ((p_flag & 0x3) == 0) {
183  rv += 2; p_flag >>= 2;
184  }
185  if ((p_flag & 0x1) == 0) {
186  rv += 1; p_flag >>= 1;
187  }
188  PFC_ASSERT( p_flag & 1 );
189  return rv;
190 }
void audio_chunk::g_formatChannelMaskDesc ( unsigned  flags,
pfc::string_base out 
)
static

Definition at line 201 of file audio_chunk_channel_config.cpp.

201  {
202  out.reset();
203  unsigned idx = 0;
204  while(flags) {
205  if (flags & 1) {
206  if (!out.is_empty()) out << " ";
207  out << g_channel_name_byidx(idx);
208  }
209  flags >>= 1;
210  ++idx;
211  }
212 }
static const char * g_channel_name_byidx(unsigned p_index)
bool is_empty() const
Definition: string_base.h:212
unsigned audio_chunk::g_guess_channel_config ( unsigned  count)
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.

109 {
110  if (count >= PFC_TABSIZE(g_audio_channel_config_table)) return 0;
111  return g_audio_channel_config_table[count];
112 }
static const unsigned g_audio_channel_config_table[]
unsigned audio_chunk::g_guess_channel_config_xiph ( unsigned  count)
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.

114  {
115  if (count == 0 || count >= PFC_TABSIZE(g_audio_channel_config_table_xiph)) throw exception_io_data();
116  return g_audio_channel_config_table_xiph[count];
117 }
static const unsigned g_audio_channel_config_table_xiph[]
static bool audio_chunk::g_is_valid_sample_rate ( t_uint32  p_val)
inlinestatic

Definition at line 11 of file audio_chunk.h.

bool audio_chunk::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

Convert a buffer of audio_samples to fixed-point PCM format.

Parameters
useUpperBitsrelevant if bps != bpsValid, signals whether upper or lower bits of each sample should be used.

Definition at line 517 of file audio_chunk.cpp.

517  {
518  const sampleToIntDesc d = {bps, bpsValid, useUpperBits, scale};
519  if (bps == 0) {
520  PFC_ASSERT(!"How did we get here?");
521  return false;
522  } else if (bps <= 8) {
523  render_8bit(in, count, out, d);
524  } else if (bps <= 16) {
525  render_16bit(in, count, out, d);
526  } else if (bps <= 24) {
527  render_24bit(in, count, out, d);
528  } else if (bps <= 32) {
529  if (bpsValid <= 28) { // for speed
530  render_32bit_<int32_t>(in, count, out, d);
531  } else {
532  render_32bit_<int64_t>(in, count, out, d);
533  }
534  } else {
535  PFC_ASSERT(!"How did we get here?");
536  return false;
537  }
538 
539  return true;
540 }
static void render_24bit(const audio_sample *in, t_size inLen, void *out, sampleToIntDesc const &d)
static void render_16bit(const audio_sample *in, t_size inLen, void *out, sampleToIntDesc const &d)
void scale(audio_sample p_value)
Helper function; scales entire chunk content by specified value.
static void render_8bit(const audio_sample *in, t_size inLen, void *out, sampleToIntDesc const &d)
virtual unsigned audio_chunk::get_channel_config ( ) const
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 >.

unsigned audio_chunk::get_channel_count ( ) const
inline

Helper - for consistency - same as get_channels().

Definition at line 88 of file audio_chunk.h.

88 {return get_channels();}
virtual unsigned get_channels() const =0
Retrieves channel count of contained audio data.
virtual unsigned audio_chunk::get_channels ( ) const
pure virtual

Retrieves channel count of contained audio data.

Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.

virtual audio_sample* audio_chunk::get_data ( )
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 >.

virtual const audio_sample* audio_chunk::get_data ( ) const
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 >.

size_t audio_chunk::get_data_length ( ) const
inline

Same as get_used_size(); old confusingly named version.

Definition at line 136 of file audio_chunk.h.

136 {return get_sample_count() * get_channels();}
virtual unsigned get_channels() const =0
Retrieves channel count of contained audio data.
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...
virtual t_size audio_chunk::get_data_size ( ) const
pure virtual

Retrieves size of allocated buffer space, in audio_samples.

Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.

double audio_chunk::get_duration ( ) const
inline

Retrieves duration of contained audio data, in seconds.

Definition at line 116 of file audio_chunk.h.

117  {
118  double rv = 0;
119  t_size srate = get_srate (), samples = get_sample_count();
120  if (srate>0 && samples>0) rv = (double)samples/(double)srate;
121  return rv;
122  }
virtual unsigned get_srate() const =0
Retrieves sample rate of contained audio data.
size_t t_size
Definition: int_types.h:48
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...
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.

437  {
438  return pfc::max_t(p_peak, get_peak());
439 }
audio_sample get_peak() const
T max_t(const T &item1, const T &item2)
Definition: primitives.h:553
audio_sample audio_chunk::get_peak ( ) const

Definition at line 441 of file audio_chunk.cpp.

441  {
443 }
virtual unsigned get_channels() const =0
Retrieves channel count of contained audio data.
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
audio_sample SHARED_EXPORT calculate_peak(const audio_sample *p_source, t_size p_count)
Definition: audio_math.cpp:108
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...
virtual t_size audio_chunk::get_sample_count ( ) const
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 >.

unsigned audio_chunk::get_sample_rate ( ) const
inline

Helper, same as get_srate().

Definition at line 103 of file audio_chunk.h.

103 {return get_srate();}
virtual unsigned get_srate() const =0
Retrieves sample rate of contained audio data.
audio_chunk::spec_t audio_chunk::get_spec ( ) const

Definition at line 580 of file audio_chunk.cpp.

580  {
581  spec_t spec = {};
582  spec.sampleRate = this->get_sample_rate();
583  spec.chanCount = this->get_channel_count();
584  spec.chanMask = this->get_channel_config();
585  return spec;
586 }
unsigned get_sample_rate() const
Helper, same as get_srate().
Definition: audio_chunk.h:103
virtual unsigned get_channel_config() const =0
Retrieves channel map of contained audio data. Conditions where number of channels specified by chann...
unsigned get_channel_count() const
Helper - for consistency - same as get_channels().
Definition: audio_chunk.h:88
virtual unsigned audio_chunk::get_srate ( ) const
pure virtual

Retrieves sample rate of contained audio data.

Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.

size_t audio_chunk::get_used_size ( ) const
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.

134 {return get_sample_count() * get_channels();}
virtual unsigned get_channels() const =0
Retrieves channel count of contained audio data.
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 audio_chunk::grow_data_size ( t_size  p_requested)
inline

Helper; resizes audio data buffer when its current size is smaller than requested.

Definition at line 112 of file audio_chunk.h.

112 {if (p_requested > get_data_size()) set_data_size(p_requested);}
virtual t_size get_data_size() const =0
Retrieves size of allocated buffer space, in audio_samples.
virtual void set_data_size(t_size p_new_size)=0
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
void audio_chunk::insert_silence_fromstart ( t_size  samples)

Definition at line 388 of file audio_chunk.cpp.

388  {
389  t_size old_size = get_sample_count() * get_channels();
390  t_size delta = samples * get_channels();
391  t_size new_size = old_size + delta;
392  set_data_size(new_size);
393  audio_sample * ptr = get_data();
394  pfc::memmove_t(ptr+delta,ptr,old_size);
395  pfc::memset_t(ptr,(audio_sample)0,delta);
396  set_sample_count(get_sample_count() + samples);
397 }
virtual unsigned get_channels() const =0
Retrieves channel count of contained audio data.
size_t t_size
Definition: int_types.h:48
void memmove_t(T *p_dst, const T *p_src, t_size p_count)
Definition: primitives.h:649
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
float audio_sample
Definition: audio_sample.h:6
virtual void set_data_size(t_size p_new_size)=0
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
void memset_t(T *p_buffer, const t_val &p_val, t_size p_count)
Definition: primitives.h:627
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...
virtual void set_sample_count(t_size val)=0
Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be abo...
bool audio_chunk::is_empty ( ) const
inline

Returns whether the chunk is empty (contains no audio data).

Definition at line 125 of file audio_chunk.h.

125 {return get_channels()==0 || get_srate()==0 || get_sample_count()==0;}
virtual unsigned get_channels() const =0
Retrieves channel count of contained audio data.
virtual unsigned get_srate() const =0
Retrieves sample rate of contained audio data.
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...
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.

341  {
342  return this->get_spec().is_valid();
343 }
spec_t get_spec() const
bool is_valid() const
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.

329 {
330  unsigned nch = get_channels();
331  if (nch==0 || nch>256) return false;
332  if (!g_is_valid_sample_rate(get_srate())) return false;
333  t_size samples = get_sample_count();
334  if (samples==0 || samples >= 0x80000000 / (sizeof(audio_sample) * nch) ) return false;
335  t_size size = get_data_size();
336  if (samples * nch > size) return false;
337  if (!get_data()) return false;
338  return true;
339 }
virtual unsigned get_channels() const =0
Retrieves channel count of contained audio data.
virtual unsigned get_srate() const =0
Retrieves sample rate of contained audio data.
size_t t_size
Definition: int_types.h:48
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
float audio_sample
Definition: audio_sample.h:6
virtual t_size get_data_size() const =0
Retrieves size of allocated buffer space, in audio_samples.
static bool g_is_valid_sample_rate(t_uint32 p_val)
Definition: audio_chunk.h:11
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...
audio_chunk::spec_t audio_chunk::makeSpec ( uint32_t  rate,
uint32_t  channels 
)
static

Definition at line 566 of file audio_chunk.cpp.

566  {
567  return makeSpec( rate, channels, g_guess_channel_config(channels) );
568 }
static spec_t makeSpec(uint32_t rate, uint32_t channels)
static unsigned g_guess_channel_config(unsigned count)
Helper function; guesses default channel map for the specified channel count. Returns 0 on failure...
audio_chunk::spec_t audio_chunk::makeSpec ( uint32_t  rate,
uint32_t  channels,
uint32_t  chanMask 
)
static

Definition at line 570 of file audio_chunk.cpp.

570  {
571  spec_t spec = {};
572  spec.sampleRate = rate; spec.chanCount = channels; spec.chanMask = mask;
573  return spec;
574 }
const audio_chunk& audio_chunk::operator= ( const audio_chunk p_source)
inline

Definition at line 216 of file audio_chunk.h.

216  {
217  copy(p_source);
218  return *this;
219  }
void copy(const audio_chunk &p_source)
Helper; copies content of another audio chunk to this chunk.
Definition: audio_chunk.h:212
void audio_chunk::pad_with_silence ( t_size  samples)

Definition at line 366 of file audio_chunk.cpp.

366  {
367  if (samples > get_sample_count())
368  {
369  t_size old_size = get_sample_count() * get_channels();
370  t_size new_size = pfc::multiply_guarded(samples,(size_t)get_channels());
371  set_data_size(new_size);
372  pfc::memset_t(get_data() + old_size,(audio_sample)0,new_size - old_size);
373  set_sample_count(samples);
374  }
375 }
t_int multiply_guarded(t_int v1, t_int v2)
Definition: primitives.h:593
virtual unsigned get_channels() const =0
Retrieves channel count of contained audio data.
size_t t_size
Definition: int_types.h:48
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
float audio_sample
Definition: audio_sample.h:6
virtual void set_data_size(t_size p_new_size)=0
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
void memset_t(T *p_buffer, const t_val &p_val, t_size p_count)
Definition: primitives.h:627
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...
virtual void set_sample_count(t_size val)=0
Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be abo...
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.

345  {
346  if (is_empty())
347  {
348  if (hint_srate && hint_nch) {
349  return set_data(0,samples,hint_nch,hint_srate);
350  } else throw exception_io_data();
351  }
352  else
353  {
354  if (hint_srate && hint_srate != get_srate()) samples = MulDiv_Size(samples,get_srate(),hint_srate);
355  if (samples > get_sample_count())
356  {
357  t_size old_size = get_sample_count() * get_channels();
358  t_size new_size = samples * get_channels();
359  set_data_size(new_size);
360  pfc::memset_t(get_data() + old_size,(audio_sample)0,new_size - old_size);
361  set_sample_count(samples);
362  }
363  }
364 }
t_size MulDiv_Size(t_size x, t_size y, t_size z)
Definition: int_types.h:52
virtual unsigned get_channels() const =0
Retrieves channel count 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, unsigned channel_config)
Helper, sets chunk data to contents of specified buffer, with specified number of channels / sample r...
Definition: audio_chunk.cpp:3
size_t t_size
Definition: int_types.h:48
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
float audio_sample
Definition: audio_sample.h:6
virtual void set_data_size(t_size p_new_size)=0
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
bool is_empty() const
Returns whether the chunk is empty (contains no audio data).
Definition: audio_chunk.h:125
void memset_t(T *p_buffer, const t_val &p_val, t_size p_count)
Definition: primitives.h:627
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...
virtual void set_sample_count(t_size val)=0
Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be abo...
bool audio_chunk::process_skip ( double &  skipDuration)

Definition at line 399 of file audio_chunk.cpp.

399  {
400  t_uint64 skipSamples = audio_math::time_to_samples(skipDuration, get_sample_rate());
401  if (skipSamples == 0) {skipDuration = 0; return true;}
402  const t_size mySamples = get_sample_count();
403  if (skipSamples < mySamples) {
404  skip_first_samples((t_size)skipSamples);
405  skipDuration = 0;
406  return true;
407  }
408  if (skipSamples == mySamples) {
409  skipDuration = 0;
410  return false;
411  }
412  skipDuration -= audio_math::samples_to_time(mySamples, get_sample_rate());
413  return false;
414 }
uint64_t t_uint64
Definition: int_types.h:3
unsigned get_sample_rate() const
Helper, same as get_srate().
Definition: audio_chunk.h:103
double samples_to_time(t_uint64 p_samples, t_uint32 p_sample_rate)
Definition: audio_sample.h:37
size_t t_size
Definition: int_types.h:48
t_size skip_first_samples(t_size samples)
t_uint64 time_to_samples(double p_time, t_uint32 p_sample_rate)
Definition: audio_sample.h:33
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 audio_chunk::reset ( )
inline

Resets all audio_chunk data.

Definition at line 140 of file audio_chunk.h.

140  {
141  set_sample_count(0);
142  set_srate(0);
143  set_channels(0);
144  set_data_size(0);
145  }
virtual void set_srate(unsigned val)=0
Sets sample rate of contained audio data.
virtual void set_channels(unsigned p_count, unsigned p_config)=0
Sets channel count / channel map.
virtual void set_data_size(t_size p_new_size)=0
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
virtual void set_sample_count(t_size val)=0
Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be abo...
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.

446 {
447  audio_sample * ptr = get_data();
448  audio_math::scale(ptr,get_sample_count() * get_channels(),ptr,p_value);
449 }
virtual unsigned get_channels() const =0
Retrieves channel count of contained audio data.
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
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
Definition: audio_math.cpp:63
float audio_sample
Definition: audio_sample.h:6
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...
virtual void audio_chunk::set_channels ( unsigned  p_count,
unsigned  p_config 
)
pure virtual

Sets channel count / channel map.

Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.

void audio_chunk::set_channels ( unsigned  val)
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.

static unsigned g_guess_channel_config(unsigned count)
Helper function; guesses default channel map for the specified channel count. Returns 0 on failure...
virtual void set_channels(unsigned p_count, unsigned p_config)=0
Sets channel count / channel map.
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.

4 {
5  t_size size = samples * nch;
6  set_data_size(size);
7  if (src)
8  pfc::memcpy_t(get_data(),src,size);
9  else
11  set_sample_count(samples);
12  set_channels(nch,channel_config);
13  set_srate(srate);
14 }
virtual void set_srate(unsigned val)=0
Sets sample rate of contained audio data.
size_t t_size
Definition: int_types.h:48
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
float audio_sample
Definition: audio_sample.h:6
virtual void set_channels(unsigned p_count, unsigned p_config)=0
Sets channel count / channel map.
virtual void set_data_size(t_size p_new_size)=0
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
void memcpy_t(t_dst *p_dst, const t_src *p_src, t_size p_count)
Definition: primitives.h:611
void memset_t(T *p_buffer, const t_val &p_val, t_size p_count)
Definition: primitives.h:627
virtual void set_sample_count(t_size val)=0
Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be abo...
void audio_chunk::set_data ( const audio_sample src,
t_size  samples,
unsigned  nch,
unsigned  srate 
)
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.

151 {set_data(src,samples,nch,srate,g_guess_channel_config(nch));}
void 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 r...
Definition: audio_chunk.cpp:3
static unsigned g_guess_channel_config(unsigned count)
Helper function; guesses default channel map for the specified channel count. Returns 0 on failure...
void audio_chunk::set_data_32 ( const float *  src,
t_size  samples,
unsigned  nch,
unsigned  srate 
)
inline

Definition at line 180 of file audio_chunk.h.

180 {return set_data(src,samples,nch,srate);}
void 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 r...
Definition: audio_chunk.cpp:3
void audio_chunk::set_data_fixedpoint ( const void *  ptr,
t_size  bytes,
unsigned  srate,
unsigned  nch,
unsigned  bps,
unsigned  channel_config 
)
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.

156  {
157  this->set_data_fixedpoint_ms(ptr, bytes, srate, nch, bps, channel_config);
158  }
void set_data_fixedpoint_ms(const void *ptr, size_t bytes, unsigned sampleRate, unsigned channels, unsigned bps, unsigned channelConfig)
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.

124 {
125  PFC_ASSERT( check_exclusive(flags,FLAG_SIGNED|FLAG_UNSIGNED) );
127 
128  bool byteSwap = !!(flags & FLAG_BIG_ENDIAN);
129  if (pfc::byte_order_is_big_endian) byteSwap = !byteSwap;
130 
131  t_size count = size / (bps/8);
132  set_data_size(count);
133  audio_sample * buffer = get_data();
134  bool isSigned = !!(flags & FLAG_SIGNED);
135 
136  switch(bps)
137  {
138  case 8:
139  // byte order irrelevant
140  if (isSigned) _import8s( (const uint8_t*) source , buffer, count);
141  else _import8u( (const uint8_t*) source , buffer, count);
142  break;
143  case 16:
144  if (byteSwap) {
145  if (isSigned) {
146  _import16any<true, true>( source, buffer, count );
147  } else {
148  _import16any<true, false>( source, buffer, count );
149  }
150  } else {
151  if (isSigned) {
152  //_import16any<false, true>( source, buffer, count );
153  audio_math::convert_from_int16((const int16_t*)source,count,buffer,1.0);
154  } else {
155  _import16any<false, false>( source, buffer, count);
156  }
157  }
158  break;
159  case 24:
160  if (byteSwap) {
161  if (isSigned) {
162  _import24any<true, true>( source, buffer, count );
163  } else {
164  _import24any<true, false>( source, buffer, count );
165  }
166  } else {
167  if (isSigned) {
168  //_import24any<false, true>( source, buffer, count);
169  _import24( source, buffer, count);
170  } else {
171  _import24any<false, false>( source, buffer, count);
172  }
173  }
174  break;
175  case 32:
176  if (byteSwap) {
177  if (isSigned) {
178  _import32any<true, true>( source, buffer, count );
179  } else {
180  _import32any<true, false>( source, buffer, count );
181  }
182  } else {
183  if (isSigned) {
184  audio_math::convert_from_int32((const int32_t*)source,count,buffer,1.0);
185  } else {
186  _import32any<false, false>( source, buffer, count);
187  }
188  }
189  break;
190  default:
191  //unknown size, cant convert
192  pfc::memset_t(buffer,(audio_sample)0,count);
193  break;
194  }
195  set_sample_count(count/nch);
196  set_srate(srate);
197  set_channels(nch,p_channel_config);
198 }
static void _import24(const void *in_, audio_sample *out, size_t count)
Definition: audio_chunk.cpp:42
virtual void set_srate(unsigned val)=0
Sets sample rate of contained audio data.
static const bool byte_order_is_big_endian
size_t t_size
Definition: int_types.h:48
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
float audio_sample
Definition: audio_sample.h:6
virtual void set_channels(unsigned p_count, unsigned p_config)=0
Sets channel count / channel map.
virtual void set_data_size(t_size p_new_size)=0
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
void SHARED_EXPORT convert_from_int32(const t_int32 *p_source, t_size p_count, audio_sample *p_output, audio_sample p_scale)
Definition: audio_math.cpp:101
static void _import8s(uint8_t const *in, audio_sample *out, size_t count)
Definition: audio_chunk.cpp:29
bool check_exclusive(unsigned val, unsigned mask)
Definition: audio_chunk.cpp:16
void SHARED_EXPORT convert_from_int16(const t_int16 *p_source, t_size p_count, audio_sample *p_output, audio_sample p_scale)
Definition: audio_math.cpp:81
void memset_t(T *p_buffer, const t_val &p_val, t_size p_count)
Definition: primitives.h:627
virtual void set_sample_count(t_size val)=0
Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be abo...
static void _import8u(uint8_t const *in, audio_sample *out, size_t count)
Definition: audio_chunk.cpp:21
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.

200  {
201  //set_data_fixedpoint_ex(ptr,bytes,sampleRate,channels,bps,(bps==8 ? FLAG_UNSIGNED : FLAG_SIGNED) | flags_autoendian(), channelConfig);
202  PFC_ASSERT( bps != 0 );
203  size_t count = bytes / (bps/8);
204  this->set_data_size( count );
205  audio_sample * buffer = this->get_data();
206  switch(bps) {
207  case 8:
208  _import8u((const uint8_t*)ptr, buffer, count);
209  break;
210  case 16:
211  audio_math::convert_from_int16((const int16_t*) ptr, count, buffer, 1.0);
212  break;
213  case 24:
214  _import24( ptr, buffer, count);
215  break;
216  case 32:
217  audio_math::convert_from_int32((const int32_t*) ptr, count, buffer, 1.0);
218  break;
219  default:
220  PFC_ASSERT(!"Unknown bit depth!");
221  memset(buffer, 0, sizeof(audio_sample) * count);
222  break;
223  }
224  set_sample_count(count/channels);
225  set_srate(sampleRate);
226  set_channels(channels,channelConfig);
227 }
static void _import24(const void *in_, audio_sample *out, size_t count)
Definition: audio_chunk.cpp:42
virtual void set_srate(unsigned val)=0
Sets sample rate of contained audio data.
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
float audio_sample
Definition: audio_sample.h:6
virtual void set_channels(unsigned p_count, unsigned p_config)=0
Sets channel count / channel map.
virtual void set_data_size(t_size p_new_size)=0
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
void SHARED_EXPORT convert_from_int32(const t_int32 *p_source, t_size p_count, audio_sample *p_output, audio_sample p_scale)
Definition: audio_math.cpp:101
void SHARED_EXPORT convert_from_int16(const t_int16 *p_source, t_size p_count, audio_sample *p_output, audio_sample p_scale)
Definition: audio_math.cpp:81
virtual void set_sample_count(t_size val)=0
Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be abo...
static void _import8u(uint8_t const *in, audio_sample *out, size_t count)
Definition: audio_chunk.cpp:21
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.

229  {
230  PFC_ASSERT( bps != 0 );
231  size_t count = bytes / (bps/8);
232  this->set_data_size( count );
233  audio_sample * buffer = this->get_data();
234  switch(bps) {
235  case 8:
236  _import8s((const uint8_t*)ptr, buffer, count);
237  break;
238  case 16:
239  audio_math::convert_from_int16((const int16_t*) ptr, count, buffer, 1.0);
240  break;
241  case 24:
242  _import24( ptr, buffer, count);
243  break;
244  case 32:
245  audio_math::convert_from_int32((const int32_t*) ptr, count, buffer, 1.0);
246  break;
247  default:
248  PFC_ASSERT(!"Unknown bit depth!");
249  memset(buffer, 0, sizeof(audio_sample) * count);
250  break;
251  }
252  set_sample_count(count/channels);
253  set_srate(sampleRate);
254  set_channels(channels,channelConfig);
255 }
static void _import24(const void *in_, audio_sample *out, size_t count)
Definition: audio_chunk.cpp:42
virtual void set_srate(unsigned val)=0
Sets sample rate of contained audio data.
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
float audio_sample
Definition: audio_sample.h:6
virtual void set_channels(unsigned p_count, unsigned p_config)=0
Sets channel count / channel map.
virtual void set_data_size(t_size p_new_size)=0
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
void SHARED_EXPORT convert_from_int32(const t_int32 *p_source, t_size p_count, audio_sample *p_output, audio_sample p_scale)
Definition: audio_math.cpp:101
static void _import8s(uint8_t const *in, audio_sample *out, size_t count)
Definition: audio_chunk.cpp:29
void SHARED_EXPORT convert_from_int16(const t_int16 *p_source, t_size p_count, audio_sample *p_output, audio_sample p_scale)
Definition: audio_math.cpp:81
virtual void set_sample_count(t_size val)=0
Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be abo...
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.

283 {
284  PFC_ASSERT(bps==32 || bps==64 || bps == 16 || bps == 24);
286  PFC_ASSERT( ! (flags & (FLAG_SIGNED|FLAG_UNSIGNED) ) );
287 
288  bool use_swap = pfc::byte_order_is_big_endian ? !!(flags & FLAG_LITTLE_ENDIAN) : !!(flags & FLAG_BIG_ENDIAN);
289 
290  const t_size count = size / (bps/8);
291  set_data_size(count);
292  audio_sample * out = get_data();
293 
294  if (bps == 32)
295  {
296  if (use_swap)
297  process_float_multi_swap(out,reinterpret_cast<const float*>(ptr),count);
298  else
299  process_float_multi(out,reinterpret_cast<const float*>(ptr),count);
300  }
301  else if (bps == 64)
302  {
303  if (use_swap)
304  process_float_multi_swap(out,reinterpret_cast<const double*>(ptr),count);
305  else
306  process_float_multi(out,reinterpret_cast<const double*>(ptr),count);
307  } else if (bps == 16) {
308  const uint16_t * in = reinterpret_cast<const uint16_t*>(ptr);
309  if (use_swap) {
310  for(size_t walk = 0; walk < count; ++walk) out[walk] = audio_math::decodeFloat16(pfc::byteswap_t(in[walk]));
311  } else {
312  for(size_t walk = 0; walk < count; ++walk) out[walk] = audio_math::decodeFloat16(in[walk]);
313  }
314  } else if (bps == 24) {
315  const uint8_t * in = reinterpret_cast<const uint8_t*>(ptr);
316  if (use_swap) {
317  for(size_t walk = 0; walk < count; ++walk) out[walk] = audio_math::decodeFloat24ptrbs(&in[walk*3]);
318  } else {
319  for(size_t walk = 0; walk < count; ++walk) out[walk] = audio_math::decodeFloat24ptr(&in[walk*3]);
320  }
321  } else pfc::throw_exception_with_message< exception_io_data >("invalid bit depth");
322 
323  set_sample_count(count/nch);
324  set_srate(srate);
325  set_channels(nch,p_channel_config);
326 }
audio_sample decodeFloat24ptrbs(const void *sourcePtr)
virtual void set_srate(unsigned val)=0
Sets sample rate of contained audio data.
T byteswap_t(T p_source)
static const bool byte_order_is_big_endian
audio_sample decodeFloat16(uint16_t source)
size_t t_size
Definition: int_types.h:48
audio_sample decodeFloat24ptr(const void *sourcePtr)
Definition: audio_sample.cpp:4
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
float audio_sample
Definition: audio_sample.h:6
static void process_float_multi_swap(audio_sample *p_out, const t_float *p_in, const t_size p_count)
static void process_float_multi(audio_sample *p_out, const t_float *p_in, const t_size p_count)
virtual void set_channels(unsigned p_count, unsigned p_config)=0
Sets channel count / channel map.
virtual void set_data_size(t_size p_new_size)=0
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
bool check_exclusive(unsigned val, unsigned mask)
Definition: audio_chunk.cpp:16
virtual void set_sample_count(t_size val)=0
Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be abo...
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.

257  {
258  const size_t count = samples * nch;
259  this->set_data_size( count );
260  audio_sample * buffer = this->get_data();
261  audio_math::convert_from_int16(src, count, buffer, 1.0);
262  set_sample_count(samples);
263  set_srate(srate);
264  set_channels(nch,channel_config);
265 }
virtual void set_srate(unsigned val)=0
Sets sample rate of contained audio data.
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
float audio_sample
Definition: audio_sample.h:6
virtual void set_channels(unsigned p_count, unsigned p_config)=0
Sets channel count / channel map.
virtual void set_data_size(t_size p_new_size)=0
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
void SHARED_EXPORT convert_from_int16(const t_int16 *p_source, t_size p_count, audio_sample *p_output, audio_sample p_scale)
Definition: audio_math.cpp:81
virtual void set_sample_count(t_size val)=0
Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be abo...
virtual void audio_chunk::set_data_size ( t_size  p_new_size)
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 >.

virtual void audio_chunk::set_sample_count ( t_size  val)
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 >.

void audio_chunk::set_sample_rate ( unsigned  val)
inline

Helper, same as set_srate().

Definition at line 105 of file audio_chunk.h.

105 {set_srate(val);}
virtual void set_srate(unsigned val)=0
Sets sample rate of contained audio data.
void audio_chunk::set_silence ( t_size  samples)

Definition at line 377 of file audio_chunk.cpp.

377  {
378  t_size items = samples * get_channels();
379  set_data_size(items);
380  pfc::memset_null_t(get_data(), items);
381  set_sample_count(samples);
382 }
virtual unsigned get_channels() const =0
Retrieves channel count of contained audio data.
size_t t_size
Definition: int_types.h:48
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
void memset_null_t(T *p_buffer, t_size p_count)
Definition: primitives.h:638
virtual void set_data_size(t_size p_new_size)=0
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
virtual void set_sample_count(t_size val)=0
Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be abo...
void audio_chunk::set_silence_seconds ( double  seconds)

Definition at line 384 of file audio_chunk.cpp.

384  {
385  set_silence( (size_t) audio_math::time_to_samples( seconds, this->get_sample_rate() ) );
386 }
unsigned get_sample_rate() const
Helper, same as get_srate().
Definition: audio_chunk.h:103
t_uint64 time_to_samples(double p_time, t_uint32 p_sample_rate)
Definition: audio_sample.h:33
void set_silence(t_size samples)
void audio_chunk::set_spec ( const spec_t spec)

Definition at line 587 of file audio_chunk.cpp.

587  {
588  set_sample_rate(spec.sampleRate);
589  set_channels( spec.chanCount, spec.chanMask );
590 }
virtual void set_channels(unsigned p_count, unsigned p_config)=0
Sets channel count / channel map.
void set_sample_rate(unsigned val)
Helper, same as set_srate().
Definition: audio_chunk.h:105
virtual void audio_chunk::set_srate ( unsigned  val)
pure virtual

Sets sample rate of contained audio data.

Implemented in audio_chunk_memref_impl, and audio_chunk_impl_t< container_t >.

t_size audio_chunk::skip_first_samples ( t_size  samples)

Definition at line 416 of file audio_chunk.cpp.

417 {
418  t_size samples_old = get_sample_count();
419  if (samples_delta >= samples_old)
420  {
421  set_sample_count(0);
422  set_data_size(0);
423  return samples_old;
424  }
425  else
426  {
427  t_size samples_new = samples_old - samples_delta;
428  unsigned nch = get_channels();
429  audio_sample * ptr = get_data();
430  pfc::memmove_t(ptr,ptr+nch*samples_delta,nch*samples_new);
431  set_sample_count(samples_new);
432  set_data_size(nch*samples_new);
433  return samples_delta;
434  }
435 }
virtual unsigned get_channels() const =0
Retrieves channel count of contained audio data.
size_t t_size
Definition: int_types.h:48
void memmove_t(T *p_dst, const T *p_src, t_size p_count)
Definition: primitives.h:649
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
float audio_sample
Definition: audio_sample.h:6
virtual void set_data_size(t_size p_new_size)=0
Resizes audio data buffer to specified size. Throws std::bad_alloc on failure.
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...
virtual void set_sample_count(t_size val)=0
Sets number of valid samples in the buffer. WARNING: sample count * channel count should never be abo...
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.

Returns
false when the conversion could not be performed because of unsupported bit depth etc.

Definition at line 550 of file audio_chunk.cpp.

550  {
551  uint32_t bpsValid = bps;
552  bps = (bps + 7) & ~7;
553  const size_t count = get_sample_count() * get_channel_count();
554  out.set_size( count * (bps/8) );
555  void * outPtr = out.get_ptr();
556  audio_sample const * inPtr = get_data();
557  if (bps == 32) {
558  float * f = (float*) outPtr;
559  for(size_t w = 0; w < count; ++w) f[w] = inPtr[w] * scale;
560  return true;
561  } else {
562  return g_toFixedPoint(inPtr, outPtr, count, bps, bpsValid, useUpperBits, scale);
563  }
564 }
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)
Convert a buffer of audio_samples to fixed-point PCM format.
void scale(audio_sample p_value)
Helper function; scales entire chunk content by specified value.
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
float audio_sample
Definition: audio_sample.h:6
unsigned get_channel_count() const
Helper - for consistency - same as get_channels().
Definition: audio_chunk.h:88
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...
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.

Parameters
useUpperBitsrelevant if bps != bpsValid, signals whether upper or lower bits of each sample should be used.

Definition at line 542 of file audio_chunk.cpp.

542  {
543  bps = (bps + 7) & ~7;
544  if (bps < bpsValid) return false;
545  const size_t count = get_sample_count() * get_channel_count();
546  out.set_size( count * (bps/8) );
547  return g_toFixedPoint(get_data(), out.get_ptr(), count, bps, bpsValid, useUpperBits, scale);
548 }
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)
Convert a buffer of audio_samples to fixed-point PCM format.
void scale(audio_sample p_value)
Helper function; scales entire chunk content by specified value.
virtual audio_sample * get_data()=0
Retrieves audio data buffer pointer (non-const version). Returned pointer is for temporary use only; ...
unsigned get_channel_count() const
Helper - for consistency - same as get_channels().
Definition: audio_chunk.h:88
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...

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