ReactOS  0.4.13-dev-52-g0efcfec
common.h File Reference
#include "samplerate.h"
Include dependency graph for common.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SRC_PRIVATE_tag
 

Macros

#define SRC_MAX_RATIO   256
 
#define SRC_MAX_RATIO_STR   "256"
 
#define SRC_MIN_RATIO_DIFF   (1e-20)
 
#define MAX(a, b)   (((a) > (b)) ? (a) : (b))
 
#define MIN(a, b)   (((a) < (b)) ? (a) : (b))
 
#define ARRAY_LEN(x)   ((int) (sizeof (x) / sizeof ((x) [0])))
 
#define OFFSETOF(type, member)   ((int) (&((type*) 0)->member))
 
#define MAKE_MAGIC(a, b, c, d, e, f)   ((a) + ((b) << 4) + ((c) << 8) + ((d) << 12) + ((e) << 16) + ((f) << 20))
 
#define UNUSED(x)   x
 
#define WARN_UNUSED
 

Typedefs

typedef struct SRC_PRIVATE_tag SRC_PRIVATE
 

Enumerations

enum  { SRC_FALSE = 0, SRC_TRUE = 1, SRC_MODE_PROCESS = 555, SRC_MODE_CALLBACK = 556 }
 
enum  {
  SRC_ERR_NO_ERROR = 0, SRC_ERR_MALLOC_FAILED, SRC_ERR_BAD_STATE, SRC_ERR_BAD_DATA,
  SRC_ERR_BAD_DATA_PTR, SRC_ERR_NO_PRIVATE, SRC_ERR_BAD_SRC_RATIO, SRC_ERR_BAD_PROC_PTR,
  SRC_ERR_SHIFT_BITS, SRC_ERR_FILTER_LEN, SRC_ERR_BAD_CONVERTER, SRC_ERR_BAD_CHANNEL_COUNT,
  SRC_ERR_SINC_BAD_BUFFER_LEN, SRC_ERR_SIZE_INCOMPATIBILITY, SRC_ERR_BAD_PRIV_PTR, SRC_ERR_BAD_SINC_STATE,
  SRC_ERR_DATA_OVERLAP, SRC_ERR_BAD_CALLBACK, SRC_ERR_BAD_MODE, SRC_ERR_NULL_CALLBACK,
  SRC_ERR_NO_VARIABLE_RATIO, SRC_ERR_SINC_PREPARE_DATA_BAD_LEN, SRC_ERR_BAD_INTERNAL_STATE, SRC_ERR_MAX_ERROR
}
 

Functions

const charsinc_get_name (int src_enum)
 
const charsinc_get_description (int src_enum)
 
int sinc_set_converter (SRC_PRIVATE *psrc, int src_enum)
 
const charlinear_get_name (int src_enum)
 
const charlinear_get_description (int src_enum)
 
int linear_set_converter (SRC_PRIVATE *psrc, int src_enum)
 
const charzoh_get_name (int src_enum)
 
const charzoh_get_description (int src_enum)
 
int zoh_set_converter (SRC_PRIVATE *psrc, int src_enum)
 
static double fmod_one (double x)
 
static int is_bad_src_ratio (double ratio)
 

Macro Definition Documentation

◆ ARRAY_LEN

#define ARRAY_LEN (   x)    ((int) (sizeof (x) / sizeof ((x) [0])))

Definition at line 28 of file common.h.

◆ MAKE_MAGIC

#define MAKE_MAGIC (   a,
  b,
  c,
  d,
  e,
  f 
)    ((a) + ((b) << 4) + ((c) << 8) + ((d) << 12) + ((e) << 16) + ((f) << 20))

Definition at line 31 of file common.h.

◆ MAX

#define MAX (   a,
  b 
)    (((a) > (b)) ? (a) : (b))

Definition at line 25 of file common.h.

◆ MIN

#define MIN (   a,
  b 
)    (((a) < (b)) ? (a) : (b))

Definition at line 26 of file common.h.

◆ OFFSETOF

#define OFFSETOF (   type,
  member 
)    ((int) (&((type*) 0)->member))

Definition at line 29 of file common.h.

◆ SRC_MAX_RATIO

#define SRC_MAX_RATIO   256

Definition at line 20 of file common.h.

◆ SRC_MAX_RATIO_STR

#define SRC_MAX_RATIO_STR   "256"

Definition at line 21 of file common.h.

◆ SRC_MIN_RATIO_DIFF

#define SRC_MIN_RATIO_DIFF   (1e-20)

Definition at line 23 of file common.h.

◆ UNUSED

#define UNUSED (   x)    x

Definition at line 42 of file common.h.

◆ WARN_UNUSED

#define WARN_UNUSED

Definition at line 48 of file common.h.

Typedef Documentation

◆ SRC_PRIVATE

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SRC_FALSE 
SRC_TRUE 
SRC_MODE_PROCESS 
SRC_MODE_CALLBACK 

Definition at line 54 of file common.h.

55 { SRC_FALSE = 0,
56  SRC_TRUE = 1,
57 
58  SRC_MODE_PROCESS = 555,
59  SRC_MODE_CALLBACK = 556
60 } ;

◆ anonymous enum

anonymous enum
Enumerator
SRC_ERR_NO_ERROR 
SRC_ERR_MALLOC_FAILED 
SRC_ERR_BAD_STATE 
SRC_ERR_BAD_DATA 
SRC_ERR_BAD_DATA_PTR 
SRC_ERR_NO_PRIVATE 
SRC_ERR_BAD_SRC_RATIO 
SRC_ERR_BAD_PROC_PTR 
SRC_ERR_SHIFT_BITS 
SRC_ERR_FILTER_LEN 
SRC_ERR_BAD_CONVERTER 
SRC_ERR_BAD_CHANNEL_COUNT 
SRC_ERR_SINC_BAD_BUFFER_LEN 
SRC_ERR_SIZE_INCOMPATIBILITY 
SRC_ERR_BAD_PRIV_PTR 
SRC_ERR_BAD_SINC_STATE 
SRC_ERR_DATA_OVERLAP 
SRC_ERR_BAD_CALLBACK 
SRC_ERR_BAD_MODE 
SRC_ERR_NULL_CALLBACK 
SRC_ERR_NO_VARIABLE_RATIO 
SRC_ERR_SINC_PREPARE_DATA_BAD_LEN 
SRC_ERR_BAD_INTERNAL_STATE 
SRC_ERR_MAX_ERROR 

Definition at line 62 of file common.h.

63 { SRC_ERR_NO_ERROR = 0,
64 
87 
88  /* This must be the last error number. */
90 } ;

Function Documentation

◆ fmod_one()

static double fmod_one ( double  x)
inlinestatic

Definition at line 143 of file common.h.

144 { double res ;
145 
146  res = x - lrint (x) ;
147  if (res < 0.0)
148  return res + 1.0 ;
149 
150  return res ;
151 } /* fmod_one */
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
_Check_return_ __CRT_INLINE long lrint(_In_ double x)
Definition: math.h:267
GLuint res
Definition: glext.h:9613

Referenced by linear_vari_process(), sinc_hex_vari_process(), sinc_mono_vari_process(), sinc_multichan_vari_process(), sinc_quad_vari_process(), sinc_stereo_vari_process(), and zoh_vari_process().

◆ is_bad_src_ratio()

static int is_bad_src_ratio ( double  ratio)
inlinestatic

◆ linear_get_description()

const char* linear_get_description ( int  src_enum)

Definition at line 146 of file src_linear.c.

147 {
148  if (src_enum == SRC_LINEAR)
149  return "Linear interpolator, very fast, poor quality." ;
150 
151  return NULL ;
152 } /* linear_get_descrition */
smooth NULL
Definition: ftsmooth.c:416

Referenced by src_get_description().

◆ linear_get_name()

const char* linear_get_name ( int  src_enum)

Definition at line 137 of file src_linear.c.

138 {
139  if (src_enum == SRC_LINEAR)
140  return "Linear Interpolator" ;
141 
142  return NULL ;
143 } /* linear_get_name */
smooth NULL
Definition: ftsmooth.c:416

Referenced by src_get_name().

◆ linear_set_converter()

int linear_set_converter ( SRC_PRIVATE psrc,
int  src_enum 
)

Definition at line 155 of file src_linear.c.

156 { LINEAR_DATA *priv = NULL ;
157 
158  if (src_enum != SRC_LINEAR)
159  return SRC_ERR_BAD_CONVERTER ;
160 
161  if (psrc->private_data != NULL)
162  { free (psrc->private_data) ;
163  psrc->private_data = NULL ;
164  } ;
165 
166  if (psrc->private_data == NULL)
167  { priv = calloc (1, sizeof (*priv) + psrc->channels * sizeof (float)) ;
168  psrc->private_data = priv ;
169  } ;
170 
171  if (priv == NULL)
172  return SRC_ERR_MALLOC_FAILED ;
173 
175  priv->channels = psrc->channels ;
176 
179  psrc->reset = linear_reset ;
180 
181  linear_reset (psrc) ;
182 
183  return SRC_ERR_NO_ERROR ;
184 } /* linear_set_converter */
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
#define free
Definition: debug_ros.c:5
int linear_magic_marker
Definition: src_linear.c:22
static void linear_reset(SRC_PRIVATE *psrc)
Definition: src_linear.c:190
int(* vari_process)(struct SRC_PRIVATE_tag *psrc, SRC_DATA *data)
Definition: common.h:105
smooth NULL
Definition: ftsmooth.c:416
static int linear_vari_process(SRC_PRIVATE *psrc, SRC_DATA *data)
Definition: src_linear.c:34
void(* reset)(struct SRC_PRIVATE_tag *psrc)
Definition: common.h:111
int channels
Definition: src_linear.c:23
int(* const_process)(struct SRC_PRIVATE_tag *psrc, SRC_DATA *data)
Definition: common.h:108
#define LINEAR_MAGIC_MARKER
Definition: src_linear.c:17
int channels
Definition: common.h:96
#define calloc
Definition: rosglue.h:14
void * private_data
Definition: common.h:102

Referenced by psrc_set_converter().

◆ sinc_get_description()

const char* sinc_get_description ( int  src_enum)

Definition at line 113 of file src_sinc.c.

114 {
115  switch (src_enum)
116  { case SRC_SINC_FASTEST :
117  return "Band limited sinc interpolation, fastest, 97dB SNR, 80% BW." ;
118 
120  return "Band limited sinc interpolation, medium quality, 121dB SNR, 90% BW." ;
121 
122  case SRC_SINC_BEST_QUALITY :
123  return "Band limited sinc interpolation, best quality, 144dB SNR, 96% BW." ;
124 
125  default :
126  break ;
127  } ;
128 
129  return NULL ;
130 } /* sinc_get_descrition */
smooth NULL
Definition: ftsmooth.c:416

Referenced by src_get_description().

◆ sinc_get_name()

const char* sinc_get_name ( int  src_enum)

Definition at line 94 of file src_sinc.c.

95 {
96  switch (src_enum)
97  { case SRC_SINC_BEST_QUALITY :
98  return "Best Sinc Interpolator" ;
99 
101  return "Medium Sinc Interpolator" ;
102 
103  case SRC_SINC_FASTEST :
104  return "Fastest Sinc Interpolator" ;
105 
106  default: break ;
107  } ;
108 
109  return NULL ;
110 } /* sinc_get_descrition */
smooth NULL
Definition: ftsmooth.c:416

Referenced by src_get_name().

◆ sinc_set_converter()

int sinc_set_converter ( SRC_PRIVATE psrc,
int  src_enum 
)

Definition at line 133 of file src_sinc.c.

134 { SINC_FILTER *filter, temp_filter ;
136  int bits ;
137 
138  /* Quick sanity check. */
139  if (SHIFT_BITS >= sizeof (increment_t) * 8 - 1)
140  return SRC_ERR_SHIFT_BITS ;
141 
142  if (psrc->private_data != NULL)
143  { free (psrc->private_data) ;
144  psrc->private_data = NULL ;
145  } ;
146 
147  memset (&temp_filter, 0, sizeof (temp_filter)) ;
148 
149  temp_filter.sinc_magic_marker = SINC_MAGIC_MARKER ;
150  temp_filter.channels = psrc->channels ;
151 
152  if (psrc->channels > ARRAY_LEN (temp_filter.left_calc))
154  else if (psrc->channels == 1)
157  }
158  else
159  if (psrc->channels == 2)
162  }
163  else
164  if (psrc->channels == 4)
167  }
168  else
169  if (psrc->channels == 6)
172  }
173  else
176  } ;
177  psrc->reset = sinc_reset ;
178 
179  switch (src_enum)
180  { case SRC_SINC_FASTEST :
181  temp_filter.coeffs = fastest_coeffs.coeffs ;
182  temp_filter.coeff_half_len = ARRAY_LEN (fastest_coeffs.coeffs) - 2 ;
183  temp_filter.index_inc = fastest_coeffs.increment ;
184  break ;
185 
187  temp_filter.coeffs = slow_mid_qual_coeffs.coeffs ;
188  temp_filter.coeff_half_len = ARRAY_LEN (slow_mid_qual_coeffs.coeffs) - 2 ;
189  temp_filter.index_inc = slow_mid_qual_coeffs.increment ;
190  break ;
191 
192  case SRC_SINC_BEST_QUALITY :
193  temp_filter.coeffs = slow_high_qual_coeffs.coeffs ;
194  temp_filter.coeff_half_len = ARRAY_LEN (slow_high_qual_coeffs.coeffs) - 2 ;
195  temp_filter.index_inc = slow_high_qual_coeffs.increment ;
196  break ;
197 
198  default :
199  return SRC_ERR_BAD_CONVERTER ;
200  } ;
201 
202  /*
203  ** FIXME : This needs to be looked at more closely to see if there is
204  ** a better way. Need to look at prepare_data () at the same time.
205  */
206 
207  temp_filter.b_len = lrint (2.5 * temp_filter.coeff_half_len / (temp_filter.index_inc * 1.0) * SRC_MAX_RATIO) ;
208  temp_filter.b_len = MAX (temp_filter.b_len, 4096) ;
209  temp_filter.b_len *= temp_filter.channels ;
210 
211  if ((filter = calloc (1, sizeof (SINC_FILTER) + sizeof (filter->buffer [0]) * (temp_filter.b_len + temp_filter.channels))) == NULL)
212  return SRC_ERR_MALLOC_FAILED ;
213 
214  *filter = temp_filter ;
215  memset (&temp_filter, 0xEE, sizeof (temp_filter)) ;
216 
217  psrc->private_data = filter ;
218 
219  sinc_reset (psrc) ;
220 
221  count = filter->coeff_half_len ;
222  for (bits = 0 ; (MAKE_INCREMENT_T (1) << bits) < count ; bits++)
223  count |= (MAKE_INCREMENT_T (1) << bits) ;
224 
225  if (bits + SHIFT_BITS - 1 >= (int) (sizeof (increment_t) * 8))
226  return SRC_ERR_FILTER_LEN ;
227 
228  return SRC_ERR_NO_ERROR ;
229 } /* sinc_set_converter */
static const struct slow_high_qual_coeffs_s slow_high_qual_coeffs
#define SINC_MAGIC_MARKER
Definition: src_sinc.c:11
#define MAKE_INCREMENT_T(x)
Definition: src_sinc.c:16
GLuint GLuint GLsizei count
Definition: gl.h:1545
int index_inc
Definition: src_sinc.c:39
#define free
Definition: debug_ros.c:5
int32_t increment_t
Definition: src_sinc.c:25
_Check_return_ __CRT_INLINE long lrint(_In_ double x)
Definition: math.h:267
static int sinc_multichan_vari_process(SRC_PRIVATE *psrc, SRC_DATA *data)
Definition: src_sinc.c:1017
int(* vari_process)(struct SRC_PRIVATE_tag *psrc, SRC_DATA *data)
Definition: common.h:105
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
#define SRC_MAX_RATIO
Definition: common.h:20
static int sinc_stereo_vari_process(SRC_PRIVATE *psrc, SRC_DATA *data)
Definition: src_sinc.c:456
#define ARRAY_LEN(x)
Definition: common.h:28
smooth NULL
Definition: ftsmooth.c:416
coeff_t const * coeffs
Definition: src_sinc.c:43
static int sinc_mono_vari_process(SRC_PRIVATE *psrc, SRC_DATA *data)
Definition: src_sinc.c:307
#define SHIFT_BITS
Definition: src_sinc.c:18
void(* reset)(struct SRC_PRIVATE_tag *psrc)
Definition: common.h:111
static void sinc_reset(SRC_PRIVATE *psrc)
Definition: src_sinc.c:232
int channels
Definition: src_sinc.c:35
T MAX(T a, T b)
Definition: polytest.cpp:85
static int sinc_quad_vari_process(SRC_PRIVATE *psrc, SRC_DATA *data)
Definition: src_sinc.c:610
int(* const_process)(struct SRC_PRIVATE_tag *psrc, SRC_DATA *data)
Definition: common.h:108
int sinc_magic_marker
Definition: src_sinc.c:33
int coeff_half_len
Definition: src_sinc.c:39
int channels
Definition: common.h:96
static const struct fastest_coeffs_s fastest_coeffs
static int sinc_hex_vari_process(SRC_PRIVATE *psrc, SRC_DATA *data)
Definition: src_sinc.c:770
static const struct slow_mid_qual_coeffs_s slow_mid_qual_coeffs
int b_len
Definition: src_sinc.c:45
double left_calc[128]
Definition: src_sinc.c:48
#define calloc
Definition: rosglue.h:14
#define memset(x, y, z)
Definition: compat.h:39
void * private_data
Definition: common.h:102
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005

Referenced by psrc_set_converter().

◆ zoh_get_description()

const char* zoh_get_description ( int  src_enum)

Definition at line 137 of file src_zoh.c.

138 {
139  if (src_enum == SRC_ZERO_ORDER_HOLD)
140  return "Zero order hold interpolator, very fast, poor quality." ;
141 
142  return NULL ;
143 } /* zoh_get_descrition */
smooth NULL
Definition: ftsmooth.c:416

Referenced by src_get_description().

◆ zoh_get_name()

const char* zoh_get_name ( int  src_enum)

Definition at line 128 of file src_zoh.c.

129 {
130  if (src_enum == SRC_ZERO_ORDER_HOLD)
131  return "ZOH Interpolator" ;
132 
133  return NULL ;
134 } /* zoh_get_name */
smooth NULL
Definition: ftsmooth.c:416

Referenced by src_get_name().

◆ zoh_set_converter()

int zoh_set_converter ( SRC_PRIVATE psrc,
int  src_enum 
)

Definition at line 146 of file src_zoh.c.

147 { ZOH_DATA *priv = NULL ;
148 
149  if (src_enum != SRC_ZERO_ORDER_HOLD)
150  return SRC_ERR_BAD_CONVERTER ;
151 
152  if (psrc->private_data != NULL)
153  { free (psrc->private_data) ;
154  psrc->private_data = NULL ;
155  } ;
156 
157  if (psrc->private_data == NULL)
158  { priv = calloc (1, sizeof (*priv) + psrc->channels * sizeof (float)) ;
159  psrc->private_data = priv ;
160  } ;
161 
162  if (priv == NULL)
163  return SRC_ERR_MALLOC_FAILED ;
164 
166  priv->channels = psrc->channels ;
167 
170  psrc->reset = zoh_reset ;
171 
172  zoh_reset (psrc) ;
173 
174  return SRC_ERR_NO_ERROR ;
175 } /* zoh_set_converter */
int zoh_magic_marker
Definition: src_zoh.c:20
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
#define free
Definition: debug_ros.c:5
int(* vari_process)(struct SRC_PRIVATE_tag *psrc, SRC_DATA *data)
Definition: common.h:105
static int zoh_vari_process(SRC_PRIVATE *psrc, SRC_DATA *data)
Definition: src_zoh.c:32
smooth NULL
Definition: ftsmooth.c:416
static void zoh_reset(SRC_PRIVATE *psrc)
Definition: src_zoh.c:181
#define ZOH_MAGIC_MARKER
Definition: src_zoh.c:17
void(* reset)(struct SRC_PRIVATE_tag *psrc)
Definition: common.h:111
int channels
Definition: src_zoh.c:21
int(* const_process)(struct SRC_PRIVATE_tag *psrc, SRC_DATA *data)
Definition: common.h:108
int channels
Definition: common.h:96
#define calloc
Definition: rosglue.h:14
void * private_data
Definition: common.h:102

Referenced by psrc_set_converter().