music_mod.c
changeset 628 461e2724372b
parent 621 944412baab72
child 711 f40c5ac95b12
     1.1 --- a/music_mod.c	Sat Jun 01 22:30:04 2013 -0700
     1.2 +++ b/music_mod.c	Sat Jun 01 23:42:48 2013 -0700
     1.3 @@ -146,7 +146,7 @@
     1.4      MREADER mr;
     1.5      Sint64 offset;
     1.6      Sint64 eof;
     1.7 -    SDL_RWops *rw;
     1.8 +    SDL_RWops *src;
     1.9  } LMM_MREADER;
    1.10  
    1.11  BOOL LMM_Seek(struct MREADER *mr,long to,int dir)
    1.12 @@ -156,35 +156,35 @@
    1.13      if ( dir == SEEK_SET ) {
    1.14          offset += lmmmr->offset;
    1.15      }
    1.16 -    return (SDL_RWseek(lmmmr->rw, offset, dir) < lmmmr->offset);
    1.17 +    return (SDL_RWseek(lmmmr->src, offset, dir) < lmmmr->offset);
    1.18  }
    1.19  long LMM_Tell(struct MREADER *mr)
    1.20  {
    1.21      LMM_MREADER* lmmmr = (LMM_MREADER*)mr;
    1.22 -    return (long)(SDL_RWtell(lmmmr->rw) - lmmmr->offset);
    1.23 +    return (long)(SDL_RWtell(lmmmr->src) - lmmmr->offset);
    1.24  }
    1.25  BOOL LMM_Read(struct MREADER *mr,void *buf,size_t sz)
    1.26  {
    1.27      LMM_MREADER* lmmmr = (LMM_MREADER*)mr;
    1.28 -    return SDL_RWread(lmmmr->rw, buf, sz, 1);
    1.29 +    return SDL_RWread(lmmmr->src, buf, sz, 1);
    1.30  }
    1.31  int LMM_Get(struct MREADER *mr)
    1.32  {
    1.33      unsigned char c;
    1.34      LMM_MREADER* lmmmr = (LMM_MREADER*)mr;
    1.35 -    if ( SDL_RWread(lmmmr->rw, &c, 1, 1) ) {
    1.36 +    if ( SDL_RWread(lmmmr->src, &c, 1, 1) ) {
    1.37          return c;
    1.38      }
    1.39      return EOF;
    1.40  }
    1.41  BOOL LMM_Eof(struct MREADER *mr)
    1.42  {
    1.43 -    long offset;
    1.44 +    Sint64 offset;
    1.45      LMM_MREADER* lmmmr = (LMM_MREADER*)mr;
    1.46      offset = LMM_Tell(mr);
    1.47      return offset >= lmmmr->eof;
    1.48  }
    1.49 -MODULE *MikMod_LoadSongRW(SDL_RWops *rw, int maxchan)
    1.50 +MODULE *MikMod_LoadSongRW(SDL_RWops *src, int maxchan)
    1.51  {
    1.52      LMM_MREADER lmmmr = {
    1.53          { LMM_Seek, LMM_Tell, LMM_Read, LMM_Get, LMM_Eof },
    1.54 @@ -192,33 +192,27 @@
    1.55          0,
    1.56          0
    1.57      };
    1.58 -    lmmmr.offset = SDL_RWtell(rw);
    1.59 -    SDL_RWseek(rw, 0, RW_SEEK_END);
    1.60 -    lmmmr.eof = SDL_RWtell(rw);
    1.61 -    SDL_RWseek(rw, lmmmr.offset, RW_SEEK_SET);
    1.62 -        lmmmr.rw = rw;
    1.63 +    lmmmr.offset = SDL_RWtell(src);
    1.64 +    SDL_RWseek(src, 0, RW_SEEK_END);
    1.65 +    lmmmr.eof = SDL_RWtell(src);
    1.66 +    SDL_RWseek(src, lmmmr.offset, RW_SEEK_SET);
    1.67 +    lmmmr.src = src;
    1.68      return mikmod.Player_LoadGeneric((MREADER*)&lmmmr, maxchan, 0);
    1.69  }
    1.70  
    1.71  /* Load a MOD stream from an SDL_RWops object */
    1.72 -MODULE *MOD_new_RW(SDL_RWops *rw, int freerw)
    1.73 +MODULE *MOD_new_RW(SDL_RWops *src, int freesrc)
    1.74  {
    1.75      MODULE *module;
    1.76  
    1.77      /* Make sure the mikmod library is loaded */
    1.78      if ( !Mix_Init(MIX_INIT_MOD) ) {
    1.79 -        if ( freerw ) {
    1.80 -            SDL_RWclose(rw);
    1.81 -        }
    1.82          return NULL;
    1.83      }
    1.84  
    1.85 -    module = MikMod_LoadSongRW(rw,64);
    1.86 +    module = MikMod_LoadSongRW(src, 64);
    1.87      if (!module) {
    1.88          Mix_SetError("%s", mikmod.MikMod_strerror(*mikmod.MikMod_errno));
    1.89 -        if ( freerw ) {
    1.90 -            SDL_RWclose(rw);
    1.91 -        }
    1.92          return NULL;
    1.93      }
    1.94  
    1.95 @@ -232,8 +226,8 @@
    1.96      module->fadeout = 1;
    1.97  #endif
    1.98  
    1.99 -    if ( freerw ) {
   1.100 -        SDL_RWclose(rw);
   1.101 +    if ( freesrc ) {
   1.102 +        SDL_RWclose(src);
   1.103      }
   1.104      return module;
   1.105  }