dynamic_mp3.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 09 Jan 2012 07:34:10 -0500
changeset 558 7915d5cc775a
parent 542 3de4970b36d4
child 601 05123263dab3
child 902 6c862e733898
permissions -rw-r--r--
Fixed version of smpeg.dll that doesn't dynamically link to libstdc++-6.dll
     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_rwops =
    69 			(SMPEG* (*)(SDL_RWops *, SMPEG_Info*, 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 		smpeg.SMPEG_actualSpec = SMPEG_actualSpec;
   144 		smpeg.SMPEG_delete = SMPEG_delete;
   145 		smpeg.SMPEG_enableaudio = SMPEG_enableaudio;
   146 		smpeg.SMPEG_enablevideo = SMPEG_enablevideo;
   147 		smpeg.SMPEG_new_rwops = SMPEG_new_rwops;
   148 		smpeg.SMPEG_play = SMPEG_play;
   149 		smpeg.SMPEG_playAudio = SMPEG_playAudio;
   150 		smpeg.SMPEG_rewind = SMPEG_rewind;
   151 		smpeg.SMPEG_setvolume = SMPEG_setvolume;
   152 		smpeg.SMPEG_skip = SMPEG_skip;
   153 		smpeg.SMPEG_status = SMPEG_status;
   154 		smpeg.SMPEG_stop = SMPEG_stop;
   155 	}
   156 	++smpeg.loaded;
   157 
   158 	return 0;
   159 }
   160 void Mix_QuitMP3()
   161 {
   162 	if ( smpeg.loaded == 0 ) {
   163 		return;
   164 	}
   165 	if ( smpeg.loaded == 1 ) {
   166 	}
   167 	--smpeg.loaded;
   168 }
   169 #endif /* MP3_DYNAMIC */
   170 
   171 #endif /* MP3_MUSIC */