foobar2000 SDK  2015-08-03
Functions
audio_chunk.cpp File Reference

Go to the source code of this file.

Functions

template<bool byteSwap, bool isSigned>
static void _import16any (const void *in, audio_sample *out, size_t count)
 
static void _import24 (const void *in_, audio_sample *out, size_t count)
 
template<bool byteSwap, bool isSigned>
static void _import24any (const void *in, audio_sample *out, size_t count)
 
static audio_sample _import24s (uint32_t i)
 
template<bool byteSwap, bool isSigned>
static void _import32any (const void *in, audio_sample *out, size_t count)
 
static void _import8s (uint8_t const *in, audio_sample *out, size_t count)
 
static void _import8u (uint8_t const *in, audio_sample *out, size_t count)
 
bool check_exclusive (unsigned val, unsigned mask)
 
template<class t_float >
static void process_float_multi (audio_sample *p_out, const t_float *p_in, const t_size p_count)
 
template<class t_float >
static void process_float_multi_swap (audio_sample *p_out, const t_float *p_in, const t_size p_count)
 
static void render_16bit (const audio_sample *in, t_size inLen, void *out, sampleToIntDesc const &d)
 
static void render_24bit (const audio_sample *in, t_size inLen, void *out, sampleToIntDesc const &d)
 
template<typename internal_t >
static void render_32bit_ (const audio_sample *in, t_size inLen, void *out, sampleToIntDesc const &d)
 
static void render_8bit (const audio_sample *in, t_size inLen, void *out, sampleToIntDesc const &d)
 

Function Documentation

template<bool byteSwap, bool isSigned>
static void _import16any ( const void *  in,
audio_sample out,
size_t  count 
)
static

Definition at line 87 of file audio_chunk.cpp.

87  {
88  uint16_t const * inPtr = (uint16_t const*) in;
89  const audio_sample factor = 1.0f / (audio_sample) 0x8000;
90  for(size_t walk = 0; walk < count; ++walk) {
91  uint16_t v = *inPtr++;
92  if (byteSwap) v = pfc::byteswap_t(v);
93  if (!isSigned) v ^= 0x8000; // to signed
94  *out++ = (audio_sample) (int16_t) v * factor;
95  }
96 }
T byteswap_t(T p_source)
float audio_sample
Definition: audio_sample.h:6
static void _import24 ( const void *  in_,
audio_sample out,
size_t  count 
)
static

Definition at line 42 of file audio_chunk.cpp.

42  {
43  const uint8_t * in = (const uint8_t*) in_;
44 #if 1
45  while(count > 0 && !pfc::is_ptr_aligned_t<4>(in)) {
46  uint32_t i = *(in++);
47  i |= (uint32_t) *(in++) << 8;
48  i |= (uint32_t) *(in++) << 16;
49  *(out++) = _import24s(i);
50  --count;
51  }
52  {
53  for(size_t loop = count >> 2; loop; --loop) {
54  uint32_t i1 = * (uint32_t*) in; in += 4;
55  uint32_t i2 = * (uint32_t*) in; in += 4;
56  uint32_t i3 = * (uint32_t*) in; in += 4;
57  *out++ = _import24s( i1 & 0xFFFFFF );
58  *out++ = _import24s( (i1 >> 24) | ((i2 & 0xFFFF) << 8) );
59  *out++ = _import24s( (i2 >> 16) | ((i3 & 0xFF) << 16) );
60  *out++ = _import24s( i3 >> 8 );
61  }
62  count &= 3;
63  }
64  for( ; count ; --count) {
65  uint32_t i = *(in++);
66  i |= (uint32_t) *(in++) << 8;
67  i |= (uint32_t) *(in++) << 16;
68  *(out++) = _import24s(i);
69  }
70 #else
71  if (count > 0) {
72  int32_t i = *(in++);
73  i |= (int32_t) *(in++) << 8;
74  i |= (int32_t) (int8_t) *in << 16;
75  *out++ = (audio_sample) i / (audio_sample) 0x800000;
76  --count;
77 
78  // Now we have in ptr at offset_of_next - 1 and we can read as int32 then discard the LSBs
79  for(;count;--count) {
80  int32_t i = *( int32_t*) in; in += 3;
81  *out++ = (audio_sample) (i >> 8) / (audio_sample) 0x800000;
82  }
83  }
84 #endif
85 }
float audio_sample
Definition: audio_sample.h:6
static audio_sample _import24s(uint32_t i)
Definition: audio_chunk.cpp:36
template<bool byteSwap, bool isSigned>
static void _import24any ( const void *  in,
audio_sample out,
size_t  count 
)
static

Definition at line 109 of file audio_chunk.cpp.

109  {
110  uint8_t const * inPtr = (uint8_t const*) in;
111  const audio_sample factor = 1.0f / (audio_sample) 0x800000;
112  for(size_t walk = 0; walk < count; ++walk) {
113  uint32_t v;
114  if (byteSwap) v = (uint32_t) inPtr[2] | ( (uint32_t) inPtr[1] << 8 ) | ( (uint32_t) inPtr[0] << 16 );
115  else v = (uint32_t) inPtr[0] | ( (uint32_t) inPtr[1] << 8 ) | ( (uint32_t) inPtr[2] << 16 );
116  inPtr += 3;
117  if (isSigned) v ^= 0x800000; // to unsigned
118  v -= 0x800000; // then subtract to get proper MSBs
119  *out++ = (audio_sample) (int32_t) v * factor;
120  }
121 }
float audio_sample
Definition: audio_sample.h:6
static audio_sample _import24s ( uint32_t  i)
static

Definition at line 36 of file audio_chunk.cpp.

36  {
37  i ^= 0x800000; // to unsigned
38  i -= 0x800000; // and back to signed / fill MSBs proper
39  return (float) (int32_t) i / (float) 0x800000;
40 }
template<bool byteSwap, bool isSigned>
static void _import32any ( const void *  in,
audio_sample out,
size_t  count 
)
static

Definition at line 98 of file audio_chunk.cpp.

98  {
99  uint32_t const * inPtr = (uint32_t const*) in;
100  const audio_sample factor = 1.0f / (audio_sample) 0x80000000;
101  for(size_t walk = 0; walk < count; ++walk) {
102  uint32_t v = *inPtr++;
103  if (byteSwap) v = pfc::byteswap_t(v);
104  if (!isSigned) v ^= 0x80000000; // to signed
105  *out++ = (audio_sample) (int32_t) v * factor;
106  }
107 }
T byteswap_t(T p_source)
float audio_sample
Definition: audio_sample.h:6
static void _import8s ( uint8_t const *  in,
audio_sample out,
size_t  count 
)
static

Definition at line 29 of file audio_chunk.cpp.

29  {
30  for(size_t walk = 0; walk < count; ++walk) {
31  int32_t i = (int8_t) *(in++);
32  *(out++) = (float) i / (float) 0x80;
33  }
34 }
static void _import8u ( uint8_t const *  in,
audio_sample out,
size_t  count 
)
static

Definition at line 21 of file audio_chunk.cpp.

21  {
22  for(size_t walk = 0; walk < count; ++walk) {
23  uint32_t i = *(in++);
24  i -= 0x80; // to signed
25  *(out++) = (float) (int32_t) i / (float) 0x80;
26  }
27 }
bool check_exclusive ( unsigned  val,
unsigned  mask 
)
inline

Definition at line 16 of file audio_chunk.cpp.

17 {
18  return (val&mask)!=0 && (val&mask)!=mask;
19 }
template<class t_float >
static void process_float_multi ( audio_sample p_out,
const t_float *  p_in,
const t_size  p_count 
)
static

Definition at line 268 of file audio_chunk.cpp.

269 {
270  for(size_t n=0;n<p_count;n++) p_out[n] = (audio_sample)p_in[n];
271 }
float audio_sample
Definition: audio_sample.h:6
template<class t_float >
static void process_float_multi_swap ( audio_sample p_out,
const t_float *  p_in,
const t_size  p_count 
)
static

Definition at line 274 of file audio_chunk.cpp.

275 {
276  for(size_t n=0;n<p_count;n++) {
277  p_out[n] = (audio_sample) pfc::byteswap_t(p_in[n]);
278  }
279 }
T byteswap_t(T p_source)
float audio_sample
Definition: audio_sample.h:6
static void render_16bit ( const audio_sample in,
t_size  inLen,
void *  out,
sampleToIntDesc const &  d 
)
static

Definition at line 500 of file audio_chunk.cpp.

500  {
501  sampleToInt<int32_t> gen(d);
502  int16_t * outWalk = reinterpret_cast<int16_t*>(out);
503  for(t_size walk = 0; walk < inLen; ++walk) {
504  *outWalk++ = (int16_t)gen(in[walk]);
505  }
506 }
size_t t_size
Definition: int_types.h:48
static void render_24bit ( const audio_sample in,
t_size  inLen,
void *  out,
sampleToIntDesc const &  d 
)
static

Definition at line 483 of file audio_chunk.cpp.

483  {
484  t_uint8 * outWalk = reinterpret_cast<t_uint8*>(out);
485  sampleToInt<int32_t> gen(d);
486  for(t_size walk = 0; walk < inLen; ++walk) {
487  int32_t v = gen(in[walk]);
488  *(outWalk ++) = (t_uint8) (v & 0xFF);
489  *(outWalk ++) = (t_uint8) ((v >> 8) & 0xFF);
490  *(outWalk ++) = (t_uint8) ((v >> 16) & 0xFF);
491  }
492 }
uint8_t t_uint8
Definition: int_types.h:9
size_t t_size
Definition: int_types.h:48
template<typename internal_t >
static void render_32bit_ ( const audio_sample in,
t_size  inLen,
void *  out,
sampleToIntDesc const &  d 
)
static

Definition at line 509 of file audio_chunk.cpp.

509  {
510  sampleToInt<internal_t> gen(d); // must use int64 for clipping
511  int32_t * outWalk = reinterpret_cast<int32_t*>(out);
512  for(t_size walk = 0; walk < inLen; ++walk) {
513  *outWalk++ = (int32_t)gen(in[walk]);
514  }
515 }
size_t t_size
Definition: int_types.h:48
static void render_8bit ( const audio_sample in,
t_size  inLen,
void *  out,
sampleToIntDesc const &  d 
)
static

Definition at line 493 of file audio_chunk.cpp.

493  {
494  sampleToInt<int32_t> gen(d);
495  t_int8 * outWalk = reinterpret_cast<t_int8*>(out);
496  for(t_size walk = 0; walk < inLen; ++walk) {
497  *outWalk++ = (t_int8)gen(in[walk]);
498  }
499 }
size_t t_size
Definition: int_types.h:48
int8_t t_int8
Definition: int_types.h:8