2 ** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
3 ** All rights reserved.
5 ** This code is released under 2-clause BSD license. Please see the
6 ** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
9 #ifndef COMMON_H_INCLUDED
10 #define COMMON_H_INCLUDED
14 #elif (SIZEOF_INT == 4)
16 #elif (SIZEOF_LONG == 4)
17 typedef long int32_t ;
20 #define SRC_MAX_RATIO 256
21 #define SRC_MAX_RATIO_STR "256"
23 #define SRC_MIN_RATIO_DIFF (1e-20)
25 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
26 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
28 #define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0])))
29 #define OFFSETOF(type,member) ((int) (&((type*) 0)->member))
31 #define MAKE_MAGIC(a,b,c,d,e,f) ((a) + ((b) << 4) + ((c) << 8) + ((d) << 12) + ((e) << 16) + ((f) << 20))
34 ** Inspiration : http://sourcefrog.net/weblog/software/languages/C/unused.html
37 #elif defined (__GNUC__)
38 # define UNUSED(x) UNUSED_ ## x __attribute__ ((unused))
39 #elif defined (__LCLINT__)
40 # define UNUSED(x) /*@unused@*/ x
46 # define WARN_UNUSED __attribute__ ((warn_unused_result))
52 #include "samplerate.h"
58 SRC_MODE_PROCESS
= 555,
59 SRC_MODE_CALLBACK
= 556
63 { SRC_ERR_NO_ERROR
= 0,
65 SRC_ERR_MALLOC_FAILED
,
70 SRC_ERR_BAD_SRC_RATIO
,
74 SRC_ERR_BAD_CONVERTER
,
75 SRC_ERR_BAD_CHANNEL_COUNT
,
76 SRC_ERR_SINC_BAD_BUFFER_LEN
,
77 SRC_ERR_SIZE_INCOMPATIBILITY
,
79 SRC_ERR_BAD_SINC_STATE
,
83 SRC_ERR_NULL_CALLBACK
,
84 SRC_ERR_NO_VARIABLE_RATIO
,
85 SRC_ERR_SINC_PREPARE_DATA_BAD_LEN
,
86 SRC_ERR_BAD_INTERNAL_STATE
,
88 /* This must be the last error number. */
92 typedef struct SRC_PRIVATE_tag
93 { double last_ratio
, last_position
;
98 /* SRC_MODE_PROCESS or SRC_MODE_CALLBACK */
101 /* Pointer to data to converter specific data. */
104 /* Varispeed process function. */
105 int (*vari_process
) (struct SRC_PRIVATE_tag
*psrc
, SRC_DATA
*data
) ;
107 /* Constant speed process function. */
108 int (*const_process
) (struct SRC_PRIVATE_tag
*psrc
, SRC_DATA
*data
) ;
111 void (*reset
) (struct SRC_PRIVATE_tag
*psrc
) ;
113 /* Data specific to SRC_MODE_CALLBACK. */
114 src_callback_t callback_func
;
115 void *user_callback_data
;
117 const float *saved_data
;
121 const char* sinc_get_name (int src_enum
) ;
122 const char* sinc_get_description (int src_enum
) ;
124 int sinc_set_converter (SRC_PRIVATE
*psrc
, int src_enum
) ;
126 /* In src_linear.c */
127 const char* linear_get_name (int src_enum
) ;
128 const char* linear_get_description (int src_enum
) ;
130 int linear_set_converter (SRC_PRIVATE
*psrc
, int src_enum
) ;
133 const char* zoh_get_name (int src_enum
) ;
134 const char* zoh_get_description (int src_enum
) ;
136 int zoh_set_converter (SRC_PRIVATE
*psrc
, int src_enum
) ;
138 /*----------------------------------------------------------
139 ** Common static inline functions.
146 res
= x
- lrint (x
) ;
154 is_bad_src_ratio (double ratio
)
155 { return (ratio
< (1.0 / SRC_MAX_RATIO
) || ratio
> (1.0 * SRC_MAX_RATIO
)) ;
156 } /* is_bad_src_ratio */
159 #endif /* COMMON_H_INCLUDED */