11/*
2- ** Copyright (c) 2002-2021 , Erik de Castro Lopo <[email protected] > 2+ ** Copyright (c) 2002-2016 , Erik de Castro Lopo <[email protected] > 33** All rights reserved.
44**
55** This code is released under 2-clause BSD license. Please see the
6- ** file at : https://github.com/libsndfile /libsamplerate/blob/master/COPYING
6+ ** file at : https://github.com/erikd /libsamplerate/blob/master/COPYING
77*/
88
99#ifndef COMMON_H_INCLUDED
1010#define COMMON_H_INCLUDED
1111
1212#include <stdint.h>
13- #ifdef HAVE_STDBOOL_H
14- #include <stdbool.h>
15- #endif
16-
17- #if defined(__x86_64__ ) || defined(_M_X64 )
18- # define HAVE_SSE2_INTRINSICS
19- #elif defined(ENABLE_SSE2_LRINT ) && (defined(_M_IX86 ) || defined(__i386__ ))
20- # if defined(_MSC_VER )
21- # define HAVE_SSE2_INTRINSICS
22- # elif defined(__clang__ )
23- # ifdef __SSE2__
24- # define HAVE_SSE2_INTRINSICS
25- # elif (__has_attribute (target ))
26- # define HAVE_SSE2_INTRINSICS
27- # define USE_TARGET_ATTRIBUTE
28- # endif
29- # elif defined(__GNUC__ )
30- # ifdef __SSE2__
31- # define HAVE_SSE2_INTRINSICS
32- # elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9 ))
33- # define HAVE_SSE2_INTRINSICS
34- # define USE_TARGET_ATTRIBUTE
35- # endif
36- # endif
37- #endif
38-
39- #ifdef HAVE_SSE2_INTRINSICS
40- #ifdef HAVE_IMMINTRIN_H
41- #include <immintrin.h>
42- #else
43- #include <emmintrin.h>
44- #endif
45- #endif /* HAVE_SSE2_INTRINSICS */
4613
4714#include <math.h>
4815
49- #ifdef HAVE_VISIBILITY
50- #define LIBSAMPLERATE_DLL_PRIVATE __attribute__ ((visibility ("hidden")))
51- #elif defined (__APPLE__ )
52- #define LIBSAMPLERATE_DLL_PRIVATE __private_extern__
53- #else
54- #define LIBSAMPLERATE_DLL_PRIVATE
55- #endif
56-
5716#define SRC_MAX_RATIO 256
5817#define SRC_MAX_RATIO_STR "256"
5918
7130
7231#define MAKE_MAGIC (a ,b ,c ,d ,e ,f ) ((a) + ((b) << 4) + ((c) << 8) + ((d) << 12) + ((e) << 16) + ((f) << 20))
7332
33+ /*
34+ ** Adds casting needed if compiled/included within cpp
35+ */
36+ #ifdef __cplusplus
37+ #define ZERO_ALLOC (type , size ) static_cast<type*>(calloc(1, size))
38+ #else // __cplusplus
39+ #define ZERO_ALLOC (type , size ) calloc(1, size)
40+ #endif
41+
7442/*
7543** Inspiration : http://sourcefrog.net/weblog/software/languages/C/unused.html
7644*/
9462enum
9563{ SRC_FALSE = 0 ,
9664 SRC_TRUE = 1 ,
97- } ;
9865
99- enum SRC_MODE
100- {
101- SRC_MODE_PROCESS = 0 ,
102- SRC_MODE_CALLBACK = 1
66+ SRC_MODE_PROCESS = 555 ,
67+ SRC_MODE_CALLBACK = 556
10368} ;
10469
105- typedef enum SRC_ERROR
106- {
107- SRC_ERR_NO_ERROR = 0 ,
70+ enum
71+ { SRC_ERR_NO_ERROR = 0 ,
10872
10973 SRC_ERR_MALLOC_FAILED ,
11074 SRC_ERR_BAD_STATE ,
@@ -131,95 +95,40 @@ typedef enum SRC_ERROR
13195
13296 /* This must be the last error number. */
13397 SRC_ERR_MAX_ERROR
134- } SRC_ERROR ;
98+ } ;
13599
136- typedef struct SRC_STATE_VT_tag
137- {
138- /* Varispeed process function. */
139- SRC_ERROR (* vari_process ) (SRC_STATE * state , SRC_DATA * data ) ;
100+ typedef struct SRC_PRIVATE_tag
101+ { double last_ratio , last_position ;
140102
141- /* Constant speed process function. */
142- SRC_ERROR (* const_process ) (SRC_STATE * state , SRC_DATA * data ) ;
143-
144- /* State reset. */
145- void (* reset ) (SRC_STATE * state ) ;
103+ int error ;
104+ int channels ;
146105
147- /* State clone. */
148- SRC_STATE * ( * copy ) ( SRC_STATE * state ) ;
106+ /* SRC_MODE_PROCESS or SRC_MODE_CALLBACK */
107+ int mode ;
149108
150- /* State close. */
151- void (* close ) (SRC_STATE * state ) ;
152- } SRC_STATE_VT ;
109+ /* Pointer to data to converter specific data. */
110+ void * private_data ;
153111
154- struct SRC_STATE_tag
155- {
156- SRC_STATE_VT * vt ;
112+ /* Varispeed process function. */
113+ int (* vari_process ) (struct SRC_PRIVATE_tag * psrc , SRC_DATA * data ) ;
157114
158- double last_ratio , last_position ;
115+ /* Constant speed process function. */
116+ int (* const_process ) (struct SRC_PRIVATE_tag * psrc , SRC_DATA * data ) ;
159117
160- SRC_ERROR error ;
161- int channels ;
118+ /* State reset. */
119+ void ( * reset ) ( struct SRC_PRIVATE_tag * psrc ) ;
162120
163- /* SRC_MODE_PROCESS or SRC_MODE_CALLBACK */
164- enum SRC_MODE mode ;
121+ /* State clone. */
122+ int ( * copy ) ( struct SRC_PRIVATE_tag * from , struct SRC_PRIVATE_tag * to ) ;
165123
166124 /* Data specific to SRC_MODE_CALLBACK. */
167125 src_callback_t callback_func ;
168126 void * user_callback_data ;
169127 long saved_frames ;
170128 const float * saved_data ;
129+ } SRC_PRIVATE ;
171130
172- /* Pointer to data to converter specific data. */
173- void * private_data ;
174- } ;
175-
176- /* In src_sinc.c */
177- const char * sinc_get_name (int src_enum ) ;
178- const char * sinc_get_description (int src_enum ) ;
179-
180- SRC_STATE * sinc_state_new (int converter_type , int channels , SRC_ERROR * error ) ;
181-
182- /* In src_linear.c */
183- const char * linear_get_name (int src_enum ) ;
184- const char * linear_get_description (int src_enum ) ;
185-
186- SRC_STATE * linear_state_new (int channels , SRC_ERROR * error ) ;
187-
188- /*----------------------------------------------------------
189- ** SIMD optimized math functions.
190- */
191-
192- #ifdef HAVE_SSE2_INTRINSICS
193- static inline int
194- #ifdef USE_TARGET_ATTRIBUTE
195- __attribute__((target ("sse2" )))
196- #endif
197- psf_lrintf (float x )
198- {
199- return _mm_cvtss_si32 (_mm_load_ss (& x )) ;
200- }
201- static inline int
202- #ifdef USE_TARGET_ATTRIBUTE
203- __attribute__((target ("sse2" )))
204- #endif
205- psf_lrint (double x )
206- {
207- return _mm_cvtsd_si32 (_mm_load_sd (& x )) ;
208- }
209-
210- #else
211-
212- static inline int psf_lrintf (float x )
213- {
214- return lrintf (x ) ;
215- } /* psf_lrintf */
216-
217- static inline int psf_lrint (double x )
218- {
219- return lrint (x ) ;
220- } /* psf_lrint */
221- #endif
222-
131+ int sinc_set_converter (SRC_PRIVATE * psrc );
223132/*----------------------------------------------------------
224133** Common static inline functions.
225134*/
@@ -228,7 +137,7 @@ static inline double
228137fmod_one (double x )
229138{ double res ;
230139
231- res = x - psf_lrint (x ) ;
140+ res = x - lrint (x ) ;
232141 if (res < 0.0 )
233142 return res + 1.0 ;
234143
@@ -241,5 +150,4 @@ is_bad_src_ratio (double ratio)
241150} /* is_bad_src_ratio */
242151
243152
244- #endif /* COMMON_H_INCLUDED */
245-
153+ #endif /* COMMON_H_INCLUDED */
0 commit comments