ReactOS 0.4.16-dev-300-g2aadf2e
common.h
Go to the documentation of this file.
1/*
2** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
3** All rights reserved.
4**
5** This code is released under 2-clause BSD license. Please see the
6** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
7*/
8
9#ifndef COMMON_H_INCLUDED
10#define COMMON_H_INCLUDED
11
12#ifdef HAVE_STDINT_H
13#include <stdint.h>
14#elif (SIZEOF_INT == 4)
15typedef int int32_t ;
16#elif (SIZEOF_LONG == 4)
17typedef long int32_t ;
18#endif
19
20#define SRC_MAX_RATIO 256
21#define SRC_MAX_RATIO_STR "256"
22
23#define SRC_MIN_RATIO_DIFF (1e-20)
24
25#define MAX(a,b) (((a) > (b)) ? (a) : (b))
26#define MIN(a,b) (((a) < (b)) ? (a) : (b))
27
28#define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0])))
29#define OFFSETOF(type,member) ((int) (&((type*) 0)->member))
30
31#define MAKE_MAGIC(a,b,c,d,e,f) ((a) + ((b) << 4) + ((c) << 8) + ((d) << 12) + ((e) << 16) + ((f) << 20))
32
33/*
34** Inspiration : http://sourcefrog.net/weblog/software/languages/C/unused.html
35*/
36#ifdef UNUSED
37#elif defined (__GNUC__)
38# define UNUSED(x) UNUSED_ ## x __attribute__ ((unused))
39#elif defined (__LCLINT__)
40# define UNUSED(x) /*@unused@*/ x
41#else
42# define UNUSED(x) x
43#endif
44
45#ifdef __GNUC__
46# define WARN_UNUSED __attribute__ ((warn_unused_result))
47#else
48# define WARN_UNUSED
49#endif
50
51
52#include "samplerate.h"
53
54enum
57
60} ;
61
62enum
64
87
88 /* This must be the last error number. */
90} ;
91
92typedef struct SRC_PRIVATE_tag
94
95 int error ;
97
98 /* SRC_MODE_PROCESS or SRC_MODE_CALLBACK */
99 int mode ;
100
101 /* Pointer to data to converter specific data. */
103
104 /* Varispeed process function. */
106
107 /* Constant speed process function. */
109
110 /* State reset. */
111 void (*reset) (struct SRC_PRIVATE_tag *psrc) ;
112
113 /* Data specific to SRC_MODE_CALLBACK. */
117 const float *saved_data ;
119
120/* In src_sinc.c */
121const char* sinc_get_name (int src_enum) ;
122const char* sinc_get_description (int src_enum) ;
123
124int sinc_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
125
126/* In src_linear.c */
127const char* linear_get_name (int src_enum) ;
128const char* linear_get_description (int src_enum) ;
129
130int linear_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
131
132/* In src_zoh.c */
133const char* zoh_get_name (int src_enum) ;
134const char* zoh_get_description (int src_enum) ;
135
136int zoh_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
137
138/*----------------------------------------------------------
139** Common static inline functions.
140*/
141
142static inline double
143fmod_one (double x)
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 */
152
153static inline int
154is_bad_src_ratio (double ratio)
155{ return (ratio < (1.0 / SRC_MAX_RATIO) || ratio > (1.0 * SRC_MAX_RATIO)) ;
156} /* is_bad_src_ratio */
157
158
159#endif /* COMMON_H_INCLUDED */
160
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLboolean reset
Definition: glext.h:5666
GLuint res
Definition: glext.h:9613
_Check_return_ __CRT_INLINE long lrint(_In_ double x)
Definition: math.h:292
#define int32_t
Definition: nsiface.idl:56
long(* src_callback_t)(void *cb_data, float **data)
Definition: samplerate.h:47
static int is_bad_src_ratio(double ratio)
Definition: common.h:154
#define SRC_MAX_RATIO
Definition: common.h:20
const char * sinc_get_description(int src_enum)
Definition: src_sinc.c:113
const char * zoh_get_description(int src_enum)
Definition: src_zoh.c:137
int sinc_set_converter(SRC_PRIVATE *psrc, int src_enum)
Definition: src_sinc.c:133
@ SRC_MODE_CALLBACK
Definition: common.h:59
@ SRC_MODE_PROCESS
Definition: common.h:58
@ SRC_FALSE
Definition: common.h:55
@ SRC_TRUE
Definition: common.h:56
const char * zoh_get_name(int src_enum)
Definition: src_zoh.c:128
int linear_set_converter(SRC_PRIVATE *psrc, int src_enum)
Definition: src_linear.c:155
@ SRC_ERR_DATA_OVERLAP
Definition: common.h:80
@ SRC_ERR_SIZE_INCOMPATIBILITY
Definition: common.h:77
@ SRC_ERR_FILTER_LEN
Definition: common.h:73
@ SRC_ERR_NO_VARIABLE_RATIO
Definition: common.h:84
@ SRC_ERR_NO_ERROR
Definition: common.h:63
@ SRC_ERR_BAD_SINC_STATE
Definition: common.h:79
@ SRC_ERR_BAD_PROC_PTR
Definition: common.h:71
@ SRC_ERR_BAD_INTERNAL_STATE
Definition: common.h:86
@ SRC_ERR_BAD_DATA_PTR
Definition: common.h:68
@ SRC_ERR_MAX_ERROR
Definition: common.h:89
@ SRC_ERR_BAD_STATE
Definition: common.h:66
@ SRC_ERR_BAD_SRC_RATIO
Definition: common.h:70
@ SRC_ERR_NULL_CALLBACK
Definition: common.h:83
@ SRC_ERR_BAD_CHANNEL_COUNT
Definition: common.h:75
@ SRC_ERR_BAD_MODE
Definition: common.h:82
@ SRC_ERR_SINC_PREPARE_DATA_BAD_LEN
Definition: common.h:85
@ SRC_ERR_BAD_CONVERTER
Definition: common.h:74
@ SRC_ERR_SINC_BAD_BUFFER_LEN
Definition: common.h:76
@ SRC_ERR_NO_PRIVATE
Definition: common.h:69
@ SRC_ERR_SHIFT_BITS
Definition: common.h:72
@ SRC_ERR_BAD_DATA
Definition: common.h:67
@ SRC_ERR_BAD_CALLBACK
Definition: common.h:81
@ SRC_ERR_BAD_PRIV_PTR
Definition: common.h:78
@ SRC_ERR_MALLOC_FAILED
Definition: common.h:65
const char * sinc_get_name(int src_enum)
Definition: src_sinc.c:94
struct SRC_PRIVATE_tag SRC_PRIVATE
static double fmod_one(double x)
Definition: common.h:143
const char * linear_get_name(int src_enum)
Definition: src_linear.c:137
int zoh_set_converter(SRC_PRIVATE *psrc, int src_enum)
Definition: src_zoh.c:146
const char * linear_get_description(int src_enum)
Definition: src_linear.c:146
double last_position
Definition: common.h:93
long saved_frames
Definition: common.h:116
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
double last_ratio
Definition: common.h:93
const float * saved_data
Definition: common.h:117
src_callback_t callback_func
Definition: common.h:114
void * user_callback_data
Definition: common.h:115
int channels
Definition: common.h:96
void * private_data
Definition: common.h:102