foobar2000 SDK  2015-08-03
Static Public Member Functions | Static Public Attributes
pfc::audio_math

#include <audio_sample.h>

+ Inheritance diagram for pfc::audio_math:

Static Public Member Functions

static void add_offset (audio_sample *p_buffer, audio_sample p_delta, t_size p_count)
 
static audio_sample calculate_peak (const audio_sample *p_source, t_size p_count)
 
static void convert_from_int16 (const t_int16 *p_source, t_size p_count, audio_sample *p_output, audio_sample p_scale)
 
static void convert_from_int32 (const t_int32 *p_source, t_size p_count, audio_sample *p_output, audio_sample p_scale)
 
static void convert_to_int16 (const audio_sample *p_source, t_size p_count, t_int16 *p_output, audio_sample p_scale)
 
static audio_sample convert_to_int16_calculate_peak (const audio_sample *p_source, t_size p_count, t_int16 *p_output, audio_sample p_scale)
 
static void convert_to_int32 (const audio_sample *p_source, t_size p_count, t_int32 *p_output, audio_sample p_scale)
 
static audio_sample convert_to_int32_calculate_peak (const audio_sample *p_source, t_size p_count, t_int32 *p_output, audio_sample p_scale)
 
static audio_sample decodeFloat16 (uint16_t source)
 
static audio_sample decodeFloat24ptr (const void *sourcePtr)
 
static audio_sample decodeFloat24ptrbs (const void *sourcePtr)
 
static audio_sample gain_to_scale (double p_gain)
 
static void remove_denormals (audio_sample *p_buffer, t_size p_count)
 
static t_int32 rint32 (audio_sample val)
 
static t_int32 rint32 (float p_val)
 
static t_int32 rint32 (audio_sample val)
 
static t_int64 rint64 (audio_sample val)
 
static t_int64 rint64 (audio_sample val)
 
static t_int64 rint64 (audio_sample val)
 
static double samples_to_time (t_uint64 p_samples, t_uint32 p_sample_rate)
 
static void scale (const audio_sample *p_source, t_size p_count, audio_sample *p_output, audio_sample p_scale)
 
static double scale_to_gain (double scale)
 
static t_uint64 time_to_samples (double p_time, t_uint32 p_sample_rate)
 

Static Public Attributes

static const audio_sample float16scale = 65536.f
 

Detailed Description

Definition at line 20 of file audio_sample.h.

Member Function Documentation

void pfc::audio_math::add_offset ( audio_sample p_buffer,
audio_sample  p_delta,
t_size  p_count 
)
static

Definition at line 133 of file audio_math.cpp.

133  {
134  for(t_size n=0;n<p_count;n++) {
135  p_buffer[n] += p_delta;
136  }
137  }
size_t t_size
Definition: int_types.h:48
audio_sample pfc::audio_math::calculate_peak ( const audio_sample p_source,
t_size  p_count 
)
static

Definition at line 106 of file audio_math.cpp.

107  {
108  return noopt_calculate_peak(p_source,p_count);
109  }
static audio_sample noopt_calculate_peak(const audio_sample *p_src, t_size p_num)
Definition: audio_math.cpp:3
void pfc::audio_math::convert_from_int16 ( const t_int16 p_source,
t_size  p_count,
audio_sample p_output,
audio_sample  p_scale 
)
static

Definition at line 79 of file audio_math.cpp.

80  {
81  audio_sample scale = (audio_sample) ( p_scale / (double) 0x8000 );
82  noopt_convert_from_int16(p_source,p_count,p_output,scale);
83  }
static void noopt_convert_from_int16(const t_int16 *p_source, t_size p_count, audio_sample *p_output, float p_scale)
Definition: audio_math.cpp:36
float audio_sample
Definition: audio_sample.h:6
static void 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:61
void pfc::audio_math::convert_from_int32 ( const t_int32 p_source,
t_size  p_count,
audio_sample p_output,
audio_sample  p_scale 
)
static

Definition at line 99 of file audio_math.cpp.

100  {
101  audio_sample scale = (audio_sample) ( p_scale / (double) 0x80000000 );
102  noopt_convert_from_int32(p_source,p_count,p_output,scale);
103  }
float audio_sample
Definition: audio_sample.h:6
static void noopt_convert_from_int32(const t_int32 *p_source, t_size p_count, audio_sample *p_output, float p_scale)
Definition: audio_math.cpp:45
static void 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:61
void pfc::audio_math::convert_to_int16 ( const audio_sample p_source,
t_size  p_count,
t_int16 p_output,
audio_sample  p_scale 
)
static

Definition at line 66 of file audio_math.cpp.

67  {
68  audio_sample scale = (audio_sample)(p_scale * 0x8000);
69  noopt_convert_to_16bit(p_source,p_count,p_output,scale);
70  }
static void noopt_convert_to_16bit(const audio_sample *p_source, t_size p_count, t_int16 *p_output, float p_scale)
Definition: audio_math.cpp:30
float audio_sample
Definition: audio_sample.h:6
static void 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:61
audio_sample pfc::audio_math::convert_to_int16_calculate_peak ( const audio_sample p_source,
t_size  p_count,
t_int16 p_output,
audio_sample  p_scale 
)
static

Definition at line 72 of file audio_math.cpp.

73  {
74  //todo?
75  convert_to_int16(p_source,p_count,p_output,p_scale);
76  return p_scale * calculate_peak(p_source,p_count);
77  }
static audio_sample calculate_peak(const audio_sample *p_source, t_size p_count)
Definition: audio_math.cpp:106
static void convert_to_int16(const audio_sample *p_source, t_size p_count, t_int16 *p_output, audio_sample p_scale)
Definition: audio_math.cpp:66
void pfc::audio_math::convert_to_int32 ( const audio_sample p_source,
t_size  p_count,
t_int32 p_output,
audio_sample  p_scale 
)
static

Definition at line 85 of file audio_math.cpp.

86  {
87  audio_sample scale = (audio_sample)(p_scale * 0x80000000);
88  {
89  noopt_convert_to_32bit(p_source,p_count,p_output,scale);
90  }
91  }
float audio_sample
Definition: audio_sample.h:6
static void noopt_convert_to_32bit(const audio_sample *p_source, t_size p_count, t_int32 *p_output, float p_scale)
Definition: audio_math.cpp:18
static void 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:61
audio_sample pfc::audio_math::convert_to_int32_calculate_peak ( const audio_sample p_source,
t_size  p_count,
t_int32 p_output,
audio_sample  p_scale 
)
static

Definition at line 93 of file audio_math.cpp.

94  {
95  convert_to_int32(p_source,p_count,p_output,p_scale);
96  return p_scale * calculate_peak(p_source,p_count);
97  }
static audio_sample calculate_peak(const audio_sample *p_source, t_size p_count)
Definition: audio_math.cpp:106
static void convert_to_int32(const audio_sample *p_source, t_size p_count, t_int32 *p_output, audio_sample p_scale)
Definition: audio_math.cpp:85
audio_sample pfc::audio_math::decodeFloat16 ( uint16_t  source)
static

Definition at line 31 of file audio_sample.cpp.

31  {
32  const unsigned fractionBits = 10;
33  const unsigned widthBits = 16;
34  typedef uint16_t source_t;
35 
36  /* typedef uint64_t out_t; typedef double retval_t;
37  enum {
38  outExponent = 11,
39  outFraction = 52,
40  outExponentShift = (1 << (outExponent-1))-1
41  };*/
42 
43  typedef uint32_t out_t; typedef float retval_t;
44  enum {
45  outExponent = 8,
46  outFraction = 23,
47  outExponentShift = (1 << (outExponent-1))-1
48  };
49 
50  const unsigned exponentBits = widthBits - fractionBits - 1;
51  // 1 bit sign | exponent | fraction
52  source_t fraction = source & (((source_t)1 << fractionBits)-1);
53  source >>= fractionBits;
54  int exponent = (int)( source & (((source_t)1 << exponentBits)-1) ) - (int)((1 << (exponentBits-1))-1);
55  source >>= exponentBits;
56 
57  if (outExponent + outExponentShift <= 0) return 0;
58 
59  out_t output = (out_t)( source&1 );
60  output <<= outExponent;
61  output |= (unsigned) (exponent + outExponentShift) & ( (1<<outExponent) - 1 );
62  output <<= outFraction;
63  int shift = (int) outFraction - (int) fractionBits;
64  if (shift < 0) output |= (out_t) (fraction >> -shift);
65  else output |= (out_t) (fraction << shift);
66  return *(retval_t*)&output / pfc::audio_math::float16scale;
67  }
static const audio_sample float16scale
Definition: audio_sample.h:76
Definition: output.h:95
audio_sample pfc::audio_math::decodeFloat24ptr ( const void *  sourcePtr)
static

Definition at line 4 of file audio_sample.cpp.

4  {
5  PFC_STATIC_ASSERT(pfc::byte_order_is_little_endian);
6  union {
7  uint8_t bytes[4];
8  float v;
9  } u;
10  const uint8_t * s = reinterpret_cast<const uint8_t*>(sourcePtr);
11  u.bytes[0] = 0;
12  u.bytes[1] = s[0];
13  u.bytes[2] = s[1];
14  u.bytes[3] = s[2];
15  return u.v;
16  }
static const bool byte_order_is_little_endian
audio_sample pfc::audio_math::decodeFloat24ptrbs ( const void *  sourcePtr)
static

Definition at line 17 of file audio_sample.cpp.

17  {
18  PFC_STATIC_ASSERT(pfc::byte_order_is_little_endian);
19  union {
20  uint8_t bytes[4];
21  float v;
22  } u;
23  const uint8_t * s = reinterpret_cast<const uint8_t*>(sourcePtr);
24  u.bytes[0] = 0;
25  u.bytes[1] = s[2];
26  u.bytes[2] = s[1];
27  u.bytes[3] = s[0];
28  return u.v;
29  }
static const bool byte_order_is_little_endian
static audio_sample pfc::audio_math::gain_to_scale ( double  p_gain)
inlinestatic

Definition at line 73 of file audio_sample.h.

73 { return (audio_sample)pow(10.0, p_gain / 20.0); }
float audio_sample
Definition: audio_sample.h:6
void pfc::audio_math::remove_denormals ( audio_sample p_buffer,
t_size  p_count 
)
static

Definition at line 111 of file audio_math.cpp.

111  {
112 #if audio_sample_size == 32
113  t_uint32 * ptr = reinterpret_cast<t_uint32*>(p_buffer);
114  for(;p_count;p_count--)
115  {
116  t_uint32 t = *ptr;
117  if ((t & 0x007FFFFF) && !(t & 0x7F800000)) *ptr=0;
118  ptr++;
119  }
120 #elif audio_sample_size == 64
121  t_uint64 * ptr = reinterpret_cast<t_uint64*>(p_buffer);
122  for(;p_count;p_count--)
123  {
124  t_uint64 t = *ptr;
125  if ((t & 0x000FFFFFFFFFFFFF) && !(t & 0x7FF0000000000000)) *ptr=0;
126  ptr++;
127  }
128 #else
129 #error unsupported
130 #endif
131  }
uint64_t t_uint64
Definition: int_types.h:3
uint32_t t_uint32
Definition: int_types.h:5
static t_int32 pfc::audio_math::rint32 ( audio_sample  val)
inlinestatic

Definition at line 54 of file audio_sample.h.

54  {
55  t_int32 rv;
56  _asm {
57  fld val;
58  fistp rv;
59  }
60  return rv;
61  }
int32_t t_int32
Definition: int_types.h:4
static t_int32 pfc::audio_math::rint32 ( float  p_val)
inlinestatic

Definition at line 64 of file audio_sample.h.

64  {
65  return (t_int32)_mm_cvtss_si32(_mm_load_ss(&p_val));
66  }
int32_t t_int32
Definition: int_types.h:4
static t_int32 pfc::audio_math::rint32 ( audio_sample  val)
inlinestatic

Definition at line 69 of file audio_sample.h.

69 { return (t_int32)floor(val + 0.5); }
int32_t t_int32
Definition: int_types.h:4
static t_int64 pfc::audio_math::rint64 ( audio_sample  val)
inlinestatic

Definition at line 46 of file audio_sample.h.

46  {
47  t_int64 rv;
48  _asm {
49  fld val;
50  fistp rv;
51  }
52  return rv;
53  }
int64_t t_int64
Definition: int_types.h:2
static t_int64 pfc::audio_math::rint64 ( audio_sample  val)
inlinestatic

Definition at line 63 of file audio_sample.h.

63 { return (t_int64)floor(val + 0.5); }
int64_t t_int64
Definition: int_types.h:2
static t_int64 pfc::audio_math::rint64 ( audio_sample  val)
inlinestatic

Definition at line 68 of file audio_sample.h.

68 { return (t_int64)floor(val + 0.5); }
int64_t t_int64
Definition: int_types.h:2
static double pfc::audio_math::samples_to_time ( t_uint64  p_samples,
t_uint32  p_sample_rate 
)
inlinestatic

Definition at line 39 of file audio_sample.h.

39  {
40  PFC_ASSERT(p_sample_rate > 0);
41  return (double)p_samples / (double)p_sample_rate;
42  }
void pfc::audio_math::scale ( const audio_sample p_source,
t_size  p_count,
audio_sample p_output,
audio_sample  p_scale 
)
static

p_source/p_output can point to same buffer

Definition at line 61 of file audio_math.cpp.

62  {
63  noopt_scale(p_source,p_count,p_output,p_scale);
64  }
static void noopt_scale(const audio_sample *p_source, t_size p_count, audio_sample *p_output, audio_sample p_scale)
Definition: audio_math.cpp:52
static double pfc::audio_math::scale_to_gain ( double  scale)
inlinestatic

Definition at line 74 of file audio_sample.h.

74 { return 20.0*log10(scale); }
static void 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:61
static t_uint64 pfc::audio_math::time_to_samples ( double  p_time,
t_uint32  p_sample_rate 
)
inlinestatic

Definition at line 35 of file audio_sample.h.

35  {
36  return (t_uint64)floor((double)p_sample_rate * p_time + 0.5);
37  }
uint64_t t_uint64
Definition: int_types.h:3

Field Documentation

const audio_sample pfc::audio_math::float16scale = 65536.f
static

Definition at line 76 of file audio_sample.h.


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