mirror of
https://github.com/ScrelliCopter/VGM-Tools
synced 2025-02-21 04:09:25 +11:00
Fix apple build and sleep deprivation code
This commit is contained in:
@@ -1,12 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
|
||||||
project(dsptools LANGUAGES C)
|
project(dsptools LANGUAGES C)
|
||||||
|
|
||||||
include(CheckIncludeFile)
|
|
||||||
check_include_file("endian.h" HAVE_ENDIAN_H)
|
|
||||||
if (HAVE_ENDIAN_H)
|
|
||||||
add_definitions(HAVE_ENDIAN_H)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_subdirectory(libdsptool)
|
add_subdirectory(libdsptool)
|
||||||
|
|
||||||
set(HEADERS wave.h)
|
set(HEADERS wave.h)
|
||||||
|
|||||||
@@ -1,39 +1,67 @@
|
|||||||
#ifndef COMMON_H
|
#ifndef COMMON_H
|
||||||
#define COMMON_H
|
#define COMMON_H
|
||||||
|
|
||||||
#ifdef HAVE_ENDIAN_H
|
#ifdef __APPLE__
|
||||||
|
# include <machine/endian.h>
|
||||||
|
#elif defined( __linux__ ) || defined( __CYGWIN__ ) || defined( __OpenBSD__ )
|
||||||
# include <endian.h>
|
# include <endian.h>
|
||||||
# define BYTE_ORDER __BYTE_ORDER
|
#elif defined( __NetBSD__ ) || defined( __FreeBSD__ ) || defined( __DragonFly__ )
|
||||||
# define LITTLE_ENDIAN __LITTLE_ENDIAN
|
# include <sys/endian.h>
|
||||||
# define BIG_ENDIAN __BIG_ENDIAN
|
# ifdef __FreeBSD__
|
||||||
#else
|
# define LITTLE_ENDIAN _LITTLE_ENDIAN
|
||||||
|
# define BIG_ENDIAN _BIG_ENDIAN
|
||||||
|
# define BYTE_ORDER _BYTE_ORDER
|
||||||
|
# endif
|
||||||
|
#elif defined( _MSC_VER ) || defined( _WIN16 ) || defined( _WIN32 ) || defined( _WIN64 )
|
||||||
|
# ifdef _MSC_VER
|
||||||
# define LITTLE_ENDIAN 1234
|
# define LITTLE_ENDIAN 1234
|
||||||
# define BIG_ENDIAN 4321
|
# define BIG_ENDIAN 4321
|
||||||
# if defined( __APPLE__ ) || defined( _WIN32 )
|
# if defined( _M_IX86 ) || defined( _M_X64 ) || defined( _M_AMD64 ) || defined( _M_IA64 )
|
||||||
# define BYTE_ORDER LITTLE_ENDIAN
|
# define BYTE_ORDER LITTLE_ENDIAN
|
||||||
# else
|
# elif defined( _M_PPC )
|
||||||
# error Can't detect endianness
|
// Probably not reliable but eh
|
||||||
|
# define BYTE_ORDER BIG_ENDIAN
|
||||||
|
# endif
|
||||||
|
# elif defined( __GNUC__ )
|
||||||
|
# include <sys/param.h>
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined( BYTE_ORDER ) || !defined( LITTLE_ENDIAN ) || !defined( BIG_ENDIAN ) || \
|
||||||
|
!( BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == BIG_ENDIAN )
|
||||||
|
# error "Couldn't determine endianness or unsupported platform"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# define swap32(X) _byteswap_ulong((X))
|
||||||
|
# define swap16(X) _byteswap_ushort((X))
|
||||||
|
#elif ( __GNUC__ == 4 && __GNUC_MINOR__ >= 8 ) || ( __GNUC__ > 4 )
|
||||||
|
# pragma message("CLion penis")
|
||||||
|
# define swap32(X) __builtin_bswap32((X))
|
||||||
|
# define swap16(X) __builtin_bswap16((X))
|
||||||
|
// Apparently smelly GCC 5 blows up on this test so this is done separately for Clang
|
||||||
|
#elif defined( __has_builtin ) && __has_builtin( __builtin_bswap32 ) && __has_builtin( __builtin_bswap16 )
|
||||||
|
# define swap32(X) __builtin_bswap32((X))
|
||||||
|
# define swap16(X) __builtin_bswap16((X))
|
||||||
|
#else
|
||||||
static inline uint32_t swap32(uint32_t v)
|
static inline uint32_t swap32(uint32_t v)
|
||||||
{
|
{
|
||||||
return (v << 24) | ((v << 8) & 0x00FF0000) | ((v >> 8) & 0x0000FF00) | (v >> 24);
|
return (v << 24U) | ((v << 8U) & 0x00FF0000U) | ((v >> 8U) & 0x0000FF00U) | (v >> 24U);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint16_t swap16(uint16_t v)
|
static inline uint16_t swap16(uint16_t v)
|
||||||
{
|
{
|
||||||
return (v << 8) | (v >> 8);
|
return (v << 8U) | (v >> 8U);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||||
# define SWAP_LE32(V) (V)
|
# define SWAP_LE32(V) (V)
|
||||||
# define SWAP_LE16(V) (V)
|
# define SWAP_LE16(V) (V)
|
||||||
# define SWAP_BE32(V) swap32((uint32_t)V)
|
# define SWAP_BE32(V) swap32((V))
|
||||||
# define SWAP_BE16(V) swap16((uint16_t)V)
|
# define SWAP_BE16(V) swap16((V))
|
||||||
#elif BYTE_ORDER == BIG_ENDIAN
|
#elif BYTE_ORDER == BIG_ENDIAN
|
||||||
# define SWAP_LE32(V) swap32((uint32_t)V)
|
# define SWAP_LE32(V) swap32((V))
|
||||||
# define SWAP_LE16(V) swap16((uint16_t)V)
|
# define SWAP_LE16(V) swap16((V))
|
||||||
# define SWAP_BE32(V) (V)
|
# define SWAP_BE32(V) (V)
|
||||||
# define SWAP_BE16(V) (V)
|
# define SWAP_BE16(V) (V)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ int main(int argc, char* argv[])
|
|||||||
if (opt || !inPathL)
|
if (opt || !inPathL)
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
|
|
||||||
// C
|
// Compute output path if one wasn't specified
|
||||||
if (!outPath)
|
if (!outPath)
|
||||||
{
|
{
|
||||||
const char* base = strrchr(inPathL, '/');
|
const char* base = strrchr(inPathL, '/');
|
||||||
@@ -205,6 +205,7 @@ int main(int argc, char* argv[])
|
|||||||
outPathAlloc = true;
|
outPathAlloc = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert left (and optionally right) channels to PCM, save as wave
|
||||||
int ret;
|
int ret;
|
||||||
PcmFile left = PCMFILE_CLEAR(), right = PCMFILE_CLEAR();
|
PcmFile left = PCMFILE_CLEAR(), right = PCMFILE_CLEAR();
|
||||||
if ((ret = loadDsp(inPathL, &left)))
|
if ((ret = loadDsp(inPathL, &left)))
|
||||||
@@ -253,6 +254,8 @@ int main(int argc, char* argv[])
|
|||||||
Cleanup:
|
Cleanup:
|
||||||
free(right.pcm);
|
free(right.pcm);
|
||||||
free(left.pcm);
|
free(left.pcm);
|
||||||
|
if (outPathAlloc)
|
||||||
|
free(outPath);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user