dynamic_mod.c
author Ozkan Sezer <sezeroz@gmail.com>
Sat, 06 Oct 2018 23:20:10 +0300
branchSDL-1.2
changeset 865 3ffb22a2755b
parent 518 8bc9b5fd2aae
child 940 36238c70b819
permissions -rw-r--r--
multiple mikmod player fixes from default (2.0) branch
     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 MOD_MUSIC
    23 
    24 #include "SDL_loadso.h"
    25 
    26 #include "dynamic_mod.h"
    27 
    28 mikmod_loader mikmod = {
    29 	0, NULL
    30 };
    31 
    32 #ifdef MOD_DYNAMIC
    33 int Mix_InitMOD()
    34 {
    35 	if ( mikmod.loaded == 0 ) {
    36 		mikmod.handle = SDL_LoadObject(MOD_DYNAMIC);
    37 		if ( mikmod.handle == NULL ) {
    38 			return -1;
    39 		}
    40 		mikmod.MikMod_Exit =
    41 			(void (*)(void))
    42 			SDL_LoadFunction(mikmod.handle, "MikMod_Exit");
    43 		if ( mikmod.MikMod_Exit == NULL ) {
    44 			SDL_UnloadObject(mikmod.handle);
    45 			return -1;
    46 		}
    47 		mikmod.MikMod_InfoDriver =
    48 			(CHAR* (*)(void))
    49 			SDL_LoadFunction(mikmod.handle, "MikMod_InfoDriver");
    50 		if ( mikmod.MikMod_InfoDriver == NULL ) {
    51 			SDL_UnloadObject(mikmod.handle);
    52 			return -1;
    53 		}
    54 		mikmod.MikMod_InfoLoader =
    55 			(CHAR* (*)(void))
    56 			SDL_LoadFunction(mikmod.handle, "MikMod_InfoLoader");
    57 		if ( mikmod.MikMod_InfoLoader == NULL ) {
    58 			SDL_UnloadObject(mikmod.handle);
    59 			return -1;
    60 		}
    61 		mikmod.MikMod_Init =
    62 			(int (*)(MIKMOD3_CONST CHAR*))
    63 			SDL_LoadFunction(mikmod.handle, "MikMod_Init");
    64 		if ( mikmod.MikMod_Init == NULL ) {
    65 			SDL_UnloadObject(mikmod.handle);
    66 			return -1;
    67 		}
    68 		mikmod.MikMod_RegisterAllLoaders =
    69 			(void (*)(void))
    70 			SDL_LoadFunction(mikmod.handle, "MikMod_RegisterAllLoaders");
    71 		if ( mikmod.MikMod_RegisterAllLoaders == NULL ) {
    72 			SDL_UnloadObject(mikmod.handle);
    73 			return -1;
    74 		}
    75 		mikmod.MikMod_RegisterDriver =
    76 			(void (*)(struct MDRIVER*))
    77 			SDL_LoadFunction(mikmod.handle, "MikMod_RegisterDriver");
    78 		if ( mikmod.MikMod_RegisterDriver == NULL ) {
    79 			SDL_UnloadObject(mikmod.handle);
    80 			return -1;
    81 		}
    82 		mikmod.MikMod_errno =
    83 			(int*)
    84 			SDL_LoadFunction(mikmod.handle, "MikMod_errno");
    85 		if ( mikmod.MikMod_errno == NULL ) {
    86 			SDL_UnloadObject(mikmod.handle);
    87 			return -1;
    88 		}
    89 		mikmod.MikMod_strerror =
    90 			(MIKMOD3_CONST char* (*)(int))
    91 			SDL_LoadFunction(mikmod.handle, "MikMod_strerror");
    92 		if ( mikmod.MikMod_strerror == NULL ) {
    93 			SDL_UnloadObject(mikmod.handle);
    94 			return -1;
    95 		}
    96 		mikmod.MikMod_free =
    97 			(void (*)(void*))
    98 			SDL_LoadFunction(mikmod.handle, "MikMod_free");
    99 		if ( mikmod.MikMod_free == NULL ) {
   100 			/* libmikmod 3.1 and earlier doesn't have it */
   101 			mikmod.MikMod_free = free;
   102 		}
   103 		mikmod.Player_Active =
   104 			(BOOL (*)(void))
   105 			SDL_LoadFunction(mikmod.handle, "Player_Active");
   106 		if ( mikmod.Player_Active == NULL ) {
   107 			SDL_UnloadObject(mikmod.handle);
   108 			return -1;
   109 		}
   110 		mikmod.Player_Free =
   111 			(void (*)(MODULE*))
   112 			SDL_LoadFunction(mikmod.handle, "Player_Free");
   113 		if ( mikmod.Player_Free == NULL ) {
   114 			SDL_UnloadObject(mikmod.handle);
   115 			return -1;
   116 		}
   117 		mikmod.Player_LoadGeneric =
   118 			(MODULE* (*)(MREADER*,int,BOOL))
   119 			SDL_LoadFunction(mikmod.handle, "Player_LoadGeneric");
   120 		if ( mikmod.Player_LoadGeneric == NULL ) {
   121 			SDL_UnloadObject(mikmod.handle);
   122 			return -1;
   123 		}
   124 		mikmod.Player_SetPosition =
   125 			(void (*)(UWORD))
   126 			SDL_LoadFunction(mikmod.handle, "Player_SetPosition");
   127 		if ( mikmod.Player_SetPosition == NULL ) {
   128 			SDL_UnloadObject(mikmod.handle);
   129 			return -1;
   130 		}
   131 		mikmod.Player_SetVolume =
   132 			(void (*)(SWORD))
   133 			SDL_LoadFunction(mikmod.handle, "Player_SetVolume");
   134 		if ( mikmod.Player_SetVolume == NULL ) {
   135 			SDL_UnloadObject(mikmod.handle);
   136 			return -1;
   137 		}
   138 		mikmod.Player_Start =
   139 			(void (*)(MODULE*))
   140 			SDL_LoadFunction(mikmod.handle, "Player_Start");
   141 		if ( mikmod.Player_Start == NULL ) {
   142 			SDL_UnloadObject(mikmod.handle);
   143 			return -1;
   144 		}
   145 		mikmod.Player_Stop =
   146 			(void (*)(void))
   147 			SDL_LoadFunction(mikmod.handle, "Player_Stop");
   148 		if ( mikmod.Player_Stop == NULL ) {
   149 			SDL_UnloadObject(mikmod.handle);
   150 			return -1;
   151 		}
   152 		mikmod.VC_WriteBytes =
   153 			(ULONG (*)(SBYTE*,ULONG))
   154 			SDL_LoadFunction(mikmod.handle, "VC_WriteBytes");
   155 		if ( mikmod.VC_WriteBytes == NULL ) {
   156 			SDL_UnloadObject(mikmod.handle);
   157 			return -1;
   158 		}
   159 		mikmod.drv_nos =
   160 			(MDRIVER*)
   161 			SDL_LoadFunction(mikmod.handle, "drv_nos");
   162 		if ( mikmod.drv_nos == NULL ) {
   163 			SDL_UnloadObject(mikmod.handle);
   164 			return -1;
   165 		}
   166 		mikmod.md_device =
   167 			(UWORD*)
   168 			SDL_LoadFunction(mikmod.handle, "md_device");
   169 		if ( mikmod.md_device == NULL ) {
   170 			SDL_UnloadObject(mikmod.handle);
   171 			return -1;
   172 		}
   173 		mikmod.md_mixfreq =
   174 			(UWORD*)
   175 			SDL_LoadFunction(mikmod.handle, "md_mixfreq");
   176 		if ( mikmod.md_mixfreq == NULL ) {
   177 			SDL_UnloadObject(mikmod.handle);
   178 			return -1;
   179 		}
   180 		mikmod.md_mode =
   181 			(UWORD*)
   182 			SDL_LoadFunction(mikmod.handle, "md_mode");
   183 		if ( mikmod.md_mode == NULL ) {
   184 			SDL_UnloadObject(mikmod.handle);
   185 			return -1;
   186 		}
   187 		mikmod.md_musicvolume =
   188 			(UBYTE*)
   189 			SDL_LoadFunction(mikmod.handle, "md_musicvolume");
   190 		if ( mikmod.md_musicvolume == NULL ) {
   191 			SDL_UnloadObject(mikmod.handle);
   192 			return -1;
   193 		}
   194 		mikmod.md_pansep =
   195 			(UBYTE*)
   196 			SDL_LoadFunction(mikmod.handle, "md_pansep");
   197 		if ( mikmod.md_pansep == NULL ) {
   198 			SDL_UnloadObject(mikmod.handle);
   199 			return -1;
   200 		}
   201 		mikmod.md_reverb =
   202 			(UBYTE*)
   203 			SDL_LoadFunction(mikmod.handle, "md_reverb");
   204 		if ( mikmod.md_reverb == NULL ) {
   205 			SDL_UnloadObject(mikmod.handle);
   206 			return -1;
   207 		}
   208 		mikmod.md_sndfxvolume =
   209 			(UBYTE*)
   210 			SDL_LoadFunction(mikmod.handle, "md_sndfxvolume");
   211 		if ( mikmod.md_sndfxvolume == NULL ) {
   212 			SDL_UnloadObject(mikmod.handle);
   213 			return -1;
   214 		}
   215 		mikmod.md_volume =
   216 			(UBYTE*)
   217 			SDL_LoadFunction(mikmod.handle, "md_volume");
   218 		if ( mikmod.md_volume == NULL ) {
   219 			SDL_UnloadObject(mikmod.handle);
   220 			return -1;
   221 		}
   222 	}
   223 	++mikmod.loaded;
   224 
   225 	return 0;
   226 }
   227 void Mix_QuitMOD()
   228 {
   229 	if ( mikmod.loaded == 0 ) {
   230 		return;
   231 	}
   232 	if ( mikmod.loaded == 1 ) {
   233 		SDL_UnloadObject(mikmod.handle);
   234 	}
   235 	--mikmod.loaded;
   236 }
   237 #else
   238 int Mix_InitMOD()
   239 {
   240 	if ( mikmod.loaded == 0 ) {
   241 		mikmod.MikMod_Exit = MikMod_Exit;
   242 		mikmod.MikMod_InfoDriver = MikMod_InfoDriver;
   243 		mikmod.MikMod_InfoLoader = MikMod_InfoLoader;
   244 		mikmod.MikMod_Init = MikMod_Init;
   245 		mikmod.MikMod_RegisterAllLoaders = MikMod_RegisterAllLoaders;
   246 		mikmod.MikMod_RegisterDriver = MikMod_RegisterDriver;
   247 		mikmod.MikMod_errno = &MikMod_errno;
   248 		mikmod.MikMod_strerror = MikMod_strerror;
   249 #if (LIBMIKMOD_VERSION < 0x030200) || !defined(DMODE_NOISEREDUCTION)
   250 		/* libmikmod 3.2.0-beta2 or older */
   251 		mikmod.MikMod_free = free;
   252 #else
   253 		mikmod.MikMod_free = MikMod_free;
   254 #endif
   255 		mikmod.Player_Active = Player_Active;
   256 		mikmod.Player_Free = Player_Free;
   257 		mikmod.Player_LoadGeneric = Player_LoadGeneric;
   258 		mikmod.Player_SetPosition = Player_SetPosition;
   259 		mikmod.Player_SetVolume = Player_SetVolume;
   260 		mikmod.Player_Start = Player_Start;
   261 		mikmod.Player_Stop = Player_Stop;
   262 		mikmod.VC_WriteBytes = VC_WriteBytes;
   263 		mikmod.drv_nos = &drv_nos;
   264 		mikmod.md_device = &md_device;
   265 		mikmod.md_mixfreq = &md_mixfreq;
   266 		mikmod.md_mode = &md_mode;
   267 		mikmod.md_musicvolume = &md_musicvolume;
   268 		mikmod.md_pansep = &md_pansep;
   269 		mikmod.md_reverb = &md_reverb;
   270 		mikmod.md_sndfxvolume = &md_sndfxvolume;
   271 		mikmod.md_volume = &md_volume;
   272 	}
   273 	++mikmod.loaded;
   274 
   275 	return 0;
   276 }
   277 void Mix_QuitMOD()
   278 {
   279 	if ( mikmod.loaded == 0 ) {
   280 		return;
   281 	}
   282 	if ( mikmod.loaded == 1 ) {
   283 	}
   284 	--mikmod.loaded;
   285 }
   286 #endif /* MOD_DYNAMIC */
   287 
   288 #endif /* MOD_MUSIC */