mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-09 09:24:24 +02:00
Renamed SDL_MixAudioFormat to SDL_MixAudio, and use float volume
This commit is contained in:
@@ -1046,7 +1046,7 @@ void SDL_AudioThreadFinalize(SDL_AudioDevice *device)
|
||||
|
||||
static void MixFloat32Audio(float *dst, const float *src, const int buffer_size)
|
||||
{
|
||||
if (SDL_MixAudioFormat((Uint8 *) dst, (const Uint8 *) src, SDL_AUDIO_F32, buffer_size, SDL_MIX_MAXVOLUME) < 0) {
|
||||
if (SDL_MixAudio((Uint8 *) dst, (const Uint8 *) src, SDL_AUDIO_F32, buffer_size, 1.0f) < 0) {
|
||||
SDL_assert(!"This shouldn't happen.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,15 +78,19 @@ static const Uint8 mix8[] = {
|
||||
};
|
||||
|
||||
// The volume ranges from 0 - 128
|
||||
#define ADJUST_VOLUME(type, s, v) ((s) = (type)(((s) * (v)) / SDL_MIX_MAXVOLUME))
|
||||
#define ADJUST_VOLUME_U8(s, v) ((s) = (Uint8)(((((s) - 128) * (v)) / SDL_MIX_MAXVOLUME) + 128))
|
||||
#define MIX_MAXVOLUME 128
|
||||
#define ADJUST_VOLUME(type, s, v) ((s) = (type)(((s) * (v)) / MIX_MAXVOLUME))
|
||||
#define ADJUST_VOLUME_U8(s, v) ((s) = (Uint8)(((((s) - 128) * (v)) / MIX_MAXVOLUME) + 128))
|
||||
|
||||
// !!! FIXME: This needs some SIMD magic.
|
||||
// !!! FIXME: Add fast-path for volume = 1
|
||||
// !!! FIXME: Use larger scales for 16-bit/32-bit integers
|
||||
|
||||
// !!! FIXME: this needs some SIMD magic.
|
||||
|
||||
int SDL_MixAudioFormat(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format,
|
||||
Uint32 len, int volume)
|
||||
int SDL_MixAudio(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format,
|
||||
Uint32 len, float fvolume)
|
||||
{
|
||||
int volume = (int)SDL_roundf(fvolume * MIX_MAXVOLUME);
|
||||
|
||||
if (volume == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -231,7 +235,6 @@ int SDL_MixAudioFormat(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format,
|
||||
|
||||
case SDL_AUDIO_F32LE:
|
||||
{
|
||||
const float fvolume = volume / ((float)SDL_MIX_MAXVOLUME);
|
||||
const float *src32 = (float *)src;
|
||||
float *dst32 = (float *)dst;
|
||||
float src1, src2;
|
||||
@@ -257,7 +260,6 @@ int SDL_MixAudioFormat(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format,
|
||||
|
||||
case SDL_AUDIO_F32BE:
|
||||
{
|
||||
const float fvolume = volume / ((float)SDL_MIX_MAXVOLUME);
|
||||
const float *src32 = (float *)src;
|
||||
float *dst32 = (float *)dst;
|
||||
float src1, src2;
|
||||
@@ -282,7 +284,7 @@ int SDL_MixAudioFormat(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format,
|
||||
} break;
|
||||
|
||||
default: // If this happens... FIXME!
|
||||
return SDL_SetError("SDL_MixAudioFormat(): unknown audio format");
|
||||
return SDL_SetError("SDL_MixAudio(): unknown audio format");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -564,7 +564,7 @@ SDL3_0.0.0 {
|
||||
SDL_Metal_DestroyView;
|
||||
SDL_Metal_GetLayer;
|
||||
SDL_MinimizeWindow;
|
||||
SDL_MixAudioFormat;
|
||||
SDL_MixAudio;
|
||||
SDL_OnApplicationDidBecomeActive;
|
||||
SDL_OnApplicationDidChangeStatusBarOrientation;
|
||||
SDL_OnApplicationDidEnterBackground;
|
||||
|
||||
@@ -589,7 +589,7 @@
|
||||
#define SDL_Metal_DestroyView SDL_Metal_DestroyView_REAL
|
||||
#define SDL_Metal_GetLayer SDL_Metal_GetLayer_REAL
|
||||
#define SDL_MinimizeWindow SDL_MinimizeWindow_REAL
|
||||
#define SDL_MixAudioFormat SDL_MixAudioFormat_REAL
|
||||
#define SDL_MixAudio SDL_MixAudio_REAL
|
||||
#define SDL_OnApplicationDidBecomeActive SDL_OnApplicationDidBecomeActive_REAL
|
||||
#define SDL_OnApplicationDidChangeStatusBarOrientation SDL_OnApplicationDidChangeStatusBarOrientation_REAL
|
||||
#define SDL_OnApplicationDidEnterBackground SDL_OnApplicationDidEnterBackground_REAL
|
||||
|
||||
@@ -618,7 +618,7 @@ SDL_DYNAPI_PROC(SDL_MetalView,SDL_Metal_CreateView,(SDL_Window *a),(a),return)
|
||||
SDL_DYNAPI_PROC(void,SDL_Metal_DestroyView,(SDL_MetalView a),(a),)
|
||||
SDL_DYNAPI_PROC(void*,SDL_Metal_GetLayer,(SDL_MetalView a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_MinimizeWindow,(SDL_Window *a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_MixAudioFormat,(Uint8 *a, const Uint8 *b, SDL_AudioFormat c, Uint32 d, int e),(a,b,c,d,e),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_MixAudio,(Uint8 *a, const Uint8 *b, SDL_AudioFormat c, Uint32 d, float e),(a,b,c,d,e),return)
|
||||
SDL_DYNAPI_PROC(void,SDL_OnApplicationDidBecomeActive,(void),(),)
|
||||
SDL_DYNAPI_PROC(void,SDL_OnApplicationDidChangeStatusBarOrientation,(void),(),)
|
||||
SDL_DYNAPI_PROC(void,SDL_OnApplicationDidEnterBackground,(void),(),)
|
||||
|
||||
Reference in New Issue
Block a user