music.c
changeset 757 420f3b37dc95
parent 725 bdf7b8d20566
child 762 6c6adcc85536
     1.1 --- a/music.c	Thu Oct 12 21:38:45 2017 -0700
     1.2 +++ b/music.c	Thu Jul 20 22:03:19 2017 +0200
     1.3 @@ -64,11 +64,14 @@
     1.4  #ifdef MP3_MAD_MUSIC
     1.5  #include "music_mad.h"
     1.6  #endif
     1.7 +#ifdef MP3_MPG_MUSIC
     1.8 +#include "music_mpg.h"
     1.9 +#endif
    1.10  #ifdef FLAC_MUSIC
    1.11  #include "music_flac.h"
    1.12  #endif
    1.13  
    1.14 -#if defined(MP3_MUSIC) || defined(MP3_MAD_MUSIC)
    1.15 +#if defined(MP3_MUSIC) || defined(MP3_MAD_MUSIC) || defined(MP3_MPG_MUSIC)
    1.16  static SDL_AudioSpec used_mixer;
    1.17  #endif
    1.18  
    1.19 @@ -115,6 +118,9 @@
    1.20  #ifdef MP3_MAD_MUSIC
    1.21          mad_data *mp3_mad;
    1.22  #endif
    1.23 +#ifdef MP3_MPG_MUSIC
    1.24 +        mpg_data *mp3_mpg;
    1.25 +#endif
    1.26  #ifdef FLAC_MUSIC
    1.27          FLAC_music *flac;
    1.28  #endif
    1.29 @@ -333,6 +339,11 @@
    1.30                  left = mad_getSamples(music_playing->data.mp3_mad, stream, len);
    1.31                  break;
    1.32  #endif
    1.33 +#ifdef MP3_MPG_MUSIC
    1.34 +            case MUS_MP3_MPG:
    1.35 +                left = mpg_get_samples(music_playing->data.mp3_mpg, stream, len);
    1.36 +                break;
    1.37 +#endif
    1.38              default:
    1.39                  /* Unknown music type?? */
    1.40                  break;
    1.41 @@ -412,7 +423,7 @@
    1.42          add_music_decoder("FLAC");
    1.43      }
    1.44  #endif
    1.45 -#if defined(MP3_MUSIC) || defined(MP3_MAD_MUSIC)
    1.46 +#if defined(MP3_MUSIC) || defined(MP3_MAD_MUSIC) || defined(MP3_MPG_MUSIC)
    1.47      /* Keep a copy of the mixer */
    1.48      used_mixer = *mixer;
    1.49      add_music_decoder("MP3");
    1.50 @@ -678,6 +689,16 @@
    1.51              Mix_SetError("Could not initialize MPEG stream.");
    1.52          }
    1.53          break;
    1.54 +#elif defined(MP3_MPG_MUSIC)
    1.55 +    case MUS_MP3:
    1.56 +        music->type = MUS_MP3_MPG;
    1.57 +        music->data.mp3_mpg = mpg_new_rw(src, &used_mixer, freesrc);
    1.58 +        if (music->data.mp3_mpg) {
    1.59 +            music->error = 0;
    1.60 +        } else {
    1.61 +            Mix_SetError("Could not initialize MPEG stream.");
    1.62 +        }
    1.63 +        break;
    1.64  #endif
    1.65  #ifdef MID_MUSIC
    1.66      case MUS_MID:
    1.67 @@ -842,6 +863,11 @@
    1.68                  mad_closeFile(music->data.mp3_mad);
    1.69                  break;
    1.70  #endif
    1.71 +#ifdef MP3_MPG_MUSIC
    1.72 +            case MUS_MP3_MPG:
    1.73 +                mpg_delete(music->data.mp3_mpg);
    1.74 +                break;
    1.75 +#endif
    1.76              default:
    1.77                  /* Unknown music type?? */
    1.78                  break;
    1.79 @@ -969,6 +995,11 @@
    1.80          mad_start(music->data.mp3_mad);
    1.81          break;
    1.82  #endif
    1.83 +#ifdef MP3_MPG_MUSIC
    1.84 +        case MUS_MP3_MPG:
    1.85 +        mpg_start(music->data.mp3_mpg);
    1.86 +        break;
    1.87 +#endif
    1.88          default:
    1.89          Mix_SetError("Can't play unknown music type");
    1.90          retval = -1;
    1.91 @@ -1086,6 +1117,11 @@
    1.92          mad_seek(music_playing->data.mp3_mad, position);
    1.93          break;
    1.94  #endif
    1.95 +#ifdef MP3_MPG_MUSIC
    1.96 +        case MUS_MP3_MPG:
    1.97 +        mpg_seek(music_playing->data.mp3_mpg, position);
    1.98 +        break;
    1.99 +#endif
   1.100          default:
   1.101          /* TODO: Implement this for other music backends */
   1.102          retval = -1;
   1.103 @@ -1188,6 +1224,11 @@
   1.104          mad_setVolume(music_playing->data.mp3_mad, volume);
   1.105          break;
   1.106  #endif
   1.107 +#ifdef MP3_MPG_MUSIC
   1.108 +        case MUS_MP3_MPG:
   1.109 +        mpg_volume(music_playing->data.mp3_mpg, volume);
   1.110 +        break;
   1.111 +#endif
   1.112          default:
   1.113          /* Unknown music type?? */
   1.114          break;
   1.115 @@ -1279,6 +1320,11 @@
   1.116          mad_stop(music_playing->data.mp3_mad);
   1.117          break;
   1.118  #endif
   1.119 +#ifdef MP3_MPG_MUSIC
   1.120 +        case MUS_MP3_MPG:
   1.121 +        mpg_stop(music_playing->data.mp3_mpg);
   1.122 +        break;
   1.123 +#endif
   1.124          default:
   1.125          /* Unknown music type?? */
   1.126          return;
   1.127 @@ -1467,6 +1513,13 @@
   1.128          }
   1.129          break;
   1.130  #endif
   1.131 +#ifdef MP3_MPG_MUSIC
   1.132 +        case MUS_MP3_MPG:
   1.133 +        if (!mpg_playing(music_playing->data.mp3_mpg)) {
   1.134 +            playing = 0;
   1.135 +        }
   1.136 +        break;
   1.137 +#endif
   1.138          default:
   1.139          playing = 0;
   1.140          break;