Skip to content

Commit fb3af0e

Browse files
committed
music_ogg: provide audio using the host endianness
This fixes two issues in big-endian devices: - When using Tremor, Tremor doesn't swap the byte order, so it "respects" the endianness of the host. This change makes sure SDL_mixer creates a stream in AUDIO_S16SYS format (meaning S16 with the host endianness). - Make also vorbis respect the host endianness. Before this change, ov_read was forced to always deliver data in little-endian order. That wouldn't work with the AUDIO_S16SYS change described above. Also, it means SDL would swap the bytes of ogg data twice in big-endian devices: first in ov_read to little- endian when reading ogg file, and then again in SDL_Convert_Byteswap before sending the data to the audio device. The result of this is fixing Tremor support on big-endian devices and improving performance/efficiency of Vorbis on big-endian devices.
1 parent 23a2b71 commit fb3af0e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/codecs/music_ogg.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static int OGG_UpdateSection(OGG_music *music)
215215
music->stream = NULL;
216216
}
217217

218-
music->stream = SDL_NewAudioStream(AUDIO_S16, (Uint8)vi->channels, (int)vi->rate,
218+
music->stream = SDL_NewAudioStream(AUDIO_S16SYS, (Uint8)vi->channels, (int)vi->rate,
219219
music_spec.format, music_spec.channels, music_spec.freq);
220220
if (!music->stream) {
221221
return -1;
@@ -421,7 +421,7 @@ static int OGG_GetSome(void *context, void *data, int bytes, SDL_bool *done)
421421
#ifdef OGG_USE_TREMOR
422422
amount = (int)vorbis.ov_read(&music->vf, music->buffer, music->buffer_size, &section);
423423
#else
424-
amount = (int)vorbis.ov_read(&music->vf, music->buffer, music->buffer_size, 0, 2, 1, &section);
424+
amount = (int)vorbis.ov_read(&music->vf, music->buffer, music->buffer_size, SDL_BYTEORDER == SDL_BIG_ENDIAN, 2, 1, &section);
425425
#endif
426426
if (amount < 0) {
427427
set_ov_error("ov_read", amount);

0 commit comments

Comments
 (0)