shithub: libsamplerate

Download patch

ref: ab8b482def718b2fbaadb7c7b49d745d499659e9
parent: 89027689b10428a4bac3b593915b7e0f71116d5f
author: Alexander Grund <alexander.grund@tu-dresden.de>
date: Mon Jul 29 12:56:47 EDT 2019

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

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,12 +13,13 @@
 
 list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
 
+set(CMAKE_C_STANDARD 99)
+set(CMAKE_C_STANDARD_REQUIRED TRUE)
+
 include(TestBigEndian)
 include(CheckFunctionExists)
 include(CheckIncludeFiles)
 include(CheckSymbolExists)
-include(CheckTypeSize)
-include(CMakePushCheckState)
 include(ClipMode)
 add_definitions(-DHAVE_CONFIG_H)
 
@@ -43,35 +44,18 @@
 	set(CPU_IS_LITTLE_ENDIAN 1)
 endif()
 
-cmake_push_check_state(RESET)
+find_library(LIBSAMPLERATE_MATH_LIBRARY m)
 
-check_symbol_exists(pow math.h RESULT)
-if(RESULT)
-    set(NEED_MATH OFF)
-else()
-    set(NEED_MATH ON)
-  list(APPEND CMAKE_REQUIRED_LIBRARIES m)
-endif()
-check_symbol_exists(lrint math.h HAVE_LRINT)
-check_symbol_exists(lrintf math.h HAVE_LRINTF)
-
 # This will set CPU_CLIPS_NEGATIVE and CPU_CLIPS_POSITIVE
-# requires HAVE_LRINT being set
 clip_mode()
 
-cmake_pop_check_state()
-
 check_function_exists(alarm HAVE_ALARM)
 check_function_exists(signal HAVE_SIGNAL)
 
-check_include_files(stdint.h HAVE_STDINT)
 check_include_files(sys/times.h HAVE_SYS_TIMES_H)
 
 check_symbol_exists(SIGALRM signal.h HAVE_SIGALRM)
 
-check_type_size(int SIZEOF_INT)
-check_type_size(long SIZEOF_LONG)
-
 find_package(ALSA)
 set(HAVE_ALSA ${ALSA_FOUND})
 if(ALSA_FOUND)
@@ -106,8 +90,8 @@
 	${PROJECT_SOURCE_DIR}/src
   ${CMAKE_CURRENT_BINARY_DIR})
 
-if(NEED_MATH)
-    target_link_libraries(samplerate PUBLIC m)
+if(LIBSAMPLERATE_MATH_LIBRARY)
+    target_link_libraries(samplerate PUBLIC ${LIBSAMPLERATE_MATH_LIBRARY})
 endif()
     
 if(LIBSAMPLERATE_TESTS)
@@ -162,7 +146,7 @@
 	set(includedir "\${prefix}/include")
 	set(libdir "\${exec_prefix}/lib")
 	set(VERSION "${PROJECT_VERSION}")
-	if(NEED_MATH)
+	if(LIBSAMPLERATE_MATH_LIBRARY)
 		set(LIBS "-lm")
 	endif()
 	configure_file(samplerate.pc.in samplerate.pc @ONLY)
--- a/Makefile.am
+++ b/Makefile.am
@@ -27,7 +27,7 @@
 # MinGW requires -no-undefined if a DLL is to be built.
 src_libsamplerate_la_LDFLAGS = -no-undefined -version-info $(SHARED_VERSION_INFO) $(SHLIB_VERSION_ARG)
 src_libsamplerate_la_SOURCES = src/samplerate.c src/src_sinc.c src/src_zoh.c src/src_linear.c \
-	src/common.h src/float_cast.h src/fastest_coeffs.h src/mid_qual_coeffs.h src/high_qual_coeffs.h \
+	src/common.h src/fastest_coeffs.h src/mid_qual_coeffs.h src/high_qual_coeffs.h \
 	src/src_config.h
 
 #-------------------------------------------------------------------------------
--- a/cmake/ClipMode.cmake
+++ b/cmake/ClipMode.cmake
@@ -1,5 +1,3 @@
-include (CheckCSourceRuns)
-
 macro (CLIP_MODE)
 
     set (CLIP_MODE_POSITIVE_MESSAGE "Target processor clips on positive float to int conversion")
@@ -7,7 +5,7 @@
 
     message (STATUS "Checking processor clipping capabilities...")
 
-    if (CMAKE_CROSSCOMPILING OR NOT HAVE_LRINT)
+    if (CMAKE_CROSSCOMPILING)
 
         set (CLIP_MSG "disabled")
         set (CPU_CLIPS_POSITIVE FALSE CACHE BOOL ${CLIP_MODE_POSITIVE_MESSAGE})
@@ -14,7 +12,14 @@
         set (CPU_CLIPS_NEGATIVE FALSE CACHE BOOL ${CLIP_MODE_NEGATIVE_MESSAGE})
 
     else ()
+        include(CheckCSourceRuns)
+        include(CMakePushCheckState)
+        cmake_push_check_state(RESET)
 
+        if(LIBSAMPLERATE_MATH_LIBRARY)
+            list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBSAMPLERATE_MATH_LIBRARY})
+        endif()
+
         check_c_source_runs (
         "
         #include <math.h>
@@ -56,6 +61,8 @@
             }
         "
         CPU_CLIPS_NEGATIVE)
+
+        cmake_pop_check_state()
 
         if (CPU_CLIPS_POSITIVE AND CPU_CLIPS_NEGATIVE)
             set (CLIP_MSG "both")
--- a/examples/audio_out.c
+++ b/examples/audio_out.c
@@ -24,7 +24,7 @@
 
 #if (HAVE_SNDFILE)
 
-#include <float_cast.h>
+#include <math.h>
 
 #include <sndfile.h>
 
--- a/examples/varispeed-play.c
+++ b/examples/varispeed-play.c
@@ -10,10 +10,9 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#include <math.h>
 
 #include "src_config.h"
-
-#include <float_cast.h>
 
 #if (HAVE_SNDFILE)
 
--- a/src/common.h
+++ b/src/common.h
@@ -9,13 +9,7 @@
 #ifndef COMMON_H_INCLUDED
 #define COMMON_H_INCLUDED
 
-#ifdef HAVE_STDINT_H
 #include <stdint.h>
-#elif (SIZEOF_INT == 4)
-typedef	int		int32_t ;
-#elif (SIZEOF_LONG == 4)
-typedef	long	int32_t ;
-#endif
 
 #include <math.h>
 
--- a/src/float_cast.h
+++ /dev/null
@@ -1,302 +1,0 @@
-/*
-** Copyright (c) 2001-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
-** All rights reserved.
-**
-** This code is released under 2-clause BSD license. Please see the
-** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
-*/
-
-/* Version 1.5 */
-
-#ifndef FLOAT_CAST_HEADER
-#define FLOAT_CAST_HEADER
-
-/*============================================================================
-**	On Intel Pentium processors (especially PIII and probably P4), converting
-**	from float to int is very slow. To meet the C specs, the code produced by
-**	most C compilers targeting Pentium needs to change the FPU rounding mode
-**	before the float to int conversion is performed.
-**
-**	Changing the FPU rounding mode causes the FPU pipeline to be flushed. It
-**	is this flushing of the pipeline which is so slow.
-**
-**	Fortunately the ISO C99 specifications define the functions lrint, lrintf,
-**	llrint and llrintf which fix this problem as a side effect.
-**
-**	On Unix-like systems, the configure process should have detected the
-**	presence of these functions. If they weren't found we have to replace them
-**	here with a standard C cast.
-*/
-
-/*
-**	The C99 prototypes for lrint and lrintf are as follows:
-**
-**		long int lrintf (float x) ;
-**		long int lrint  (double x) ;
-*/
-
-#include "src_config.h"
-
-/*
-**	The presence of the required functions are detected during the configure
-**	process and the values HAVE_LRINT and HAVE_LRINTF are set accordingly in
-**	the config.h file.
-*/
-
-#define		HAVE_LRINT_REPLACEMENT	0
-
-#if (HAVE_LRINT && HAVE_LRINTF)
-
-	/*
-	**	These defines enable functionality introduced with the 1999 ISO C
-	**	standard. They must be defined before the inclusion of math.h to
-	**	engage them. If optimisation is enabled, these functions will be
-	**	inlined. With optimisation switched off, you have to link in the
-	**	maths library using -lm.
-	*/
-
-	#define	_ISOC9X_SOURCE	1
-	#define _ISOC99_SOURCE	1
-
-	#define	__USE_ISOC9X	1
-	#define	__USE_ISOC99	1
-
-	#include	<math.h>
-
-#elif (defined (__WATCOMC__) && defined(__386__))
-
-	#include	<math.h>
-
-	#undef		HAVE_LRINT_REPLACEMENT
-	#define		HAVE_LRINT_REPLACEMENT	1
-
-	#undef	lrint
-	#undef	lrintf
-
-	#define	lrint	double2int
-	#define	lrintf	float2int
-
-extern __inline long double2int(double);
-#pragma aux double2int = \
-    "push  eax" \
-    "fistp dword ptr [esp]" \
-    "pop   eax" \
-    parm [8087] \
-    value [eax] \
-    modify exact [eax];
-
-extern __inline long float2int(float);
-#pragma aux float2int = \
-    "push  eax" \
-    "fistp dword ptr [esp]" \
-    "pop   eax" \
-    parm [8087] \
-    value [eax] \
-    modify exact [eax];
-
-#elif (defined (__CYGWIN__))
-
-	#include	<math.h>
-
-	#undef		HAVE_LRINT_REPLACEMENT
-	#define		HAVE_LRINT_REPLACEMENT	1
-
-	#undef	lrint
-	#undef	lrintf
-
-	#define	lrint	double2int
-	#define	lrintf	float2int
-
-	/*
-	**	The native CYGWIN lrint and lrintf functions are buggy:
-	**		http://sourceware.org/ml/cygwin/2005-06/msg00153.html
-	**		http://sourceware.org/ml/cygwin/2005-09/msg00047.html
-	**	and slow.
-	**	These functions (pulled from the Public Domain MinGW math.h header)
-	**	replace the native versions.
-	*/
-
-	static inline long double2int (double in)
-	{	long retval ;
-
-		__asm__ __volatile__
-		(	"fistpl %0"
-			: "=m" (retval)
-			: "t" (in)
-			: "st"
-			) ;
-
-		return retval ;
-	} /* double2int */
-
-	static inline long float2int (float in)
-	{	long retval ;
-
-		__asm__ __volatile__
-		(	"fistpl %0"
-			: "=m" (retval)
-			: "t" (in)
-			: "st"
-			) ;
-
-		return retval ;
-	} /* float2int */
-
-#elif (defined (WIN64) || defined(_WIN64))
-
-	/*	Win64 section should be places before Win32 one, because
-	**	most likely both WIN32 and WIN64 will be defined in 64-bit case.
-	*/
-
-	#include	<math.h>
-
-	/*	Win64 doesn't seem to have these functions, nor inline assembly.
-	**	Therefore implement inline versions of these functions here.
-	*/
-	#include    <emmintrin.h>
-	#include    <mmintrin.h>
-
-	__inline long int
-	lrint(double flt)
-	{
-		return _mm_cvtsd_si32(_mm_load_sd(&flt));
-	}
-
-	__inline long int
-	lrintf(float flt)
-	{
-		return _mm_cvtss_si32(_mm_load_ss(&flt));
-	}
-
-#elif (defined (WIN32) || defined (_WIN32))
-
-	#undef		HAVE_LRINT_REPLACEMENT
-	#define		HAVE_LRINT_REPLACEMENT	1
-
-	#include	<math.h>
-
-	/*
-	**	Win32 doesn't seem to have these functions.
-	**	Therefore implement inline versions of these functions here.
-	*/
-
-	__inline long int
-	lrint (double flt)
-	{	int intgr ;
-
-		_asm
-		{	fld flt
-			fistp intgr
-			} ;
-
-		return intgr ;
-	}
-
-	__inline long int
-	lrintf (float flt)
-	{	int intgr ;
-
-		_asm
-		{	fld flt
-			fistp intgr
-			} ;
-
-		return intgr ;
-	}
-
-#elif (defined (__MWERKS__) && defined (macintosh))
-
-	/* This MacOS 9 solution was provided by Stephane Letz */
-
-	#undef		HAVE_LRINT_REPLACEMENT
-	#define		HAVE_LRINT_REPLACEMENT	1
-	#include	<math.h>
-
-	#undef	lrint
-	#undef	lrintf
-
-	#define	lrint	double2int
-	#define	lrintf	float2int
-
-	inline int
-	float2int (register float in)
-	{	long res [2] ;
-
-		asm
-		{	fctiw	in, in
-			stfd	 in, res
-		}
-		return res [1] ;
-	} /* float2int */
-
-	inline int
-	double2int (register double in)
-	{	long res [2] ;
-
-		asm
-		{	fctiw	in, in
-			stfd	 in, res
-		}
-		return res [1] ;
-	} /* double2int */
-
-#elif (defined (__MACH__) && defined (__APPLE__))
-
-	/* For Apple MacOSX. */
-
-	#undef		HAVE_LRINT_REPLACEMENT
-	#define		HAVE_LRINT_REPLACEMENT	1
-	#include	<math.h>
-
-	#undef lrint
-	#undef lrintf
-
-	#define lrint	double2int
-	#define lrintf	float2int
-
-	inline static long
-	float2int (register float in)
-	{	int res [2] ;
-
-		__asm__ __volatile__
-		(	"fctiw	%1, %1\n\t"
-			"stfd	%1, %0"
-			: "=m" (res)	/* Output */
-			: "f" (in)		/* Input */
-			: "memory"
-			) ;
-
-		return res [1] ;
-	} /* lrintf */
-
-	inline static long
-	double2int (register double in)
-	{	int res [2] ;
-
-		__asm__ __volatile__
-		(	"fctiw	%1, %1\n\t"
-			"stfd	%1, %0"
-			: "=m" (res)	/* Output */
-			: "f" (in)		/* Input */
-			: "memory"
-			) ;
-
-		return res [1] ;
-	} /* lrint */
-
-#else
-	#ifndef __sgi
-	#warning "Don't have the functions lrint() and lrintf()."
-	#warning "Replacing these functions with a standard C cast."
-	#endif
-
-	#include	<math.h>
-
-	#define	lrint(dbl)		((long) (dbl))
-	#define	lrintf(flt)		((long) (flt))
-
-#endif
-
-
-#endif /* FLOAT_CAST_HEADER */
-
--- a/src/samplerate.c
+++ b/src/samplerate.c
@@ -9,11 +9,11 @@
 #include	<stdio.h>
 #include	<stdlib.h>
 #include	<string.h>
+#include	<math.h>
 
 #include	"src_config.h"
 
 #include	"samplerate.h"
-#include	"float_cast.h"
 #include	"common.h"
 
 static int psrc_set_converter (SRC_PRIVATE	*psrc, int converter_type) ;
--- a/src/src_linear.c
+++ b/src/src_linear.c
@@ -9,9 +9,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <math.h>
 
 #include "src_config.h"
-#include "float_cast.h"
 #include "common.h"
 
 static int linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
--- a/src/src_sinc.c
+++ b/src/src_sinc.c
@@ -9,9 +9,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <math.h>
 
 #include "src_config.h"
-#include "float_cast.h"
 #include "common.h"
 
 #define	SINC_MAGIC_MARKER	MAKE_MAGIC (' ', 's', 'i', 'n', 'c', ' ')
--- a/src/src_zoh.c
+++ b/src/src_zoh.c
@@ -9,9 +9,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <math.h>
 
 #include "src_config.h"
-#include "float_cast.h"
 #include "common.h"
 
 static int zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
--- a/tests/multichan_throughput_test.c
+++ b/tests/multichan_throughput_test.c
@@ -11,6 +11,7 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#include <math.h>
 
 #include <samplerate.h>
 
@@ -17,7 +18,6 @@
 #include "src_config.h"
 
 #include "util.h"
-#include "float_cast.h"
 
 #define BUFFER_LEN	(1<<17)
 
--- a/tests/throughput_test.c
+++ b/tests/throughput_test.c
@@ -11,6 +11,7 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#include <math.h>
 
 #include <samplerate.h>
 
@@ -17,7 +18,6 @@
 #include "src_config.h"
 
 #include "util.h"
-#include "float_cast.h"
 
 #define BUFFER_LEN	(1<<16)