ReactOS  0.4.14-dev-556-g4c5b21f
src_linear.c File Reference
#include "precomp.h"
Include dependency graph for src_linear.c:

Go to the source code of this file.

Classes

struct  LINEAR_DATA
 

Macros

#define LINEAR_MAGIC_MARKER   MAKE_MAGIC ('l', 'i', 'n', 'e', 'a', 'r')
 
#define SRC_DEBUG   0
 

Functions

static int linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
 
static void linear_reset (SRC_PRIVATE *psrc)
 
const charlinear_get_name (int src_enum)
 
const charlinear_get_description (int src_enum)
 
int linear_set_converter (SRC_PRIVATE *psrc, int src_enum)
 

Macro Definition Documentation

◆ LINEAR_MAGIC_MARKER

#define LINEAR_MAGIC_MARKER   MAKE_MAGIC ('l', 'i', 'n', 'e', 'a', 'r')

Definition at line 17 of file src_linear.c.

◆ SRC_DEBUG

#define SRC_DEBUG   0

Definition at line 19 of file src_linear.c.

Function Documentation

◆ 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_reset()

static void linear_reset ( SRC_PRIVATE psrc)
static

Definition at line 190 of file src_linear.c.

191 { LINEAR_DATA *priv = NULL ;
192 
193  priv = (LINEAR_DATA*) psrc->private_data ;
194  if (priv == NULL)
195  return ;
196 
197  priv->channels = psrc->channels ;
198  priv->reset = 1 ;
199  memset (priv->last_value, 0, sizeof (priv->last_value [0]) * priv->channels) ;
200 
201  return ;
202 } /* linear_reset */
return
Definition: dirsup.c:529
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
smooth NULL
Definition: ftsmooth.c:416
if(!(yy_init))
Definition: macro.lex.yy.c:714
float last_value[1]
Definition: src_linear.c:27
int channels
Definition: src_linear.c:23
int channels
Definition: common.h:96
#define memset(x, y, z)
Definition: compat.h:39
void * private_data
Definition: common.h:102

Referenced by linear_set_converter().

◆ 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().

◆ linear_vari_process()

static int linear_vari_process ( SRC_PRIVATE psrc,
SRC_DATA data 
)
static

Definition at line 34 of file src_linear.c.

35 { LINEAR_DATA *priv ;
36  double src_ratio, input_index, rem ;
37  int ch ;
38 
39  if (data->input_frames <= 0)
40  return SRC_ERR_NO_ERROR ;
41 
42  if (psrc->private_data == NULL)
43  return SRC_ERR_NO_PRIVATE ;
44 
45  priv = (LINEAR_DATA*) psrc->private_data ;
46 
47  if (priv->reset)
48  { /* If we have just been reset, set the last_value data. */
49  for (ch = 0 ; ch < priv->channels ; ch++)
50  priv->last_value [ch] = data->data_in [ch] ;
51  priv->reset = 0 ;
52  } ;
53 
54  priv->in_count = data->input_frames * priv->channels ;
55  priv->out_count = data->output_frames * priv->channels ;
56  priv->in_used = priv->out_gen = 0 ;
57 
58  src_ratio = psrc->last_ratio ;
59 
60  if (is_bad_src_ratio (src_ratio))
62 
63  input_index = psrc->last_position ;
64 
65  /* Calculate samples before first sample in input array. */
66  while (input_index < 1.0 && priv->out_gen < priv->out_count)
67  {
68  if (priv->in_used + priv->channels * (1.0 + input_index) >= priv->in_count)
69  break ;
70 
71  if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
72  src_ratio = psrc->last_ratio + priv->out_gen * (data->src_ratio - psrc->last_ratio) / priv->out_count ;
73 
74  for (ch = 0 ; ch < priv->channels ; ch++)
75  { data->data_out [priv->out_gen] = (float) (priv->last_value [ch] + input_index *
76  (data->data_in [ch] - priv->last_value [ch])) ;
77  priv->out_gen ++ ;
78  } ;
79 
80  /* Figure out the next index. */
81  input_index += 1.0 / src_ratio ;
82  } ;
83 
84  rem = fmod_one (input_index) ;
85  priv->in_used += priv->channels * lrint (input_index - rem) ;
86  input_index = rem ;
87 
88  /* Main processing loop. */
89  while (priv->out_gen < priv->out_count && priv->in_used + priv->channels * input_index < priv->in_count)
90  {
91  if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
92  src_ratio = psrc->last_ratio + priv->out_gen * (data->src_ratio - psrc->last_ratio) / priv->out_count ;
93 
94  if (SRC_DEBUG && priv->in_used < priv->channels && input_index < 1.0)
95  { printf ("Whoops!!!! in_used : %ld channels : %d input_index : %f\n", priv->in_used, priv->channels, input_index) ;
96  exit (1) ;
97  } ;
98 
99  for (ch = 0 ; ch < priv->channels ; ch++)
100  { data->data_out [priv->out_gen] = (float) (data->data_in [priv->in_used - priv->channels + ch] + input_index *
101  (data->data_in [priv->in_used + ch] - data->data_in [priv->in_used - priv->channels + ch])) ;
102  priv->out_gen ++ ;
103  } ;
104 
105  /* Figure out the next index. */
106  input_index += 1.0 / src_ratio ;
107  rem = fmod_one (input_index) ;
108 
109  priv->in_used += priv->channels * lrint (input_index - rem) ;
110  input_index = rem ;
111  } ;
112 
113  if (priv->in_used > priv->in_count)
114  { input_index += (priv->in_used - priv->in_count) / priv->channels ;
115  priv->in_used = priv->in_count ;
116  } ;
117 
118  psrc->last_position = input_index ;
119 
120  if (priv->in_used > 0)
121  for (ch = 0 ; ch < priv->channels ; ch++)
122  priv->last_value [ch] = data->data_in [priv->in_used - priv->channels + ch] ;
123 
124  /* Save current ratio rather then target ratio. */
125  psrc->last_ratio = src_ratio ;
126 
127  data->input_frames_used = priv->in_used / priv->channels ;
128  data->output_frames_gen = priv->out_gen / priv->channels ;
129 
130  return SRC_ERR_NO_ERROR ;
131 } /* linear_vari_process */
long in_count
Definition: src_linear.c:25
static double fmod_one(double x)
Definition: common.h:143
_Check_return_ __CRT_INLINE long lrint(_In_ double x)
Definition: math.h:267
smooth NULL
Definition: ftsmooth.c:416
long out_gen
Definition: src_linear.c:26
#define SRC_MIN_RATIO_DIFF
Definition: common.h:23
if(!(yy_init))
Definition: macro.lex.yy.c:714
double last_ratio
Definition: common.h:93
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
float last_value[1]
Definition: src_linear.c:27
double last_position
Definition: common.h:93
long out_count
Definition: src_linear.c:26
int channels
Definition: src_linear.c:23
long in_used
Definition: src_linear.c:25
_Check_return_ _CRT_JIT_INTRINSIC double __cdecl fabs(_In_ double x)
static float(__cdecl *square_half_float)(float x
#define SRC_DEBUG
Definition: src_linear.c:19
void exit(int exitcode)
Definition: _exit.c:33
void * private_data
Definition: common.h:102
static int is_bad_src_ratio(double ratio)
Definition: common.h:154
static UINT UINT * out_count
Definition: clipboard.c:35
#define printf
Definition: config.h:203

Referenced by linear_set_converter().