dynamic_mp3.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 08 Nov 2009 18:40:07 +0000
changeset 474 a2c238c0c4b2
parent 472 463ba3222193
child 518 8bc9b5fd2aae
permissions -rw-r--r--
Don't break binary compatibility!
     1 /*
     2     SDL_mixer:  An audio mixer library based on the SDL library
     3     Copyright (C) 1997-2009 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Library General Public
     7     License as published by the Free Software Foundation; either
     8     version 2 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Library General Public License for more details.
    14 
    15     You should have received a copy of the GNU Library General Public
    16     License along with this library; if not, write to the Free
    17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 #ifdef MP3_MUSIC
    24 
    25 #include "SDL_loadso.h"
    26 
    27 #include "dynamic_mp3.h"
    28 
    29 smpeg_loader smpeg = {
    30 	0, NULL
    31 };
    32 
    33 #ifdef MP3_DYNAMIC
    34 int Mix_InitMP3()
    35 {
    36 	if ( smpeg.loaded == 0 ) {
    37 		smpeg.handle = SDL_LoadObject(MP3_DYNAMIC);
    38 		if ( smpeg.handle == NULL ) {
    39 			return -1;
    40 		}
    41 		smpeg.SMPEG_actualSpec =
    42 			(void (*)( SMPEG *, SDL_AudioSpec * ))
    43 			SDL_LoadFunction(smpeg.handle, "SMPEG_actualSpec");
    44 		if ( smpeg.SMPEG_actualSpec == NULL ) {
    45 			SDL_UnloadObject(smpeg.handle);
    46 			return -1;
    47 		}
    48 		smpeg.SMPEG_delete =
    49 			(void (*)( SMPEG* ))
    50 			SDL_LoadFunction(smpeg.handle, "SMPEG_delete");
    51 		if ( smpeg.SMPEG_delete == NULL ) {
    52 			SDL_UnloadObject(smpeg.handle);
    53 			return -1;
    54 		}
    55 		smpeg.SMPEG_enableaudio =
    56 			(void (*)( SMPEG*, int ))
    57 			SDL_LoadFunction(smpeg.handle, "SMPEG_enableaudio");
    58 		if ( smpeg.SMPEG_enableaudio == NULL ) {
    59 			SDL_UnloadObject(smpeg.handle);
    60 			return -1;
    61 		}
    62 		smpeg.SMPEG_enablevideo =
    63 			(void (*)( SMPEG*, int ))
    64 			SDL_LoadFunction(smpeg.handle, "SMPEG_enablevideo");
    65 		if ( smpeg.SMPEG_enablevideo == NULL ) {
    66 			SDL_UnloadObject(smpeg.handle);
    67 			return -1;
    68 		}
    69 		smpeg.SMPEG_new =
    70 			(SMPEG* (*)(const char *, SMPEG_Info*, int))
    71 			SDL_LoadFunction(smpeg.handle, "SMPEG_new");
    72 		if ( smpeg.SMPEG_new == NULL ) {
    73 			SDL_UnloadObject(smpeg.handle);
    74 			return -1;
    75 		}
    76 		smpeg.SMPEG_new_rwops =
    77 			(SMPEG* (*)(SDL_RWops *, SMPEG_Info*, int))
    78 			SDL_LoadFunction(smpeg.handle, "SMPEG_new_rwops");
    79 		if ( smpeg.SMPEG_new_rwops == NULL ) {
    80 			SDL_UnloadObject(smpeg.handle);
    81 			return -1;
    82 		}
    83 		smpeg.SMPEG_play =
    84 			(void (*)( SMPEG* ))
    85 			SDL_LoadFunction(smpeg.handle, "SMPEG_play");
    86 		if ( smpeg.SMPEG_play == NULL ) {
    87 			SDL_UnloadObject(smpeg.handle);
    88 			return -1;
    89 		}
    90 		smpeg.SMPEG_playAudio =
    91 			(int (*)( SMPEG *, Uint8 *, int ))
    92 			SDL_LoadFunction(smpeg.handle, "SMPEG_playAudio");
    93 		if ( smpeg.SMPEG_playAudio == NULL ) {
    94 			SDL_UnloadObject(smpeg.handle);
    95 			return -1;
    96 		}
    97 		smpeg.SMPEG_rewind =
    98 			(void (*)( SMPEG* ))
    99 			SDL_LoadFunction(smpeg.handle, "SMPEG_rewind");
   100 		if ( smpeg.SMPEG_rewind == NULL ) {
   101 			SDL_UnloadObject(smpeg.handle);
   102 			return -1;
   103 		}
   104 		smpeg.SMPEG_setvolume =
   105 			(void (*)( SMPEG*, int ))
   106 			SDL_LoadFunction(smpeg.handle, "SMPEG_setvolume");
   107 		if ( smpeg.SMPEG_setvolume == NULL ) {
   108 			SDL_UnloadObject(smpeg.handle);
   109 			return -1;
   110 		}
   111 		smpeg.SMPEG_skip =
   112 			(void (*)( SMPEG*, float ))
   113 			SDL_LoadFunction(smpeg.handle, "SMPEG_skip");
   114 		if ( smpeg.SMPEG_skip == NULL ) {
   115 			SDL_UnloadObject(smpeg.handle);
   116 			return -1;
   117 		}
   118 		smpeg.SMPEG_status =
   119 			(SMPEGstatus (*)( SMPEG* ))
   120 			SDL_LoadFunction(smpeg.handle, "SMPEG_status");
   121 		if ( smpeg.SMPEG_status == NULL ) {
   122 			SDL_UnloadObject(smpeg.handle);
   123 			return -1;
   124 		}
   125 		smpeg.SMPEG_stop =
   126 			(void (*)( SMPEG* ))
   127 			SDL_LoadFunction(smpeg.handle, "SMPEG_stop");
   128 		if ( smpeg.SMPEG_stop == NULL ) {
   129 			SDL_UnloadObject(smpeg.handle);
   130 			return -1;
   131 		}
   132 	}
   133 	++smpeg.loaded;
   134 
   135 	return 0;
   136 }
   137 void Mix_QuitMP3()
   138 {
   139 	if ( smpeg.loaded == 0 ) {
   140 		return;
   141 	}
   142 	if ( smpeg.loaded == 1 ) {
   143 		SDL_UnloadObject(smpeg.handle);
   144 	}
   145 	--smpeg.loaded;
   146 }
   147 #else
   148 int Mix_InitMP3()
   149 {
   150 	if ( smpeg.loaded == 0 ) {
   151 		smpeg.SMPEG_actualSpec = SMPEG_actualSpec;
   152 		smpeg.SMPEG_delete = SMPEG_delete;
   153 		smpeg.SMPEG_enableaudio = SMPEG_enableaudio;
   154 		smpeg.SMPEG_enablevideo = SMPEG_enablevideo;
   155 		smpeg.SMPEG_new = SMPEG_new;
   156 		smpeg.SMPEG_new_rwops = SMPEG_new_rwops;
   157 		smpeg.SMPEG_play = SMPEG_play;
   158 		smpeg.SMPEG_playAudio = SMPEG_playAudio;
   159 		smpeg.SMPEG_rewind = SMPEG_rewind;
   160 		smpeg.SMPEG_setvolume = SMPEG_setvolume;
   161 		smpeg.SMPEG_skip = SMPEG_skip;
   162 		smpeg.SMPEG_status = SMPEG_status;
   163 		smpeg.SMPEG_stop = SMPEG_stop;
   164 	}
   165 	++smpeg.loaded;
   166 
   167 	return 0;
   168 }
   169 void Mix_QuitMP3()
   170 {
   171 	if ( smpeg.loaded == 0 ) {
   172 		return;
   173 	}
   174 	if ( smpeg.loaded == 1 ) {
   175 	}
   176 	--smpeg.loaded;
   177 }
   178 #endif /* MP3_DYNAMIC */
   179 
   180 #endif /* MP3_MUSIC */