mirror of
https://github.com/holub/mame
synced 2025-10-04 16:34:53 +03:00
Backport libflac endian patch from a5d1d4f0c5
(nw)
This commit is contained in:
parent
6b79dc2275
commit
a4ce5ecbd0
1
3rdparty/libflac/include/share/Makefile.am
vendored
1
3rdparty/libflac/include/share/Makefile.am
vendored
@ -6,6 +6,7 @@ SUBDIRS = grabbag
|
|||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
alloc.h \
|
alloc.h \
|
||||||
|
endswap.h \
|
||||||
getopt.h \
|
getopt.h \
|
||||||
grabbag.h \
|
grabbag.h \
|
||||||
replaygain_analysis.h \
|
replaygain_analysis.h \
|
||||||
|
77
3rdparty/libflac/include/share/endswap.h
vendored
Normal file
77
3rdparty/libflac/include/share/endswap.h
vendored
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/* libFLAC - Free Lossless Audio Codec library
|
||||||
|
* Copyright (C) 2012-2014 Xiph.org Foundation
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* - Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* - Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* - Neither the name of the Xiph.org Foundation nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* These changes are necessary because we don't use FLAC's build system. */
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define HAVE_BSWAP32 1
|
||||||
|
#else
|
||||||
|
#define HAVE_BSWAP32 0
|
||||||
|
#endif
|
||||||
|
#if ((__GNUC__ >= 4) && (__GNUC_MINOR__ >= 8)) || defined(__clang_major__)
|
||||||
|
#define HAVE_BSWAP16 1
|
||||||
|
#else
|
||||||
|
#define HAVE_BSWAP16 0
|
||||||
|
#endif
|
||||||
|
#ifdef __linux__
|
||||||
|
#define HAVE_BYTESWAP_H
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAVE_BSWAP32 /* GCC and Clang */
|
||||||
|
|
||||||
|
/* GCC prior to 4.8 didn't provide bswap16 on x86_64 */
|
||||||
|
#if ! HAVE_BSWAP16
|
||||||
|
static inline unsigned short __builtin_bswap16(unsigned short a)
|
||||||
|
{
|
||||||
|
return (a<<8)|(a>>8);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ENDSWAP_16(x) (__builtin_bswap16 (x))
|
||||||
|
#define ENDSWAP_32(x) (__builtin_bswap32 (x))
|
||||||
|
|
||||||
|
#elif defined _MSC_VER /* Windows. Apparently in <stdlib.h>. */
|
||||||
|
|
||||||
|
#define ENDSWAP_16(x) (_byteswap_ushort (x))
|
||||||
|
#define ENDSWAP_32(x) (_byteswap_ulong (x))
|
||||||
|
|
||||||
|
#elif defined HAVE_BYTESWAP_H /* Linux */
|
||||||
|
|
||||||
|
#include <byteswap.h>
|
||||||
|
|
||||||
|
#define ENDSWAP_16(x) (bswap_16 (x))
|
||||||
|
#define ENDSWAP_32(x) (bswap_32 (x))
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define ENDSWAP_16(x) ((((x) >> 8) & 0xFF) | (((x) & 0xFF) << 8))
|
||||||
|
#define ENDSWAP_32(x) ((((x) >> 24) & 0xFF) | (((x) >> 8) & 0xFF00) | (((x) & 0xFF00) << 8) | (((x) & 0xFF) << 24))
|
||||||
|
|
||||||
|
#endif
|
52
3rdparty/libflac/src/libFLAC/bitreader.c
vendored
52
3rdparty/libflac/src/libFLAC/bitreader.c
vendored
@ -35,19 +35,11 @@
|
|||||||
|
|
||||||
#include <stdlib.h> /* for malloc() */
|
#include <stdlib.h> /* for malloc() */
|
||||||
#include <string.h> /* for memcpy(), memset() */
|
#include <string.h> /* for memcpy(), memset() */
|
||||||
#ifdef _MSC_VER
|
|
||||||
#include <winsock.h> /* for ntohl() */
|
|
||||||
#elif defined FLAC__SYS_DARWIN
|
|
||||||
#include <machine/endian.h> /* for ntohl() */
|
|
||||||
#elif defined __MINGW32__
|
|
||||||
#include <winsock.h> /* for ntohl() */
|
|
||||||
#else
|
|
||||||
#include <netinet/in.h> /* for ntohl() */
|
|
||||||
#endif
|
|
||||||
#include "private/bitmath.h"
|
#include "private/bitmath.h"
|
||||||
#include "private/bitreader.h"
|
#include "private/bitreader.h"
|
||||||
#include "private/crc.h"
|
#include "private/crc.h"
|
||||||
#include "FLAC/assert.h"
|
#include "FLAC/assert.h"
|
||||||
|
#include "share/endswap.h"
|
||||||
|
|
||||||
/* Things should be fastest when this matches the machine word size */
|
/* Things should be fastest when this matches the machine word size */
|
||||||
/* WATCHOUT: if you change this you must also change the following #defines down to COUNT_ZERO_MSBS below to match */
|
/* WATCHOUT: if you change this you must also change the following #defines down to COUNT_ZERO_MSBS below to match */
|
||||||
@ -61,11 +53,7 @@ typedef FLAC__uint32 brword;
|
|||||||
#if WORDS_BIGENDIAN
|
#if WORDS_BIGENDIAN
|
||||||
#define SWAP_BE_WORD_TO_HOST(x) (x)
|
#define SWAP_BE_WORD_TO_HOST(x) (x)
|
||||||
#else
|
#else
|
||||||
#ifdef _MSC_VER
|
#define SWAP_BE_WORD_TO_HOST(x) ENDSWAP_32(x)
|
||||||
#define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
|
|
||||||
#else
|
|
||||||
#define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
/* counts the # of zero MSBs in a word */
|
/* counts the # of zero MSBs in a word */
|
||||||
#define COUNT_ZERO_MSBS(word) ( \
|
#define COUNT_ZERO_MSBS(word) ( \
|
||||||
@ -149,35 +137,6 @@ struct FLAC__BitReader {
|
|||||||
FLAC__CPUInfo cpu_info;
|
FLAC__CPUInfo cpu_info;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
/* OPT: an MSVC built-in would be better */
|
|
||||||
static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
|
|
||||||
{
|
|
||||||
x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
|
|
||||||
return (x>>16) | (x<<16);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(_M_IX86)
|
|
||||||
static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
|
|
||||||
{
|
|
||||||
__asm {
|
|
||||||
mov edx, start
|
|
||||||
mov ecx, len
|
|
||||||
test ecx, ecx
|
|
||||||
loop1:
|
|
||||||
jz done1
|
|
||||||
mov eax, [edx]
|
|
||||||
bswap eax
|
|
||||||
mov [edx], eax
|
|
||||||
add edx, 4
|
|
||||||
dec ecx
|
|
||||||
jmp short loop1
|
|
||||||
done1:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
|
static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
|
||||||
{
|
{
|
||||||
register unsigned crc = br->read_crc16;
|
register unsigned crc = br->read_crc16;
|
||||||
@ -266,13 +225,6 @@ FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
|
|||||||
#if WORDS_BIGENDIAN
|
#if WORDS_BIGENDIAN
|
||||||
#else
|
#else
|
||||||
end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
|
end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
|
||||||
# if defined(_MSC_VER) && (FLAC__BYTES_PER_WORD == 4) && defined(_M_IX86)
|
|
||||||
if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
|
|
||||||
start = br->words;
|
|
||||||
local_swap32_block_(br->buffer + start, end - start);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
# endif
|
|
||||||
for(start = br->words; start < end; start++)
|
for(start = br->words; start < end; start++)
|
||||||
br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
|
br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
|
||||||
#endif
|
#endif
|
||||||
|
28
3rdparty/libflac/src/libFLAC/bitwriter.c
vendored
28
3rdparty/libflac/src/libFLAC/bitwriter.c
vendored
@ -35,22 +35,11 @@
|
|||||||
|
|
||||||
#include <stdlib.h> /* for malloc() */
|
#include <stdlib.h> /* for malloc() */
|
||||||
#include <string.h> /* for memcpy(), memset() */
|
#include <string.h> /* for memcpy(), memset() */
|
||||||
#ifdef _MSC_VER
|
|
||||||
#include <winsock.h> /* for ntohl() */
|
|
||||||
#elif defined FLAC__SYS_DARWIN
|
|
||||||
#include <machine/endian.h> /* for ntohl() */
|
|
||||||
#elif defined __MINGW32__
|
|
||||||
#include <winsock.h> /* for ntohl() */
|
|
||||||
#else
|
|
||||||
#include <netinet/in.h> /* for ntohl() */
|
|
||||||
#endif
|
|
||||||
#if 0 /* UNUSED */
|
|
||||||
#include "private/bitmath.h"
|
|
||||||
#endif
|
|
||||||
#include "private/bitwriter.h"
|
#include "private/bitwriter.h"
|
||||||
#include "private/crc.h"
|
#include "private/crc.h"
|
||||||
#include "FLAC/assert.h"
|
#include "FLAC/assert.h"
|
||||||
#include "share/alloc.h"
|
#include "share/alloc.h"
|
||||||
|
#include "share/endswap.h"
|
||||||
|
|
||||||
/* Things should be fastest when this matches the machine word size */
|
/* Things should be fastest when this matches the machine word size */
|
||||||
/* WATCHOUT: if you change this you must also change the following #defines down to SWAP_BE_WORD_TO_HOST below to match */
|
/* WATCHOUT: if you change this you must also change the following #defines down to SWAP_BE_WORD_TO_HOST below to match */
|
||||||
@ -63,11 +52,7 @@ typedef FLAC__uint32 bwword;
|
|||||||
#if WORDS_BIGENDIAN
|
#if WORDS_BIGENDIAN
|
||||||
#define SWAP_BE_WORD_TO_HOST(x) (x)
|
#define SWAP_BE_WORD_TO_HOST(x) (x)
|
||||||
#else
|
#else
|
||||||
#ifdef _MSC_VER
|
#define SWAP_BE_WORD_TO_HOST(x) ENDSWAP_32(x)
|
||||||
#define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
|
|
||||||
#else
|
|
||||||
#define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -107,15 +92,6 @@ struct FLAC__BitWriter {
|
|||||||
unsigned bits; /* # of used bits in accum */
|
unsigned bits; /* # of used bits in accum */
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
/* OPT: an MSVC built-in would be better */
|
|
||||||
static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
|
|
||||||
{
|
|
||||||
x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
|
|
||||||
return (x>>16) | (x<<16);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* * WATCHOUT: The current implementation only grows the buffer. */
|
/* * WATCHOUT: The current implementation only grows the buffer. */
|
||||||
static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
|
static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user