Skip to content

Commit

Permalink
Fixed bug 2952 - SDL_MixAudioFormat does not support audio format AUD…
Browse files Browse the repository at this point in the history
…IO_U16LSB/AUDIO_U16MSB

Simon Sandstr?m

As stated in Summary. The switch statement will execute the default case and set a SDL error message: "SDL_MixAudio(): unknown audio format".

There are atleast two more problems here:

1. SDL_MixAudioFormat does not notify the user that an error has occured and that a SDL error message was set. It took me awhile to understand why I couldn't mix down the volume on my AUDIO_U16LSB formatted audio stream.. until I started digging in the SDL source code.

2. The error message is incorrect, it should read: "SDL_MixAudioFormat(): unknown audio format".
  • Loading branch information
slouken committed Oct 8, 2016
1 parent d2676c2 commit 93ff12c
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion src/audio/SDL_mixer.c
Expand Up @@ -202,6 +202,54 @@ SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
}
break;

case AUDIO_U16LSB:
{
Uint16 src1, src2;
int dst_sample;
const int max_audioval = 0xFFFF;

len /= 2;
while (len--) {
src1 = ((src[1]) << 8 | src[0]);
ADJUST_VOLUME(src1, volume);
src2 = ((dst[1]) << 8 | dst[0]);
src += 2;
dst_sample = src1 + src2;
if (dst_sample > max_audioval) {
dst_sample = max_audioval;
}
dst[0] = dst_sample & 0xFF;
dst_sample >>= 8;
dst[1] = dst_sample & 0xFF;
dst += 2;
}
}
break;

case AUDIO_U16MSB:
{
Uint16 src1, src2;
int dst_sample;
const int max_audioval = 0xFFFF;

len /= 2;
while (len--) {
src1 = ((src[0]) << 8 | src[1]);
ADJUST_VOLUME(src1, volume);
src2 = ((dst[0]) << 8 | dst[1]);
src += 2;
dst_sample = src1 + src2;
if (dst_sample > max_audioval) {
dst_sample = max_audioval;
}
dst[1] = dst_sample & 0xFF;
dst_sample >>= 8;
dst[0] = dst_sample & 0xFF;
dst += 2;
}
}
break;

case AUDIO_S32LSB:
{
const Uint32 *src32 = (Uint32 *) src;
Expand Down Expand Up @@ -313,7 +361,7 @@ SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
break;

default: /* If this happens... FIXME! */
SDL_SetError("SDL_MixAudio(): unknown audio format");
SDL_SetError("SDL_MixAudioFormat(): unknown audio format");
return;
}
}
Expand Down

0 comments on commit 93ff12c

Please sign in to comment.