src/ALAC/ : Replace Apple endswap routines with ones from libsndfile.

This commit is contained in:
Erik de Castro Lopo 2013-02-11 17:54:38 +11:00
parent 88b1e0fad8
commit b9e801d580
4 changed files with 12 additions and 212 deletions

View File

@ -1,3 +1,8 @@
2013-02-11 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/ALAC/
Replace Apple endswap routines with ones from libsndfile.
2013-02-10 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/common.h

View File

@ -1,185 +0,0 @@
/*
* Copyright (c) 2011 Apple Inc. All rights reserved.
*
* @APPLE_APACHE_LICENSE_HEADER_START@
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @APPLE_APACHE_LICENSE_HEADER_END@
*/
//
// EndianPortable.c
//
// Copyright 2011 Apple Inc. All rights reserved.
//
#include <stdio.h>
#include "EndianPortable.h"
#define BSWAP16(x) (((x << 8) | ((x >> 8) & 0x00ff)))
#define BSWAP32(x) (((x << 24) | ((x << 8) & 0x00ff0000) | ((x >> 8) & 0x0000ff00) | ((x >> 24) & 0x000000ff)))
#define BSWAP64(x) ((((int64_t)x << 56) | (((int64_t)x << 40) & 0x00ff000000000000LL) | \
(((int64_t)x << 24) & 0x0000ff0000000000LL) | (((int64_t)x << 8) & 0x000000ff00000000LL) | \
(((int64_t)x >> 8) & 0x00000000ff000000LL) | (((int64_t)x >> 24) & 0x0000000000ff0000LL) | \
(((int64_t)x >> 40) & 0x000000000000ff00LL) | (((int64_t)x >> 56) & 0x00000000000000ffLL)))
#if defined(__i386__)
#define TARGET_RT_LITTLE_ENDIAN 1
#elif defined(__x86_64__)
#define TARGET_RT_LITTLE_ENDIAN 1
#elif defined(__powerpc__)
#define TARGET_RT_LITTLE_ENDIAN 0
#elif defined (TARGET_OS_WIN32)
#define TARGET_RT_LITTLE_ENDIAN 1
#elif defined (__BYTE_ORDER__)
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define TARGET_RT_LITTLE_ENDIAN 1
#else
#define TARGET_RT_LITTLE_ENDIAN 0
#endif
#endif
uint16_t Swap16NtoB(uint16_t inUInt16)
{
#if TARGET_RT_LITTLE_ENDIAN
return BSWAP16(inUInt16);
#else
return inUInt16;
#endif
}
uint16_t Swap16BtoN(uint16_t inUInt16)
{
#if TARGET_RT_LITTLE_ENDIAN
return BSWAP16(inUInt16);
#else
return inUInt16;
#endif
}
uint32_t Swap32NtoB(uint32_t inUInt32)
{
#if TARGET_RT_LITTLE_ENDIAN
return BSWAP32(inUInt32);
#else
return inUInt32;
#endif
}
uint32_t Swap32BtoN(uint32_t inUInt32)
{
#if TARGET_RT_LITTLE_ENDIAN
return BSWAP32(inUInt32);
#else
return inUInt32;
#endif
}
uint64_t Swap64BtoN(uint64_t inUInt64)
{
#if TARGET_RT_LITTLE_ENDIAN
return BSWAP64(inUInt64);
#else
return inUInt64;
#endif
}
uint64_t Swap64NtoB(uint64_t inUInt64)
{
#if TARGET_RT_LITTLE_ENDIAN
return BSWAP64(inUInt64);
#else
return inUInt64;
#endif
}
float SwapFloat32BtoN(float in)
{
#if TARGET_RT_LITTLE_ENDIAN
union {
float f;
int32_t i;
} x;
x.f = in;
x.i = BSWAP32(x.i);
return x.f;
#else
return in;
#endif
}
float SwapFloat32NtoB(float in)
{
#if TARGET_RT_LITTLE_ENDIAN
union {
float f;
int32_t i;
} x;
x.f = in;
x.i = BSWAP32(x.i);
return x.f;
#else
return in;
#endif
}
double SwapFloat64BtoN(double in)
{
#if TARGET_RT_LITTLE_ENDIAN
union {
double f;
int64_t i;
} x;
x.f = in;
x.i = BSWAP64(x.i);
return x.f;
#else
return in;
#endif
}
double SwapFloat64NtoB(double in)
{
#if TARGET_RT_LITTLE_ENDIAN
union {
double f;
int64_t i;
} x;
x.f = in;
x.i = BSWAP64(x.i);
return x.f;
#else
return in;
#endif
}
void Swap16(uint16_t * inUInt16)
{
*inUInt16 = BSWAP16(*inUInt16);
}
void Swap24(uint8_t * inUInt24)
{
uint8_t tempVal = inUInt24[0];
inUInt24[0] = inUInt24[2];
inUInt24[2] = tempVal;
}
void Swap32(uint32_t * inUInt32)
{
*inUInt32 = BSWAP32(*inUInt32);
}

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2011 Apple Inc. All rights reserved.
** Copyright (C) 2013 Erik de Castro Lopo <erikd@mega-nerd.com>
*
* @APPLE_APACHE_LICENSE_HEADER_START@
*
@ -27,33 +28,12 @@
#ifndef _EndianPortable_h
#define _EndianPortable_h
#include <stdint.h>
#include <sfendian.h>
#ifdef __cplusplus
extern "C" {
#endif
#define Swap16NtoB(x) H2BE_16(x)
#define Swap16BtoN(x) BE2H_16(x)
uint16_t Swap16NtoB(uint16_t inUInt16);
uint16_t Swap16BtoN(uint16_t inUInt16);
uint32_t Swap32NtoB(uint32_t inUInt32);
uint32_t Swap32BtoN(uint32_t inUInt32);
uint64_t Swap64BtoN(uint64_t inUInt64);
uint64_t Swap64NtoB(uint64_t inUInt64);
float SwapFloat32BtoN(float in);
float SwapFloat32NtoB(float in);
double SwapFloat64BtoN(double in);
double SwapFloat64NtoB(double in);
void Swap16(uint16_t * inUInt16);
void Swap24(uint8_t * inUInt24);
void Swap32(uint32_t * inUInt32);
#ifdef __cplusplus
}
#endif
#define Swap32NtoB(x) H2BE_32(x)
#define Swap32BtoN(x) BE2H_32(x)
#endif

View File

@ -69,7 +69,7 @@ G72x_libg72x_la_SOURCES = G72x/g72x.h G72x/g72x_priv.h \
ALAC_libalac_la_SOURCES = ALAC/ALACAudioTypes.h ALAC/ALACBitUtilities.h \
ALAC/EndianPortable.h ALAC/aglib.h ALAC/dplib.h ALAC/matrixlib.h \
ALAC/alac_codec.h \
ALAC/ALACBitUtilities.c ALAC/EndianPortable.c ALAC/ag_dec.c \
ALAC/ALACBitUtilities.c ALAC/ag_dec.c \
ALAC/ag_enc.c ALAC/dp_dec.c ALAC/dp_enc.c ALAC/matrix_dec.c \
ALAC/matrix_enc.c ALAC/alac_decoder.c ALAC/alac_encoder.c