music.c
changeset 855 a7dee77dd60f
parent 848 3907db698eb5
child 861 671a669e1065
     1.1 --- a/music.c	Tue Jun 12 13:45:37 2018 +0300
     1.2 +++ b/music.c	Fri Jun 15 08:32:56 2018 +0300
     1.3 @@ -36,6 +36,7 @@
     1.4  #include "music_fluidsynth.h"
     1.5  #include "music_timidity.h"
     1.6  #include "music_ogg.h"
     1.7 +#include "music_opus.h"
     1.8  #include "music_mpg123.h"
     1.9  #include "music_mad.h"
    1.10  #include "music_smpeg.h"
    1.11 @@ -92,6 +93,9 @@
    1.12  #ifdef MUSIC_OGG
    1.13      &Mix_MusicInterface_OGG,
    1.14  #endif
    1.15 +#ifdef MUSIC_OPUS
    1.16 +    &Mix_MusicInterface_Opus,
    1.17 +#endif
    1.18  #ifdef MUSIC_MP3_MPG123
    1.19      &Mix_MusicInterface_MPG123,
    1.20  #endif
    1.21 @@ -354,6 +358,10 @@
    1.22          add_music_decoder("OGG");
    1.23          add_chunk_decoder("OGG");
    1.24      }
    1.25 +    if (has_music(MUS_OPUS)) {
    1.26 +        add_music_decoder("OPUS");
    1.27 +        add_chunk_decoder("OPUS");
    1.28 +    }
    1.29      if (has_music(MUS_MP3)) {
    1.30          add_music_decoder("MP3");
    1.31          add_chunk_decoder("MP3");
    1.32 @@ -438,6 +446,7 @@
    1.33  static Mix_MusicType detect_music_type(SDL_RWops *src)
    1.34  {
    1.35      Uint8 magic[12];
    1.36 +    Mix_MusicType t;
    1.37  
    1.38      if (SDL_RWread(src, magic, 1, 12) != 12) {
    1.39          Mix_SetError("Couldn't read first 12 bytes of audio data");
    1.40 @@ -451,8 +460,17 @@
    1.41          (SDL_memcmp(magic, "FORM", 4) == 0)) {
    1.42          return MUS_WAV;
    1.43      }
    1.44 -
    1.45 -    return detect_music_type_from_magic(magic);
    1.46 +    t = detect_music_type_from_magic(magic);
    1.47 +    if (t == MUS_OGG) {
    1.48 +        Sint64 pos = SDL_RWtell(src);
    1.49 +        SDL_RWseek(src, 28, RW_SEEK_CUR);
    1.50 +        SDL_RWread(src, magic, 1, 8);
    1.51 +        SDL_RWseek(src, pos, RW_SEEK_SET);
    1.52 +        if (SDL_memcmp(magic, "OpusHead", 8) == 0) {
    1.53 +            return MUS_OPUS;
    1.54 +        }
    1.55 +    }
    1.56 +    return t;
    1.57  }
    1.58  
    1.59  /* Load a music file */
    1.60 @@ -503,6 +521,8 @@
    1.61              type = MUS_MID;
    1.62          } else if (SDL_strcasecmp(ext, "OGG") == 0) {
    1.63              type = MUS_OGG;
    1.64 +        } else if (SDL_strcasecmp(ext, "OPUS") == 0) {
    1.65 +            type = MUS_OPUS;
    1.66          } else if (SDL_strcasecmp(ext, "FLAC") == 0) {
    1.67              type = MUS_FLAC;
    1.68          } else  if (SDL_strcasecmp(ext, "MPG") == 0 ||