dynamic_mp3.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 31 Dec 2011 23:28:23 -0500
changeset 528 bc0dfe8ae026
parent 518 8bc9b5fd2aae
child 542 3de4970b36d4
permissions -rw-r--r--
Backed out changeset 1eddea51f162
     1 /*
     2   SDL_mixer:  An audio mixer library based on the SDL library
     3   Copyright (C) 1997-2012 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 
    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 =
    69 			(SMPEG* (*)(const char *, SMPEG_Info*, int))
    70 			SDL_LoadFunction(smpeg.handle, "SMPEG_new");
    71 		if ( smpeg.SMPEG_new == NULL ) {
    72 			SDL_UnloadObject(smpeg.handle);
    73 			return -1;
    74 		}
    75 		smpeg.SMPEG_new_rwops =
    76 			(SMPEG* (*)(SDL_RWops *, SMPEG_Info*, int))
    77 			SDL_LoadFunction(smpeg.handle, "SMPEG_new_rwops");
    78 		if ( smpeg.SMPEG_new_rwops == NULL ) {
    79 			SDL_UnloadObject(smpeg.handle);
    80 			return -1;
    81 		}
    82 		smpeg.SMPEG_play =
    83 			(void (*)( SMPEG* ))
    84 			SDL_LoadFunction(smpeg.handle, "SMPEG_play");
    85 		if ( smpeg.SMPEG_play == NULL ) {
    86 			SDL_UnloadObject(smpeg.handle);
    87 			return -1;
    88 		}
    89 		smpeg.SMPEG_playAudio =
    90 			(int (*)( SMPEG *, Uint8 *, int ))
    91 			SDL_LoadFunction(smpeg.handle, "SMPEG_playAudio");
    92 		if ( smpeg.SMPEG_playAudio == NULL ) {
    93 			SDL_UnloadObject(smpeg.handle);
    94 			return -1;
    95 		}
    96 		smpeg.SMPEG_rewind =
    97 			(void (*)( SMPEG* ))
    98 			SDL_LoadFunction(smpeg.handle, "SMPEG_rewind");
    99 		if ( smpeg.SMPEG_rewind == NULL ) {
   100 			SDL_UnloadObject(smpeg.handle);
   101 			return -1;
   102 		}
   103 		smpeg.SMPEG_setvolume =
   104 			(void (*)( SMPEG*, int ))
   105 			SDL_LoadFunction(smpeg.handle, "SMPEG_setvolume");
   106 		if ( smpeg.SMPEG_setvolume == NULL ) {
   107 			SDL_UnloadObject(smpeg.handle);
   108 			return -1;
   109 		}
   110 		smpeg.SMPEG_skip =
   111 			(void (*)( SMPEG*, float ))
   112 			SDL_LoadFunction(smpeg.handle, "SMPEG_skip");
   113 		if ( smpeg.SMPEG_skip == NULL ) {
   114 			SDL_UnloadObject(smpeg.handle);
   115 			return -1;
   116 		}
   117 		smpeg.SMPEG_status =
   118 			(SMPEGstatus (*)( SMPEG* ))
   119 			SDL_LoadFunction(smpeg.handle, "SMPEG_status");
   120 		if ( smpeg.SMPEG_status == NULL ) {
   121 			SDL_UnloadObject(smpeg.handle);
   122 			return -1;
   123 		}
   124 		smpeg.SMPEG_stop =
   125 			(void (*)( SMPEG* ))
   126 			SDL_LoadFunction(smpeg.handle, "SMPEG_stop");
   127 		if ( smpeg.SMPEG_stop == NULL ) {
   128 			SDL_UnloadObject(smpeg.handle);
   129 			return -1;
   130 		}
   131 	}
   132 	++smpeg.loaded;
   133 
   134 	return 0;
   135 }
   136 void Mix_QuitMP3()
   137 {
   138 	if ( smpeg.loaded == 0 ) {
   139 		return;
   140 	}
   141 	if ( smpeg.loaded == 1 ) {
   142 		SDL_UnloadObject(smpeg.handle);
   143 	}
   144 	--smpeg.loaded;
   145 }
   146 #else
   147 int Mix_InitMP3()
   148 {
   149 	if ( smpeg.loaded == 0 ) {
   150 		smpeg.SMPEG_actualSpec = SMPEG_actualSpec;
   151 		smpeg.SMPEG_delete = SMPEG_delete;
   152 		smpeg.SMPEG_enableaudio = SMPEG_enableaudio;
   153 		smpeg.SMPEG_enablevideo = SMPEG_enablevideo;
   154 		smpeg.SMPEG_new = SMPEG_new;
   155 		smpeg.SMPEG_new_rwops = SMPEG_new_rwops;
   156 		smpeg.SMPEG_play = SMPEG_play;
   157 		smpeg.SMPEG_playAudio = SMPEG_playAudio;
   158 		smpeg.SMPEG_rewind = SMPEG_rewind;
   159 		smpeg.SMPEG_setvolume = SMPEG_setvolume;
   160 		smpeg.SMPEG_skip = SMPEG_skip;
   161 		smpeg.SMPEG_status = SMPEG_status;
   162 		smpeg.SMPEG_stop = SMPEG_stop;
   163 	}
   164 	++smpeg.loaded;
   165 
   166 	return 0;
   167 }
   168 void Mix_QuitMP3()
   169 {
   170 	if ( smpeg.loaded == 0 ) {
   171 		return;
   172 	}
   173 	if ( smpeg.loaded == 1 ) {
   174 	}
   175 	--smpeg.loaded;
   176 }
   177 #endif /* MP3_DYNAMIC */
   178 
   179 #endif /* MP3_MUSIC */