Skip to content

Commit

Permalink
music_ogg: provide audio using the host endianness
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sergiou87 committed Jun 15, 2020
1 parent 23a2b71 commit fb3af0e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/codecs/music_ogg.c
Expand Up @@ -215,7 +215,7 @@ static int OGG_UpdateSection(OGG_music *music)
music->stream = NULL;
}

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

0 comments on commit fb3af0e

Please sign in to comment.