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
1313
1414 list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
1515
16+set(CMAKE_C_STANDARD 99)
17+set(CMAKE_C_STANDARD_REQUIRED TRUE)
18+
1619 include(TestBigEndian)
1720 include(CheckFunctionExists)
1821 include(CheckIncludeFiles)
1922 include(CheckSymbolExists)
20−include(CheckTypeSize)
21−include(CMakePushCheckState)
2223 include(ClipMode)
2324 add_definitions(-DHAVE_CONFIG_H)
2425
@@ -43,35 +44,18 @@ else() · 18 unmodified lines
4344 set(CPU_IS_LITTLE_ENDIAN 1)
4445 endif()
4546
46−cmake_push_check_state(RESET)
47−
48−check_symbol_exists(pow math.h RESULT)
49−if(RESULT)
50− set(NEED_MATH OFF)
51−else()
52− set(NEED_MATH ON)
53− list(APPEND CMAKE_REQUIRED_LIBRARIES m)
54−endif()
55−check_symbol_exists(lrint math.h HAVE_LRINT)
56−check_symbol_exists(lrintf math.h HAVE_LRINTF)
47+find_library(LIBSAMPLERATE_MATH_LIBRARY m)
5748
5849 # This will set CPU_CLIPS_NEGATIVE and CPU_CLIPS_POSITIVE
59−# requires HAVE_LRINT being set
6050 clip_mode()
6151
62−cmake_pop_check_state()
63−
6452 check_function_exists(alarm HAVE_ALARM)
6553 check_function_exists(signal HAVE_SIGNAL)
6654
67−check_include_files(stdint.h HAVE_STDINT)
6855 check_include_files(sys/times.h HAVE_SYS_TIMES_H)
6956
7057 check_symbol_exists(SIGALRM signal.h HAVE_SIGALRM)
7158
72−check_type_size(int SIZEOF_INT)
73−check_type_size(long SIZEOF_LONG)
74−
7559 find_package(ALSA)
7660 set(HAVE_ALSA ${ALSA_FOUND})
7761 if(ALSA_FOUND)
@@ -106,8 +90,8 @@ target_include_directories(samplerate PUBLIC · 28 unmodified lines
10690 ${PROJECT_SOURCE_DIR}/src
10791 ${CMAKE_CURRENT_BINARY_DIR})
10892
109−if(NEED_MATH)
110− target_link_libraries(samplerate PUBLIC m)
93+if(LIBSAMPLERATE_MATH_LIBRARY)
94+ target_link_libraries(samplerate PUBLIC ${LIBSAMPLERATE_MATH_LIBRARY})
11195 endif()
11296
11397 if(LIBSAMPLERATE_TESTS)
@@ -162,7 +146,7 @@ if(LIBSAMPLERATE_INSTALL) · 48 unmodified lines
162146 set(includedir "\${prefix}/include")
163147 set(libdir "\${exec_prefix}/lib")
164148 set(VERSION "${PROJECT_VERSION}")
165− if(NEED_MATH)
149+ if(LIBSAMPLERATE_MATH_LIBRARY)
166150 set(LIBS "-lm")
167151 endif()
168152 configure_file(samplerate.pc.in samplerate.pc @ONLY)
Makefile.am+1−1
@@ -27,7 +27,7 @@ CLEANFILES = src/src_sinc.s · 26 unmodified lines
2727 # MinGW requires -no-undefined if a DLL is to be built.
2828 src_libsamplerate_la_LDFLAGS = -no-undefined -version-info $(SHARED_VERSION_INFO) $(SHLIB_VERSION_ARG)
2929 src_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 \
3131 src/src_config.h
3232
3333 #-------------------------------------------------------------------------------
cmake/ClipMode.cmake+10−3
@@ -1,5 +1,3 @@
1−include (CheckCSourceRuns)
2−
31 macro (CLIP_MODE)
42
53 set (CLIP_MODE_POSITIVE_MESSAGE "Target processor clips on positive float to int conversion")
@@ -7,13 +5,20 @@ macro (CLIP_MODE) · 1 unmodified line
75
86 message (STATUS "Checking processor clipping capabilities...")
97
10− if (CMAKE_CROSSCOMPILING OR NOT HAVE_LRINT)
8+ if (CMAKE_CROSSCOMPILING)
119
1210 set (CLIP_MSG "disabled")
1311 set (CPU_CLIPS_POSITIVE FALSE CACHE BOOL ${CLIP_MODE_POSITIVE_MESSAGE})
1412 set (CPU_CLIPS_NEGATIVE FALSE CACHE BOOL ${CLIP_MODE_NEGATIVE_MESSAGE})
1513
1614 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()
1722
1823 check_c_source_runs (
1924 "
@@ -57,6 +62,8 @@ macro (CLIP_MODE) · 37 unmodified lines
5762 "
5863 CPU_CLIPS_NEGATIVE)
5964
65+ cmake_pop_check_state()
66+
6067 if (CPU_CLIPS_POSITIVE AND CPU_CLIPS_NEGATIVE)
6168 set (CLIP_MSG "both")
6269 elseif (CPU_CLIPS_POSITIVE)
examples/audio_out.c+1−1
@@ -24,7 +24,7 @@ · 23 unmodified lines
2424
2525 #if (HAVE_SNDFILE)
2626
27−#include <float_cast.h>
27+#include <math.h>
2828
2929 #include <sndfile.h>
3030
examples/varispeed-play.c+1−2
@@ -10,11 +10,10 @@ · 9 unmodified lines
1010 #include <stdlib.h>
1111 #include <unistd.h>
1212 #include <string.h>
13+#include <math.h>
1314
1415 #include "src_config.h"
1516
16−#include <float_cast.h>
17−
1817 #if (HAVE_SNDFILE)
1918
2019 #include <samplerate.h>
src/common.h+0−6
@@ -9,13 +9,7 @@ · 8 unmodified lines
99 #ifndef COMMON_H_INCLUDED
1010 #define COMMON_H_INCLUDED
1111
12−#ifdef HAVE_STDINT_H
1312 #include <stdint.h>
14−#elif (SIZEOF_INT == 4)
15−typedef int int32_t ;
16−#elif (SIZEOF_LONG == 4)
17−typedef long int32_t ;
18−#endif
1913
2014 #include <math.h>
2115
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−
79−extern __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−
88−extern __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
99 #include <stdio.h>
1010 #include <stdlib.h>
1111 #include <string.h>
12+#include <math.h>
1213
1314 #include "src_config.h"
1415
1516 #include "samplerate.h"
16−#include "float_cast.h"
1717 #include "common.h"
1818
1919 static int psrc_set_converter (SRC_PRIVATE *psrc, int converter_type) ;
src/src_linear.c+1−1
@@ -9,9 +9,9 @@ · 8 unmodified lines
99 #include <stdio.h>
1010 #include <stdlib.h>
1111 #include <string.h>
12+#include <math.h>
1213
1314 #include "src_config.h"
14−#include "float_cast.h"
1515 #include "common.h"
1616
1717 static int linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
src/src_sinc.c+1−1
@@ -9,9 +9,9 @@ · 8 unmodified lines
99 #include <stdio.h>
1010 #include <stdlib.h>
1111 #include <string.h>
12+#include <math.h>
1213
1314 #include "src_config.h"
14−#include "float_cast.h"
1515 #include "common.h"
1616
1717 #define SINC_MAGIC_MARKER MAKE_MAGIC (' ', 's', 'i', 'n', 'c', ' ')
src/src_zoh.c+1−1
@@ -9,9 +9,9 @@ · 8 unmodified lines
99 #include <stdio.h>
1010 #include <stdlib.h>
1111 #include <string.h>
12+#include <math.h>
1213
1314 #include "src_config.h"
14−#include "float_cast.h"
1515 #include "common.h"
1616
1717 static int zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
tests/multichan_throughput_test.c+1−1
@@ -11,13 +11,13 @@ · 10 unmodified lines
1111 #include <string.h>
1212 #include <time.h>
1313 #include <unistd.h>
14+#include <math.h>
1415
1516 #include <samplerate.h>
1617
1718 #include "src_config.h"
1819
1920 #include "util.h"
20−#include "float_cast.h"
2121
2222 #define BUFFER_LEN (1<<17)
2323
tests/throughput_test.c+1−1
@@ -11,13 +11,13 @@ · 10 unmodified lines
1111 #include <string.h>
1212 #include <time.h>
1313 #include <unistd.h>
14+#include <math.h>
1415
1516 #include <samplerate.h>
1617
1718 #include "src_config.h"
1819
1920 #include "util.h"
20−#include "float_cast.h"
2121
2222 #define BUFFER_LEN (1<<16)
2323

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