Slightly optimized and fixed float SDL_MixAudioFormat
parent
33f28d6143
commit
46cecc42a2
|
@ -231,57 +231,53 @@ int SDL_MixAudioFormat(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format,
|
||||||
|
|
||||||
case SDL_AUDIO_F32LE:
|
case SDL_AUDIO_F32LE:
|
||||||
{
|
{
|
||||||
const float fmaxvolume = 1.0f / ((float)SDL_MIX_MAXVOLUME);
|
const float fvolume = volume / ((float)SDL_MIX_MAXVOLUME);
|
||||||
const float fvolume = (float)volume;
|
|
||||||
const float *src32 = (float *)src;
|
const float *src32 = (float *)src;
|
||||||
float *dst32 = (float *)dst;
|
float *dst32 = (float *)dst;
|
||||||
float src1, src2;
|
float src1, src2;
|
||||||
double dst_sample;
|
float dst_sample;
|
||||||
// !!! FIXME: are these right?
|
const float max_audioval = 1.0f;
|
||||||
const double max_audioval = 3.402823466e+38F;
|
const float min_audioval = -1.0f;
|
||||||
const double min_audioval = -3.402823466e+38F;
|
|
||||||
|
|
||||||
len /= 4;
|
len /= 4;
|
||||||
while (len--) {
|
while (len--) {
|
||||||
src1 = ((SDL_SwapFloatLE(*src32) * fvolume) * fmaxvolume);
|
src1 = SDL_SwapFloatLE(*src32) * fvolume;
|
||||||
src2 = SDL_SwapFloatLE(*dst32);
|
src2 = SDL_SwapFloatLE(*dst32);
|
||||||
src32++;
|
src32++;
|
||||||
|
|
||||||
dst_sample = ((double)src1) + ((double)src2);
|
dst_sample = src1 + src2;
|
||||||
if (dst_sample > max_audioval) {
|
if (dst_sample > max_audioval) {
|
||||||
dst_sample = max_audioval;
|
dst_sample = max_audioval;
|
||||||
} else if (dst_sample < min_audioval) {
|
} else if (dst_sample < min_audioval) {
|
||||||
dst_sample = min_audioval;
|
dst_sample = min_audioval;
|
||||||
}
|
}
|
||||||
*(dst32++) = SDL_SwapFloatLE((float)dst_sample);
|
*(dst32++) = SDL_SwapFloatLE(dst_sample);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case SDL_AUDIO_F32BE:
|
case SDL_AUDIO_F32BE:
|
||||||
{
|
{
|
||||||
const float fmaxvolume = 1.0f / ((float)SDL_MIX_MAXVOLUME);
|
const float fvolume = volume / ((float)SDL_MIX_MAXVOLUME);
|
||||||
const float fvolume = (float)volume;
|
|
||||||
const float *src32 = (float *)src;
|
const float *src32 = (float *)src;
|
||||||
float *dst32 = (float *)dst;
|
float *dst32 = (float *)dst;
|
||||||
float src1, src2;
|
float src1, src2;
|
||||||
double dst_sample;
|
float dst_sample;
|
||||||
// !!! FIXME: are these right?
|
const float max_audioval = 1.0f;
|
||||||
const double max_audioval = 3.402823466e+38F;
|
const float min_audioval = -1.0f;
|
||||||
const double min_audioval = -3.402823466e+38F;
|
|
||||||
|
|
||||||
len /= 4;
|
len /= 4;
|
||||||
while (len--) {
|
while (len--) {
|
||||||
src1 = ((SDL_SwapFloatBE(*src32) * fvolume) * fmaxvolume);
|
src1 = SDL_SwapFloatBE(*src32) * fvolume;
|
||||||
src2 = SDL_SwapFloatBE(*dst32);
|
src2 = SDL_SwapFloatBE(*dst32);
|
||||||
src32++;
|
src32++;
|
||||||
|
|
||||||
dst_sample = ((double)src1) + ((double)src2);
|
dst_sample = src1 + src2;
|
||||||
if (dst_sample > max_audioval) {
|
if (dst_sample > max_audioval) {
|
||||||
dst_sample = max_audioval;
|
dst_sample = max_audioval;
|
||||||
} else if (dst_sample < min_audioval) {
|
} else if (dst_sample < min_audioval) {
|
||||||
dst_sample = min_audioval;
|
dst_sample = min_audioval;
|
||||||
}
|
}
|
||||||
*(dst32++) = SDL_SwapFloatBE((float)dst_sample);
|
*(dst32++) = SDL_SwapFloatBE(dst_sample);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue