Restore audio format binary compatibility with SDL 2.0

main
Sam Lantinga 2023-09-04 10:16:33 -07:00
parent e85206ffd8
commit 3a932141e4
3 changed files with 22 additions and 24 deletions

View File

@ -81,14 +81,12 @@ typedef Uint16 SDL_AudioFormat;
#define SDL_AUDIO_MASK_BITSIZE (0xFF) #define SDL_AUDIO_MASK_BITSIZE (0xFF)
#define SDL_AUDIO_MASK_FLOAT (1<<8) #define SDL_AUDIO_MASK_FLOAT (1<<8)
#define SDL_AUDIO_MASK_LIL_ENDIAN (1<<12) #define SDL_AUDIO_MASK_BIG_ENDIAN (1<<12)
#define SDL_AUDIO_MASK_BIG_ENDIAN (1<<13)
#define SDL_AUDIO_MASK_ENDIAN (SDL_AUDIO_MASK_BIG_ENDIAN|SDL_AUDIO_MASK_LIL_ENDIAN)
#define SDL_AUDIO_MASK_SIGNED (1<<15) #define SDL_AUDIO_MASK_SIGNED (1<<15)
#define SDL_AUDIO_BITSIZE(x) ((x) & SDL_AUDIO_MASK_BITSIZE) #define SDL_AUDIO_BITSIZE(x) ((x) & SDL_AUDIO_MASK_BITSIZE)
#define SDL_AUDIO_ISFLOAT(x) ((x) & SDL_AUDIO_MASK_FLOAT) #define SDL_AUDIO_ISFLOAT(x) ((x) & SDL_AUDIO_MASK_FLOAT)
#define SDL_AUDIO_ISBIGENDIAN(x) (((x) & SDL_AUDIO_MASK_ENDIAN) == SDL_AUDIO_MASK_BIG_ENDIAN) #define SDL_AUDIO_ISBIGENDIAN(x) ((x) & SDL_AUDIO_MASK_BIG_ENDIAN)
#define SDL_AUDIO_ISLITTLEENDIAN(x) (((x) & SDL_AUDIO_MASK_ENDIAN) == SDL_AUDIO_MASK_LIL_ENDIAN) #define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))
#define SDL_AUDIO_ISSIGNED(x) ((x) & SDL_AUDIO_MASK_SIGNED) #define SDL_AUDIO_ISSIGNED(x) ((x) & SDL_AUDIO_MASK_SIGNED)
#define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x)) #define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))
#define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x)) #define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x))
@ -101,24 +99,24 @@ typedef Uint16 SDL_AudioFormat;
/* @{ */ /* @{ */
#define SDL_AUDIO_U8 0x0008 /**< Unsigned 8-bit samples */ #define SDL_AUDIO_U8 0x0008 /**< Unsigned 8-bit samples */
#define SDL_AUDIO_S8 0x8008 /**< Signed 8-bit samples */ #define SDL_AUDIO_S8 0x8008 /**< Signed 8-bit samples */
#define SDL_AUDIO_S16LE 0x9010 /**< Signed 16-bit samples */ #define SDL_AUDIO_S16LE 0x8010 /**< Signed 16-bit samples */
#define SDL_AUDIO_S16BE 0xA010 /**< As above, but big-endian byte order */ #define SDL_AUDIO_S16BE 0x9010 /**< As above, but big-endian byte order */
/* @} */ /* @} */
/** /**
* \name int32 support * \name int32 support
*/ */
/* @{ */ /* @{ */
#define SDL_AUDIO_S32LE 0x9020 /**< 32-bit integer samples */ #define SDL_AUDIO_S32LE 0x8020 /**< 32-bit integer samples */
#define SDL_AUDIO_S32BE 0xA020 /**< As above, but big-endian byte order */ #define SDL_AUDIO_S32BE 0x9020 /**< As above, but big-endian byte order */
/* @} */ /* @} */
/** /**
* \name float32 support * \name float32 support
*/ */
/* @{ */ /* @{ */
#define SDL_AUDIO_F32LE 0x9120 /**< 32-bit floating point samples */ #define SDL_AUDIO_F32LE 0x8120 /**< 32-bit floating point samples */
#define SDL_AUDIO_F32BE 0xA120 /**< As above, but big-endian byte order */ #define SDL_AUDIO_F32BE 0x9120 /**< As above, but big-endian byte order */
/* @} */ /* @} */
/** /**

View File

@ -857,11 +857,11 @@ static void AudioConvertByteswap(void *dst, const void *src, int num_samples, in
static void AudioConvertToFloat(float *dst, const void *src, int num_samples, SDL_AudioFormat src_fmt) static void AudioConvertToFloat(float *dst, const void *src, int num_samples, SDL_AudioFormat src_fmt)
{ {
// Endian conversion is handled separately // Endian conversion is handled separately
switch (src_fmt & ~SDL_AUDIO_MASK_ENDIAN) { switch (src_fmt & ~SDL_AUDIO_MASK_BIG_ENDIAN) {
case SDL_AUDIO_S8: SDL_Convert_S8_to_F32(dst, (const Sint8 *) src, num_samples); break; case SDL_AUDIO_S8: SDL_Convert_S8_to_F32(dst, (const Sint8 *) src, num_samples); break;
case SDL_AUDIO_U8: SDL_Convert_U8_to_F32(dst, (const Uint8 *) src, num_samples); break; case SDL_AUDIO_U8: SDL_Convert_U8_to_F32(dst, (const Uint8 *) src, num_samples); break;
case (SDL_AUDIO_S16 & ~SDL_AUDIO_MASK_ENDIAN): SDL_Convert_S16_to_F32(dst, (const Sint16 *) src, num_samples); break; case SDL_AUDIO_S16LE: SDL_Convert_S16_to_F32(dst, (const Sint16 *) src, num_samples); break;
case (SDL_AUDIO_S32 & ~SDL_AUDIO_MASK_ENDIAN): SDL_Convert_S32_to_F32(dst, (const Sint32 *) src, num_samples); break; case SDL_AUDIO_S32LE: SDL_Convert_S32_to_F32(dst, (const Sint32 *) src, num_samples); break;
default: SDL_assert(!"Unexpected audio format!"); break; default: SDL_assert(!"Unexpected audio format!"); break;
} }
} }
@ -869,11 +869,11 @@ static void AudioConvertToFloat(float *dst, const void *src, int num_samples, SD
static void AudioConvertFromFloat(void *dst, const float *src, int num_samples, SDL_AudioFormat dst_fmt) static void AudioConvertFromFloat(void *dst, const float *src, int num_samples, SDL_AudioFormat dst_fmt)
{ {
// Endian conversion is handled separately // Endian conversion is handled separately
switch (dst_fmt & ~SDL_AUDIO_MASK_ENDIAN) { switch (dst_fmt & ~SDL_AUDIO_MASK_BIG_ENDIAN) {
case SDL_AUDIO_S8: SDL_Convert_F32_to_S8((Sint8 *) dst, src, num_samples); break; case SDL_AUDIO_S8: SDL_Convert_F32_to_S8((Sint8 *) dst, src, num_samples); break;
case SDL_AUDIO_U8: SDL_Convert_F32_to_U8((Uint8 *) dst, src, num_samples); break; case SDL_AUDIO_U8: SDL_Convert_F32_to_U8((Uint8 *) dst, src, num_samples); break;
case (SDL_AUDIO_S16 & ~SDL_AUDIO_MASK_ENDIAN): SDL_Convert_F32_to_S16((Sint16 *) dst, src, num_samples); break; case SDL_AUDIO_S16LE: SDL_Convert_F32_to_S16((Sint16 *) dst, src, num_samples); break;
case (SDL_AUDIO_S32 & ~SDL_AUDIO_MASK_ENDIAN): SDL_Convert_F32_to_S32((Sint32 *) dst, src, num_samples); break; case SDL_AUDIO_S32LE: SDL_Convert_F32_to_S32((Sint32 *) dst, src, num_samples); break;
default: SDL_assert(!"Unexpected audio format!"); break; default: SDL_assert(!"Unexpected audio format!"); break;
} }
} }
@ -959,7 +959,7 @@ void ConvertAudio(int num_frames, const void *src, SDL_AudioFormat src_format, i
} }
// just a byteswap needed? // just a byteswap needed?
if ((src_format & ~SDL_AUDIO_MASK_ENDIAN) == (dst_format & ~SDL_AUDIO_MASK_ENDIAN)) { if ((src_format & ~SDL_AUDIO_MASK_BIG_ENDIAN) == (dst_format & ~SDL_AUDIO_MASK_BIG_ENDIAN)) {
if (src_bitsize == 8) { if (src_bitsize == 8) {
if (src != dst) { if (src != dst) {
SDL_memcpy(dst, src, num_frames * dst_sample_frame_size); SDL_memcpy(dst, src, num_frames * dst_sample_frame_size);

View File

@ -462,12 +462,12 @@ static const int g_numAudioFrequencies = SDL_arraysize(g_audioFrequencies);
/* Verify the audio formats are laid out as expected */ /* Verify the audio formats are laid out as expected */
SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_U8_FORMAT, SDL_AUDIO_U8 == SDL_AUDIO_BITSIZE(8)); SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_U8_FORMAT, SDL_AUDIO_U8 == SDL_AUDIO_BITSIZE(8));
SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_S8_FORMAT, SDL_AUDIO_S8 == (SDL_AUDIO_BITSIZE(8) | SDL_AUDIO_MASK_SIGNED)); SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_S8_FORMAT, SDL_AUDIO_S8 == (SDL_AUDIO_BITSIZE(8) | SDL_AUDIO_MASK_SIGNED));
SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_S16LE_FORMAT, SDL_AUDIO_S16LE == (SDL_AUDIO_BITSIZE(16) | SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_LIL_ENDIAN)); SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_S16LE_FORMAT, SDL_AUDIO_S16LE == (SDL_AUDIO_BITSIZE(16) | SDL_AUDIO_MASK_SIGNED));
SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_S16BE_FORMAT, SDL_AUDIO_S16BE == (SDL_AUDIO_BITSIZE(16) | SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_BIG_ENDIAN)); SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_S16BE_FORMAT, SDL_AUDIO_S16BE == (SDL_AUDIO_S16LE | SDL_AUDIO_MASK_BIG_ENDIAN));
SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_S32LE_FORMAT, SDL_AUDIO_S32LE == (SDL_AUDIO_BITSIZE(32) | SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_LIL_ENDIAN)); SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_S32LE_FORMAT, SDL_AUDIO_S32LE == (SDL_AUDIO_BITSIZE(32) | SDL_AUDIO_MASK_SIGNED));
SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_S32BE_FORMAT, SDL_AUDIO_S32BE == (SDL_AUDIO_BITSIZE(32) | SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_BIG_ENDIAN)); SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_S32BE_FORMAT, SDL_AUDIO_S32BE == (SDL_AUDIO_S32LE | SDL_AUDIO_MASK_BIG_ENDIAN));
SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_F32LE_FORMAT, SDL_AUDIO_F32LE == (SDL_AUDIO_BITSIZE(32) | SDL_AUDIO_MASK_FLOAT | SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_LIL_ENDIAN)); SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_F32LE_FORMAT, SDL_AUDIO_F32LE == (SDL_AUDIO_BITSIZE(32) | SDL_AUDIO_MASK_FLOAT | SDL_AUDIO_MASK_SIGNED));
SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_F32BE_FORMAT, SDL_AUDIO_F32BE == (SDL_AUDIO_BITSIZE(32) | SDL_AUDIO_MASK_FLOAT | SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_BIG_ENDIAN)); SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_F32BE_FORMAT, SDL_AUDIO_F32BE == (SDL_AUDIO_F32LE | SDL_AUDIO_MASK_BIG_ENDIAN));
/** /**
* \brief Builds various audio conversion structures * \brief Builds various audio conversion structures