dynamic_mp3.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 02 Jan 2016 22:12:31 -0800
changeset 712 7e59d684b070
parent 711 f40c5ac95b12
child 725 bdf7b8d20566
permissions -rw-r--r--
Updated to version 2.0.1
     1 /*
     2   SDL_mixer:  An audio mixer library based on the SDL library
     3   Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 #ifdef MP3_MUSIC
    23 
    24 #include "SDL_loadso.h"
    25 #include "SDL_mixer.h"
    26 #include "dynamic_mp3.h"
    27 
    28 smpeg_loader smpeg = {
    29     0, NULL
    30 };
    31 
    32 #ifdef MP3_DYNAMIC
    33 int Mix_InitMP3()
    34 {
    35     if ( smpeg.loaded == 0 ) {
    36         smpeg.handle = SDL_LoadObject(MP3_DYNAMIC);
    37         if ( smpeg.handle == NULL ) {
    38             return -1;
    39         }
    40         smpeg.SMPEG_actualSpec =
    41             (void (*)( SMPEG *, SDL_AudioSpec * ))
    42             SDL_LoadFunction(smpeg.handle, "SMPEG_actualSpec");
    43         if ( smpeg.SMPEG_actualSpec == NULL ) {
    44             SDL_UnloadObject(smpeg.handle);
    45             return -1;
    46         }
    47         smpeg.SMPEG_delete =
    48             (void (*)( SMPEG* ))
    49             SDL_LoadFunction(smpeg.handle, "SMPEG_delete");
    50         if ( smpeg.SMPEG_delete == NULL ) {
    51             SDL_UnloadObject(smpeg.handle);
    52             return -1;
    53         }
    54         smpeg.SMPEG_enableaudio =
    55             (void (*)( SMPEG*, int ))
    56             SDL_LoadFunction(smpeg.handle, "SMPEG_enableaudio");
    57         if ( smpeg.SMPEG_enableaudio == NULL ) {
    58             SDL_UnloadObject(smpeg.handle);
    59             return -1;
    60         }
    61         smpeg.SMPEG_enablevideo =
    62             (void (*)( SMPEG*, int ))
    63             SDL_LoadFunction(smpeg.handle, "SMPEG_enablevideo");
    64         if ( smpeg.SMPEG_enablevideo == NULL ) {
    65             SDL_UnloadObject(smpeg.handle);
    66             return -1;
    67         }
    68         smpeg.SMPEG_new_rwops =
    69             (SMPEG* (*)(SDL_RWops *, SMPEG_Info*, int, int))
    70             SDL_LoadFunction(smpeg.handle, "SMPEG_new_rwops");
    71         if ( smpeg.SMPEG_new_rwops == NULL ) {
    72             SDL_UnloadObject(smpeg.handle);
    73             return -1;
    74         }
    75         smpeg.SMPEG_play =
    76             (void (*)( SMPEG* ))
    77             SDL_LoadFunction(smpeg.handle, "SMPEG_play");
    78         if ( smpeg.SMPEG_play == NULL ) {
    79             SDL_UnloadObject(smpeg.handle);
    80             return -1;
    81         }
    82         smpeg.SMPEG_playAudio =
    83             (int (*)( SMPEG *, Uint8 *, int ))
    84             SDL_LoadFunction(smpeg.handle, "SMPEG_playAudio");
    85         if ( smpeg.SMPEG_playAudio == NULL ) {
    86             SDL_UnloadObject(smpeg.handle);
    87             return -1;
    88         }
    89         smpeg.SMPEG_rewind =
    90             (void (*)( SMPEG* ))
    91             SDL_LoadFunction(smpeg.handle, "SMPEG_rewind");
    92         if ( smpeg.SMPEG_rewind == NULL ) {
    93             SDL_UnloadObject(smpeg.handle);
    94             return -1;
    95         }
    96         smpeg.SMPEG_setvolume =
    97             (void (*)( SMPEG*, int ))
    98             SDL_LoadFunction(smpeg.handle, "SMPEG_setvolume");
    99         if ( smpeg.SMPEG_setvolume == NULL ) {
   100             SDL_UnloadObject(smpeg.handle);
   101             return -1;
   102         }
   103         smpeg.SMPEG_skip =
   104             (void (*)( SMPEG*, float ))
   105             SDL_LoadFunction(smpeg.handle, "SMPEG_skip");
   106         if ( smpeg.SMPEG_skip == NULL ) {
   107             SDL_UnloadObject(smpeg.handle);
   108             return -1;
   109         }
   110         smpeg.SMPEG_status =
   111             (SMPEGstatus (*)( SMPEG* ))
   112             SDL_LoadFunction(smpeg.handle, "SMPEG_status");
   113         if ( smpeg.SMPEG_status == NULL ) {
   114             SDL_UnloadObject(smpeg.handle);
   115             return -1;
   116         }
   117         smpeg.SMPEG_stop =
   118             (void (*)( SMPEG* ))
   119             SDL_LoadFunction(smpeg.handle, "SMPEG_stop");
   120         if ( smpeg.SMPEG_stop == NULL ) {
   121             SDL_UnloadObject(smpeg.handle);
   122             return -1;
   123         }
   124     }
   125     ++smpeg.loaded;
   126 
   127     return 0;
   128 }
   129 void Mix_QuitMP3()
   130 {
   131     if ( smpeg.loaded == 0 ) {
   132         return;
   133     }
   134     if ( smpeg.loaded == 1 ) {
   135         SDL_UnloadObject(smpeg.handle);
   136     }
   137     --smpeg.loaded;
   138 }
   139 #else
   140 int Mix_InitMP3()
   141 {
   142     if ( smpeg.loaded == 0 ) {
   143 #ifdef __MACOSX__
   144         extern SMPEG* SMPEG_new_rwops(SDL_RWops*, SMPEG_Info*, int, int) __attribute__((weak_import));
   145         if ( SMPEG_new_rwops == NULL )
   146         {
   147             /* Missing weakly linked framework */
   148             Mix_SetError("Missing smpeg2.framework");
   149             return -1;
   150         }
   151 #endif // __MACOSX__
   152 
   153         smpeg.SMPEG_actualSpec = SMPEG_actualSpec;
   154         smpeg.SMPEG_delete = SMPEG_delete;
   155         smpeg.SMPEG_enableaudio = SMPEG_enableaudio;
   156         smpeg.SMPEG_enablevideo = SMPEG_enablevideo;
   157         smpeg.SMPEG_new_rwops = SMPEG_new_rwops;
   158         smpeg.SMPEG_play = SMPEG_play;
   159         smpeg.SMPEG_playAudio = SMPEG_playAudio;
   160         smpeg.SMPEG_rewind = SMPEG_rewind;
   161         smpeg.SMPEG_setvolume = SMPEG_setvolume;
   162         smpeg.SMPEG_skip = SMPEG_skip;
   163         smpeg.SMPEG_status = SMPEG_status;
   164         smpeg.SMPEG_stop = SMPEG_stop;
   165     }
   166     ++smpeg.loaded;
   167 
   168     return 0;
   169 }
   170 void Mix_QuitMP3()
   171 {
   172     if ( smpeg.loaded == 0 ) {
   173         return;
   174     }
   175     if ( smpeg.loaded == 1 ) {
   176     }
   177     --smpeg.loaded;
   178 }
   179 #endif /* MP3_DYNAMIC */
   180 
   181 #endif /* MP3_MUSIC */