From f0c8c68592db93034f4b952354de61b7b23ac22e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 10 Jul 2015 03:31:51 -0700 Subject: [PATCH] detect endianness with cmake --- CMakeLists.txt | 9 +++++++++ src/alsa.cpp | 7 +++++++ src/config.h.in | 10 ++++++++++ src/soundio.h | 26 ++------------------------ 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8081ef7..6b3e6b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,15 @@ set(TEST_CFLAGS "${LIB_CFLAGS} -fprofile-arcs -ftest-coverage") set(TEST_LDFLAGS "-fprofile-arcs -ftest-coverage") set(TEST_INCLUDES "${CMAKE_SOURCE_DIR}/test") +include(TestBigEndian) +test_big_endian(IS_BIG_ENDIAN) +if(IS_BIG_ENDIAN) + set(SOUNDIO_OS_BIG_ENDIAN true) + set(SOUNDIO_OS_LITTLE_ENDIAN false) +else() + set(SOUNDIO_OS_BIG_ENDIAN false) + set(SOUNDIO_OS_LITTLE_ENDIAN true) +endif() configure_file ( "${CMAKE_SOURCE_DIR}/src/config.h.in" ${CONFIGURE_OUT_FILE} diff --git a/src/alsa.cpp b/src/alsa.cpp index 07e0a84..47cdd8f 100644 --- a/src/alsa.cpp +++ b/src/alsa.cpp @@ -190,6 +190,13 @@ static void test_fmt_mask(SoundIoDevice *device, const snd_pcm_format_mask_t *fm } } +// TODO: look at http://www.alsa-project.org/alsa-doc/alsa-lib/_2test_2pcm_8c-example.html#a27 +// deterimine what do do about: +// * hw buffer size +// * hw period time +// * sw start threshold +// * sw avail min + static int probe_device(SoundIoDevice *device, snd_pcm_chmap_query_t **maps) { int err; snd_pcm_t *handle; diff --git a/src/config.h.in b/src/config.h.in index 04c5439..68afd03 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2015 Andrew Kelley + * + * This file is part of libsoundio, which is MIT licensed. + * See http://opensource.org/licenses/MIT + */ + #ifndef SOUNDIO_CONFIG_H #define SOUNDIO_CONFIG_H @@ -6,6 +13,9 @@ #define SOUNDIO_VERSION_PATCH @LIBSOUNDIO_VERSION_PATCH@ #define SOUNDIO_VERSION_STRING "@LIBSOUNDIO_VERSION@" +#cmakedefine SOUNDIO_OS_BIG_ENDIAN @SOUNDIO_OS_BIG_ENDIAN@ +#cmakedefine SOUNDIO_OS_LITTLE_ENDIAN @SOUNDIO_OS_LITTLE_ENDIAN@ + #cmakedefine SOUNDIO_HAVE_ALSA #cmakedefine SOUNDIO_HAVE_PULSEAUDIO diff --git a/src/soundio.h b/src/soundio.h index d271053..7cd5412 100644 --- a/src/soundio.h +++ b/src/soundio.h @@ -11,30 +11,6 @@ #include "config.h" #include -#if (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) || \ - defined(__BIG_ENDIAN__) || \ - defined(__ARMEB__) || \ - defined(__THUMBEB__) || \ - defined(__AARCH64EB__) || \ - defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__) - -#define SOUNDIO_OS_BIG_ENDIAN - -#elif (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \ - defined(__LITTLE_ENDIAN__) || \ - defined(__ARMEL__) || \ - defined(__THUMBEL__) || \ - defined(__AARCH64EL__) || \ - defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || \ - defined(_WIN32) - -#define SOUNDIO_OS_LITTLE_ENDIAN - -#else -#error unknown byte order -#endif - - #ifdef __cplusplus extern "C" { @@ -180,6 +156,8 @@ enum SoundIoFormat { #define SoundIoFormatU32NE SoundIoFormatU32LE #define SoundIoFormatFloat32NE SoundIoFormatFloat32LE #define SoundIoFormatFloat64NE SoundIoFormatFloat64LE +#else +#error unknown byte order #endif struct SoundIoDevice {