ReactOS 0.4.16-dev-92-g0c2cdca
src_zoh.c File Reference
#include "precomp.h"
Include dependency graph for src_zoh.c:

Go to the source code of this file.

Classes

struct  ZOH_DATA
 

Macros

#define ZOH_MAGIC_MARKER   MAKE_MAGIC ('s', 'r', 'c', 'z', 'o', 'h')
 

Functions

static int zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
 
static void zoh_reset (SRC_PRIVATE *psrc)
 
const charzoh_get_name (int src_enum)
 
const charzoh_get_description (int src_enum)
 
int zoh_set_converter (SRC_PRIVATE *psrc, int src_enum)
 

Macro Definition Documentation

◆ ZOH_MAGIC_MARKER

#define ZOH_MAGIC_MARKER   MAKE_MAGIC ('s', 'r', 'c', 'z', 'o', 'h')

Definition at line 17 of file src_zoh.c.

Function Documentation

◆ 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 */
#define NULL
Definition: types.h:112
@ SRC_ZERO_ORDER_HOLD
Definition: samplerate.h:162

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 */

Referenced by src_get_name().

◆ zoh_reset()

static void zoh_reset ( SRC_PRIVATE psrc)
static

Definition at line 181 of file src_zoh.c.

182{ ZOH_DATA *priv ;
183
184 priv = (ZOH_DATA*) psrc->private_data ;
185 if (priv == NULL)
186 return ;
187
188 priv->channels = psrc->channels ;
189 priv->reset = 1 ;
190 memset (priv->last_value, 0, sizeof (priv->last_value [0]) * priv->channels) ;
191
192 return ;
193} /* zoh_reset */
return
Definition: dirsup.c:529
if(dx< 0)
Definition: linetemp.h:194
#define memset(x, y, z)
Definition: compat.h:39
int channels
Definition: common.h:96
void * private_data
Definition: common.h:102
int reset
Definition: src_zoh.c:22
int channels
Definition: src_zoh.c:21
float last_value[1]
Definition: src_zoh.c:25
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList

Referenced by zoh_set_converter().

◆ 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 */
#define free
Definition: debug_ros.c:5
#define calloc
Definition: rosglue.h:14
@ SRC_ERR_NO_ERROR
Definition: common.h:63
@ SRC_ERR_BAD_CONVERTER
Definition: common.h:74
@ SRC_ERR_MALLOC_FAILED
Definition: common.h:65
#define ZOH_MAGIC_MARKER
Definition: src_zoh.c:17
static int zoh_vari_process(SRC_PRIVATE *psrc, SRC_DATA *data)
Definition: src_zoh.c:32
static void zoh_reset(SRC_PRIVATE *psrc)
Definition: src_zoh.c:181
int(* const_process)(struct SRC_PRIVATE_tag *psrc, SRC_DATA *data)
Definition: common.h:108
int(* vari_process)(struct SRC_PRIVATE_tag *psrc, SRC_DATA *data)
Definition: common.h:105
void(* reset)(struct SRC_PRIVATE_tag *psrc)
Definition: common.h:111
int zoh_magic_marker
Definition: src_zoh.c:20

Referenced by psrc_set_converter().

◆ zoh_vari_process()

static int zoh_vari_process ( SRC_PRIVATE psrc,
SRC_DATA data 
)
static

Definition at line 32 of file src_zoh.c.

33{ ZOH_DATA *priv ;
34 double src_ratio, input_index, rem ;
35 int ch ;
36
37 if (data->input_frames <= 0)
38 return SRC_ERR_NO_ERROR ;
39
40 if (psrc->private_data == NULL)
41 return SRC_ERR_NO_PRIVATE ;
42
43 priv = (ZOH_DATA*) psrc->private_data ;
44
45 if (priv->reset)
46 { /* If we have just been reset, set the last_value data. */
47 for (ch = 0 ; ch < priv->channels ; ch++)
48 priv->last_value [ch] = data->data_in [ch] ;
49 priv->reset = 0 ;
50 } ;
51
52 priv->in_count = data->input_frames * priv->channels ;
53 priv->out_count = data->output_frames * priv->channels ;
54 priv->in_used = priv->out_gen = 0 ;
55
56 src_ratio = psrc->last_ratio ;
57
58 if (is_bad_src_ratio (src_ratio))
60
61 input_index = psrc->last_position ;
62
63 /* Calculate samples before first sample in input array. */
64 while (input_index < 1.0 && priv->out_gen < priv->out_count)
65 {
66 if (priv->in_used + priv->channels * input_index >= priv->in_count)
67 break ;
68
69 if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
70 src_ratio = psrc->last_ratio + priv->out_gen * (data->src_ratio - psrc->last_ratio) / priv->out_count ;
71
72 for (ch = 0 ; ch < priv->channels ; ch++)
73 { data->data_out [priv->out_gen] = priv->last_value [ch] ;
74 priv->out_gen ++ ;
75 } ;
76
77 /* Figure out the next index. */
78 input_index += 1.0 / src_ratio ;
79 } ;
80
81 rem = fmod_one (input_index) ;
82 priv->in_used += priv->channels * lrint (input_index - rem) ;
83 input_index = rem ;
84
85 /* Main processing loop. */
86 while (priv->out_gen < priv->out_count && priv->in_used + priv->channels * input_index <= priv->in_count)
87 {
88 if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
89 src_ratio = psrc->last_ratio + priv->out_gen * (data->src_ratio - psrc->last_ratio) / priv->out_count ;
90
91 for (ch = 0 ; ch < priv->channels ; ch++)
92 { data->data_out [priv->out_gen] = data->data_in [priv->in_used - priv->channels + ch] ;
93 priv->out_gen ++ ;
94 } ;
95
96 /* Figure out the next index. */
97 input_index += 1.0 / src_ratio ;
98 rem = fmod_one (input_index) ;
99
100 priv->in_used += priv->channels * lrint (input_index - rem) ;
101 input_index = rem ;
102 } ;
103
104 if (priv->in_used > priv->in_count)
105 { input_index += (priv->in_used - priv->in_count) / priv->channels ;
106 priv->in_used = priv->in_count ;
107 } ;
108
109 psrc->last_position = input_index ;
110
111 if (priv->in_used > 0)
112 for (ch = 0 ; ch < priv->channels ; ch++)
113 priv->last_value [ch] = data->data_in [priv->in_used - priv->channels + ch] ;
114
115 /* Save current ratio rather then target ratio. */
116 psrc->last_ratio = src_ratio ;
117
118 data->input_frames_used = priv->in_used / priv->channels ;
119 data->output_frames_gen = priv->out_gen / priv->channels ;
120
121 return SRC_ERR_NO_ERROR ;
122} /* zoh_vari_process */
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
_Check_return_ _CRT_JIT_INTRINSIC double __cdecl fabs(_In_ double x)
Definition: fabs.c:17
_Check_return_ __CRT_INLINE long lrint(_In_ double x)
Definition: math.h:292
#define for
Definition: utility.h:88
static UINT UINT * out_count
Definition: clipboard.c:35
static int is_bad_src_ratio(double ratio)
Definition: common.h:154
static double fmod_one(double x)
Definition: common.h:143
@ SRC_ERR_BAD_INTERNAL_STATE
Definition: common.h:86
@ SRC_ERR_NO_PRIVATE
Definition: common.h:69
#define SRC_MIN_RATIO_DIFF
Definition: common.h:23
double last_position
Definition: common.h:93
double last_ratio
Definition: common.h:93
long in_count
Definition: src_zoh.c:23
long out_count
Definition: src_zoh.c:24
long in_used
Definition: src_zoh.c:23
long out_gen
Definition: src_zoh.c:24

Referenced by zoh_set_converter().