History

Require C99 compiler

Already required for configure builds, now also for CMake builds. Simplifies some code as e.g. lrint and stdint.h are always available. Closes #77

Alexander Grund committed 7 years ago

Commit ab8b4821 parent 890276813 files · +26 −344Browse files

Unified · Split

13 files
  1. CMakeLists.txt +7 −23
  2. Makefile.am +1 −1
  3. cmake/ClipMode.cmake +10 −3
  4. examples/audio_out.c +1 −1
  5. examples/varispeed-play.c +1 −2
  6. src/common.h +0 −6
  7. src/float_cast.h +0 −302
  8. src/samplerate.c +1 −1
  9. src/src_linear.c +1 −1
  10. src/src_sinc.c +1 −1
  11. src/src_zoh.c +1 −1
  12. tests/multichan_throughput_test.c +1 −1
  13. tests/throughput_test.c +1 −1
CMakeLists.txt+7−23
@@ -13,12 +13,13 @@ option(LIBSAMPLERATE_INSTALL "Enable to add install directives" ${IS_ROOT_PROJEC · 12 unmodified lines
13 13
14list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)14list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
15 15
16set(CMAKE_C_STANDARD 99)
17set(CMAKE_C_STANDARD_REQUIRED TRUE)
18
16include(TestBigEndian)19include(TestBigEndian)
17include(CheckFunctionExists)20include(CheckFunctionExists)
18include(CheckIncludeFiles)21include(CheckIncludeFiles)
19include(CheckSymbolExists)22include(CheckSymbolExists)
20include(CheckTypeSize)
21include(CMakePushCheckState)
22include(ClipMode)23include(ClipMode)
23add_definitions(-DHAVE_CONFIG_H)24add_definitions(-DHAVE_CONFIG_H)
24 25
@@ -43,35 +44,18 @@ else() · 18 unmodified lines
43 set(CPU_IS_LITTLE_ENDIAN 1)44 set(CPU_IS_LITTLE_ENDIAN 1)
44endif()45endif()
45 46
46cmake_push_check_state(RESET)47find_library(LIBSAMPLERATE_MATH_LIBRARY m)
47
48check_symbol_exists(pow math.h RESULT)
49if(RESULT)
50 set(NEED_MATH OFF)
51else()
52 set(NEED_MATH ON)
53 list(APPEND CMAKE_REQUIRED_LIBRARIES m)
54endif()
55check_symbol_exists(lrint math.h HAVE_LRINT)
56check_symbol_exists(lrintf math.h HAVE_LRINTF)
57 48
58# This will set CPU_CLIPS_NEGATIVE and CPU_CLIPS_POSITIVE49# This will set CPU_CLIPS_NEGATIVE and CPU_CLIPS_POSITIVE
59# requires HAVE_LRINT being set
60clip_mode()50clip_mode()
61 51
62cmake_pop_check_state()
63
64check_function_exists(alarm HAVE_ALARM)52check_function_exists(alarm HAVE_ALARM)
65check_function_exists(signal HAVE_SIGNAL)53check_function_exists(signal HAVE_SIGNAL)
66 54
67check_include_files(stdint.h HAVE_STDINT)
68check_include_files(sys/times.h HAVE_SYS_TIMES_H)55check_include_files(sys/times.h HAVE_SYS_TIMES_H)
69 56
70check_symbol_exists(SIGALRM signal.h HAVE_SIGALRM)57check_symbol_exists(SIGALRM signal.h HAVE_SIGALRM)
71 58
72check_type_size(int SIZEOF_INT)
73check_type_size(long SIZEOF_LONG)
74
75find_package(ALSA)59find_package(ALSA)
76set(HAVE_ALSA ${ALSA_FOUND})60set(HAVE_ALSA ${ALSA_FOUND})
77if(ALSA_FOUND)61if(ALSA_FOUND)
@@ -106,8 +90,8 @@ target_include_directories(samplerate PUBLIC · 28 unmodified lines
106 ${PROJECT_SOURCE_DIR}/src90 ${PROJECT_SOURCE_DIR}/src
107 ${CMAKE_CURRENT_BINARY_DIR})91 ${CMAKE_CURRENT_BINARY_DIR})
108 92
109if(NEED_MATH)93if(LIBSAMPLERATE_MATH_LIBRARY)
110 target_link_libraries(samplerate PUBLIC m)94 target_link_libraries(samplerate PUBLIC ${LIBSAMPLERATE_MATH_LIBRARY})
111endif()95endif()
112 96
113if(LIBSAMPLERATE_TESTS)97if(LIBSAMPLERATE_TESTS)
@@ -162,7 +146,7 @@ if(LIBSAMPLERATE_INSTALL) · 48 unmodified lines
162 set(includedir "\${prefix}/include")146 set(includedir "\${prefix}/include")
163 set(libdir "\${exec_prefix}/lib")147 set(libdir "\${exec_prefix}/lib")
164 set(VERSION "${PROJECT_VERSION}")148 set(VERSION "${PROJECT_VERSION}")
165 if(NEED_MATH)149 if(LIBSAMPLERATE_MATH_LIBRARY)
166 set(LIBS "-lm")150 set(LIBS "-lm")
167 endif()151 endif()
168 configure_file(samplerate.pc.in samplerate.pc @ONLY)152 configure_file(samplerate.pc.in samplerate.pc @ONLY)
Makefile.am+1−1
@@ -27,7 +27,7 @@ CLEANFILES = src/src_sinc.s · 26 unmodified lines
27# MinGW requires -no-undefined if a DLL is to be built.27# MinGW requires -no-undefined if a DLL is to be built.
28src_libsamplerate_la_LDFLAGS = -no-undefined -version-info $(SHARED_VERSION_INFO) $(SHLIB_VERSION_ARG)28src_libsamplerate_la_LDFLAGS = -no-undefined -version-info $(SHARED_VERSION_INFO) $(SHLIB_VERSION_ARG)
29src_libsamplerate_la_SOURCES = src/samplerate.c src/src_sinc.c src/src_zoh.c src/src_linear.c \29src_libsamplerate_la_SOURCES = src/samplerate.c src/src_sinc.c src/src_zoh.c src/src_linear.c \
30 src/common.h src/float_cast.h src/fastest_coeffs.h src/mid_qual_coeffs.h src/high_qual_coeffs.h \30 src/common.h src/fastest_coeffs.h src/mid_qual_coeffs.h src/high_qual_coeffs.h \
31 src/src_config.h31 src/src_config.h
32 32
33#-------------------------------------------------------------------------------33#-------------------------------------------------------------------------------
cmake/ClipMode.cmake+10−3
@@ -1,5 +1,3 @@
1include (CheckCSourceRuns)
2
3macro (CLIP_MODE)1macro (CLIP_MODE)
4 2
5 set (CLIP_MODE_POSITIVE_MESSAGE "Target processor clips on positive float to int conversion")3 set (CLIP_MODE_POSITIVE_MESSAGE "Target processor clips on positive float to int conversion")
@@ -7,13 +5,20 @@ macro (CLIP_MODE) · 1 unmodified line
7 5
8 message (STATUS "Checking processor clipping capabilities...")6 message (STATUS "Checking processor clipping capabilities...")
9 7
10 if (CMAKE_CROSSCOMPILING OR NOT HAVE_LRINT)8 if (CMAKE_CROSSCOMPILING)
11 9
12 set (CLIP_MSG "disabled")10 set (CLIP_MSG "disabled")
13 set (CPU_CLIPS_POSITIVE FALSE CACHE BOOL ${CLIP_MODE_POSITIVE_MESSAGE})11 set (CPU_CLIPS_POSITIVE FALSE CACHE BOOL ${CLIP_MODE_POSITIVE_MESSAGE})
14 set (CPU_CLIPS_NEGATIVE FALSE CACHE BOOL ${CLIP_MODE_NEGATIVE_MESSAGE})12 set (CPU_CLIPS_NEGATIVE FALSE CACHE BOOL ${CLIP_MODE_NEGATIVE_MESSAGE})
15 13
16 else ()14 else ()
15 include(CheckCSourceRuns)
16 include(CMakePushCheckState)
17 cmake_push_check_state(RESET)
18
19 if(LIBSAMPLERATE_MATH_LIBRARY)
20 list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBSAMPLERATE_MATH_LIBRARY})
21 endif()
17 22
18 check_c_source_runs (23 check_c_source_runs (
19 "24 "
@@ -57,6 +62,8 @@ macro (CLIP_MODE) · 37 unmodified lines
57 "62 "
58 CPU_CLIPS_NEGATIVE)63 CPU_CLIPS_NEGATIVE)
59 64
65 cmake_pop_check_state()
66
60 if (CPU_CLIPS_POSITIVE AND CPU_CLIPS_NEGATIVE)67 if (CPU_CLIPS_POSITIVE AND CPU_CLIPS_NEGATIVE)
61 set (CLIP_MSG "both")68 set (CLIP_MSG "both")
62 elseif (CPU_CLIPS_POSITIVE)69 elseif (CPU_CLIPS_POSITIVE)
examples/audio_out.c+1−1
@@ -24,7 +24,7 @@ · 23 unmodified lines
24 24
25#if (HAVE_SNDFILE)25#if (HAVE_SNDFILE)
26 26
27#include <float_cast.h>27#include <math.h>
28 28
29#include <sndfile.h>29#include <sndfile.h>
30 30
examples/varispeed-play.c+1−2
@@ -10,11 +10,10 @@ · 9 unmodified lines
10#include <stdlib.h>10#include <stdlib.h>
11#include <unistd.h>11#include <unistd.h>
12#include <string.h>12#include <string.h>
13#include <math.h>
13 14
14#include "src_config.h"15#include "src_config.h"
15 16
16#include <float_cast.h>
17
18#if (HAVE_SNDFILE)17#if (HAVE_SNDFILE)
19 18
20#include <samplerate.h>19#include <samplerate.h>
src/common.h+0−6
@@ -9,13 +9,7 @@ · 8 unmodified lines
9#ifndef COMMON_H_INCLUDED9#ifndef COMMON_H_INCLUDED
10#define COMMON_H_INCLUDED10#define COMMON_H_INCLUDED
11 11
12#ifdef HAVE_STDINT_H
13#include <stdint.h>12#include <stdint.h>
14#elif (SIZEOF_INT == 4)
15typedef int int32_t ;
16#elif (SIZEOF_LONG == 4)
17typedef long int32_t ;
18#endif
19 13
20#include <math.h>14#include <math.h>
21 15
src/float_cast.h+0−302
@@ -1,302 +0,0 @@
1/*
2** Copyright (c) 2001-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/* Version 1.5 */
10
11#ifndef FLOAT_CAST_HEADER
12#define FLOAT_CAST_HEADER
13
14/*============================================================================
15** On Intel Pentium processors (especially PIII and probably P4), converting
16** from float to int is very slow. To meet the C specs, the code produced by
17** most C compilers targeting Pentium needs to change the FPU rounding mode
18** before the float to int conversion is performed.
19**
20** Changing the FPU rounding mode causes the FPU pipeline to be flushed. It
21** is this flushing of the pipeline which is so slow.
22**
23** Fortunately the ISO C99 specifications define the functions lrint, lrintf,
24** llrint and llrintf which fix this problem as a side effect.
25**
26** On Unix-like systems, the configure process should have detected the
27** presence of these functions. If they weren't found we have to replace them
28** here with a standard C cast.
29*/
30
31/*
32** The C99 prototypes for lrint and lrintf are as follows:
33**
34** long int lrintf (float x) ;
35** long int lrint (double x) ;
36*/
37
38#include "src_config.h"
39
40/*
41** The presence of the required functions are detected during the configure
42** process and the values HAVE_LRINT and HAVE_LRINTF are set accordingly in
43** the config.h file.
44*/
45
46#define HAVE_LRINT_REPLACEMENT 0
47
48#if (HAVE_LRINT && HAVE_LRINTF)
49
50 /*
51 ** These defines enable functionality introduced with the 1999 ISO C
52 ** standard. They must be defined before the inclusion of math.h to
53 ** engage them. If optimisation is enabled, these functions will be
54 ** inlined. With optimisation switched off, you have to link in the
55 ** maths library using -lm.
56 */
57
58 #define _ISOC9X_SOURCE 1
59 #define _ISOC99_SOURCE 1
60
61 #define __USE_ISOC9X 1
62 #define __USE_ISOC99 1
63
64 #include <math.h>
65
66#elif (defined (__WATCOMC__) && defined(__386__))
67
68 #include <math.h>
69
70 #undef HAVE_LRINT_REPLACEMENT
71 #define HAVE_LRINT_REPLACEMENT 1
72
73 #undef lrint
74 #undef lrintf
75
76 #define lrint double2int
77 #define lrintf float2int
78
79extern __inline long double2int(double);
80#pragma aux double2int = \
81 "push eax" \
82 "fistp dword ptr [esp]" \
83 "pop eax" \
84 parm [8087] \
85 value [eax] \
86 modify exact [eax];
87
88extern __inline long float2int(float);
89#pragma aux float2int = \
90 "push eax" \
91 "fistp dword ptr [esp]" \
92 "pop eax" \
93 parm [8087] \
94 value [eax] \
95 modify exact [eax];
96
97#elif (defined (__CYGWIN__))
98
99 #include <math.h>
100
101 #undef HAVE_LRINT_REPLACEMENT
102 #define HAVE_LRINT_REPLACEMENT 1
103
104 #undef lrint
105 #undef lrintf
106
107 #define lrint double2int
108 #define lrintf float2int
109
110 /*
111 ** The native CYGWIN lrint and lrintf functions are buggy:
112 ** http://sourceware.org/ml/cygwin/2005-06/msg00153.html
113 ** http://sourceware.org/ml/cygwin/2005-09/msg00047.html
114 ** and slow.
115 ** These functions (pulled from the Public Domain MinGW math.h header)
116 ** replace the native versions.
117 */
118
119 static inline long double2int (double in)
120 { long retval ;
121
122 __asm__ __volatile__
123 ( "fistpl %0"
124 : "=m" (retval)
125 : "t" (in)
126 : "st"
127 ) ;
128
129 return retval ;
130 } /* double2int */
131
132 static inline long float2int (float in)
133 { long retval ;
134
135 __asm__ __volatile__
136 ( "fistpl %0"
137 : "=m" (retval)
138 : "t" (in)
139 : "st"
140 ) ;
141
142 return retval ;
143 } /* float2int */
144
145#elif (defined (WIN64) || defined(_WIN64))
146
147 /* Win64 section should be places before Win32 one, because
148 ** most likely both WIN32 and WIN64 will be defined in 64-bit case.
149 */
150
151 #include <math.h>
152
153 /* Win64 doesn't seem to have these functions, nor inline assembly.
154 ** Therefore implement inline versions of these functions here.
155 */
156 #include <emmintrin.h>
157 #include <mmintrin.h>
158
159 __inline long int
160 lrint(double flt)
161 {
162 return _mm_cvtsd_si32(_mm_load_sd(&flt));
163 }
164
165 __inline long int
166 lrintf(float flt)
167 {
168 return _mm_cvtss_si32(_mm_load_ss(&flt));
169 }
170
171#elif (defined (WIN32) || defined (_WIN32))
172
173 #undef HAVE_LRINT_REPLACEMENT
174 #define HAVE_LRINT_REPLACEMENT 1
175
176 #include <math.h>
177
178 /*
179 ** Win32 doesn't seem to have these functions.
180 ** Therefore implement inline versions of these functions here.
181 */
182
183 __inline long int
184 lrint (double flt)
185 { int intgr ;
186
187 _asm
188 { fld flt
189 fistp intgr
190 } ;
191
192 return intgr ;
193 }
194
195 __inline long int
196 lrintf (float flt)
197 { int intgr ;
198
199 _asm
200 { fld flt
201 fistp intgr
202 } ;
203
204 return intgr ;
205 }
206
207#elif (defined (__MWERKS__) && defined (macintosh))
208
209 /* This MacOS 9 solution was provided by Stephane Letz */
210
211 #undef HAVE_LRINT_REPLACEMENT
212 #define HAVE_LRINT_REPLACEMENT 1
213 #include <math.h>
214
215 #undef lrint
216 #undef lrintf
217
218 #define lrint double2int
219 #define lrintf float2int
220
221 inline int
222 float2int (register float in)
223 { long res [2] ;
224
225 asm
226 { fctiw in, in
227 stfd in, res
228 }
229 return res [1] ;
230 } /* float2int */
231
232 inline int
233 double2int (register double in)
234 { long res [2] ;
235
236 asm
237 { fctiw in, in
238 stfd in, res
239 }
240 return res [1] ;
241 } /* double2int */
242
243#elif (defined (__MACH__) && defined (__APPLE__))
244
245 /* For Apple MacOSX. */
246
247 #undef HAVE_LRINT_REPLACEMENT
248 #define HAVE_LRINT_REPLACEMENT 1
249 #include <math.h>
250
251 #undef lrint
252 #undef lrintf
253
254 #define lrint double2int
255 #define lrintf float2int
256
257 inline static long
258 float2int (register float in)
259 { int res [2] ;
260
261 __asm__ __volatile__
262 ( "fctiw %1, %1\n\t"
263 "stfd %1, %0"
264 : "=m" (res) /* Output */
265 : "f" (in) /* Input */
266 : "memory"
267 ) ;
268
269 return res [1] ;
270 } /* lrintf */
271
272 inline static long
273 double2int (register double in)
274 { int res [2] ;
275
276 __asm__ __volatile__
277 ( "fctiw %1, %1\n\t"
278 "stfd %1, %0"
279 : "=m" (res) /* Output */
280 : "f" (in) /* Input */
281 : "memory"
282 ) ;
283
284 return res [1] ;
285 } /* lrint */
286
287#else
288 #ifndef __sgi
289 #warning "Don't have the functions lrint() and lrintf()."
290 #warning "Replacing these functions with a standard C cast."
291 #endif
292
293 #include <math.h>
294
295 #define lrint(dbl) ((long) (dbl))
296 #define lrintf(flt) ((long) (flt))
297
298#endif
299
300
301#endif /* FLOAT_CAST_HEADER */
302
src/samplerate.c+1−1
@@ -9,11 +9,11 @@ · 8 unmodified lines
9#include <stdio.h>9#include <stdio.h>
10#include <stdlib.h>10#include <stdlib.h>
11#include <string.h>11#include <string.h>
12#include <math.h>
12 13
13#include "src_config.h"14#include "src_config.h"
14 15
15#include "samplerate.h"16#include "samplerate.h"
16#include "float_cast.h"
17#include "common.h"17#include "common.h"
18 18
19static int psrc_set_converter (SRC_PRIVATE *psrc, int converter_type) ;19static int psrc_set_converter (SRC_PRIVATE *psrc, int converter_type) ;
src/src_linear.c+1−1
@@ -9,9 +9,9 @@ · 8 unmodified lines
9#include <stdio.h>9#include <stdio.h>
10#include <stdlib.h>10#include <stdlib.h>
11#include <string.h>11#include <string.h>
12#include <math.h>
12 13
13#include "src_config.h"14#include "src_config.h"
14#include "float_cast.h"
15#include "common.h"15#include "common.h"
16 16
17static int linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;17static int linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
src/src_sinc.c+1−1
@@ -9,9 +9,9 @@ · 8 unmodified lines
9#include <stdio.h>9#include <stdio.h>
10#include <stdlib.h>10#include <stdlib.h>
11#include <string.h>11#include <string.h>
12#include <math.h>
12 13
13#include "src_config.h"14#include "src_config.h"
14#include "float_cast.h"
15#include "common.h"15#include "common.h"
16 16
17#define SINC_MAGIC_MARKER MAKE_MAGIC (' ', 's', 'i', 'n', 'c', ' ')17#define SINC_MAGIC_MARKER MAKE_MAGIC (' ', 's', 'i', 'n', 'c', ' ')
src/src_zoh.c+1−1
@@ -9,9 +9,9 @@ · 8 unmodified lines
9#include <stdio.h>9#include <stdio.h>
10#include <stdlib.h>10#include <stdlib.h>
11#include <string.h>11#include <string.h>
12#include <math.h>
12 13
13#include "src_config.h"14#include "src_config.h"
14#include "float_cast.h"
15#include "common.h"15#include "common.h"
16 16
17static int zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;17static int zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
tests/multichan_throughput_test.c+1−1
@@ -11,13 +11,13 @@ · 10 unmodified lines
11#include <string.h>11#include <string.h>
12#include <time.h>12#include <time.h>
13#include <unistd.h>13#include <unistd.h>
14#include <math.h>
14 15
15#include <samplerate.h>16#include <samplerate.h>
16 17
17#include "src_config.h"18#include "src_config.h"
18 19
19#include "util.h"20#include "util.h"
20#include "float_cast.h"
21 21
22#define BUFFER_LEN (1<<17)22#define BUFFER_LEN (1<<17)
23 23
tests/throughput_test.c+1−1
@@ -11,13 +11,13 @@ · 10 unmodified lines
11#include <string.h>11#include <string.h>
12#include <time.h>12#include <time.h>
13#include <unistd.h>13#include <unistd.h>
14#include <math.h>
14 15
15#include <samplerate.h>16#include <samplerate.h>
16 17
17#include "src_config.h"18#include "src_config.h"
18 19
19#include "util.h"20#include "util.h"
20#include "float_cast.h"
21 21
22#define BUFFER_LEN (1<<16)22#define BUFFER_LEN (1<<16)
23 23

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t