dynamic_mod.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 14 Jan 2012 19:52:34 -0500
changeset 564 2aee47b6dc73
parent 518 8bc9b5fd2aae
child 587 56cad6484b04
child 865 3ffb22a2755b
permissions -rw-r--r--
Fixed MOD playback on 64-bit Windows
slouken@419
     1
/*
slouken@518
     2
  SDL_mixer:  An audio mixer library based on the SDL library
slouken@518
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
slouken@419
     4
slouken@518
     5
  This software is provided 'as-is', without any express or implied
slouken@518
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@518
     7
  arising from the use of this software.
slouken@419
     8
slouken@518
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@518
    10
  including commercial applications, and to alter it and redistribute it
slouken@518
    11
  freely, subject to the following restrictions:
slouken@419
    12
slouken@518
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@518
    14
     claim that you wrote the original software. If you use this software
slouken@518
    15
     in a product, an acknowledgment in the product documentation would be
slouken@518
    16
     appreciated but is not required.
slouken@518
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@518
    18
     misrepresented as being the original software.
slouken@518
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@419
    20
*/
slouken@419
    21
slouken@419
    22
#ifdef MOD_MUSIC
slouken@419
    23
slouken@419
    24
#include "SDL_loadso.h"
slouken@419
    25
slouken@419
    26
#include "dynamic_mod.h"
slouken@419
    27
slouken@419
    28
mikmod_loader mikmod = {
slouken@419
    29
	0, NULL
slouken@419
    30
};
slouken@419
    31
slouken@419
    32
#ifdef MOD_DYNAMIC
slouken@419
    33
int Mix_InitMOD()
slouken@419
    34
{
slouken@419
    35
	if ( mikmod.loaded == 0 ) {
slouken@419
    36
		mikmod.handle = SDL_LoadObject(MOD_DYNAMIC);
slouken@419
    37
		if ( mikmod.handle == NULL ) {
slouken@419
    38
			return -1;
slouken@419
    39
		}
slouken@419
    40
		mikmod.MikMod_Exit =
slouken@419
    41
			(void (*)(void))
slouken@419
    42
			SDL_LoadFunction(mikmod.handle, "MikMod_Exit");
slouken@419
    43
		if ( mikmod.MikMod_Exit == NULL ) {
slouken@419
    44
			SDL_UnloadObject(mikmod.handle);
slouken@419
    45
			return -1;
slouken@419
    46
		}
slouken@419
    47
		mikmod.MikMod_InfoDriver =
slouken@419
    48
			(CHAR* (*)(void))
slouken@419
    49
			SDL_LoadFunction(mikmod.handle, "MikMod_InfoDriver");
slouken@419
    50
		if ( mikmod.MikMod_InfoDriver == NULL ) {
slouken@419
    51
			SDL_UnloadObject(mikmod.handle);
slouken@419
    52
			return -1;
slouken@419
    53
		}
slouken@419
    54
		mikmod.MikMod_InfoLoader =
slouken@419
    55
			(CHAR* (*)(void))
slouken@419
    56
			SDL_LoadFunction(mikmod.handle, "MikMod_InfoLoader");
slouken@419
    57
		if ( mikmod.MikMod_InfoLoader == NULL ) {
slouken@419
    58
			SDL_UnloadObject(mikmod.handle);
slouken@419
    59
			return -1;
slouken@419
    60
		}
slouken@419
    61
		mikmod.MikMod_Init =
slouken@419
    62
			(BOOL (*)(CHAR*))
slouken@419
    63
			SDL_LoadFunction(mikmod.handle, "MikMod_Init");
slouken@419
    64
		if ( mikmod.MikMod_Init == NULL ) {
slouken@419
    65
			SDL_UnloadObject(mikmod.handle);
slouken@419
    66
			return -1;
slouken@419
    67
		}
slouken@419
    68
		mikmod.MikMod_RegisterAllLoaders =
slouken@419
    69
			(void (*)(void))
slouken@419
    70
			SDL_LoadFunction(mikmod.handle, "MikMod_RegisterAllLoaders");
slouken@419
    71
		if ( mikmod.MikMod_RegisterAllLoaders == NULL ) {
slouken@419
    72
			SDL_UnloadObject(mikmod.handle);
slouken@419
    73
			return -1;
slouken@419
    74
		}
slouken@419
    75
		mikmod.MikMod_RegisterDriver =
slouken@419
    76
			(void (*)(struct MDRIVER*))
slouken@419
    77
			SDL_LoadFunction(mikmod.handle, "MikMod_RegisterDriver");
slouken@419
    78
		if ( mikmod.MikMod_RegisterDriver == NULL ) {
slouken@419
    79
			SDL_UnloadObject(mikmod.handle);
slouken@419
    80
			return -1;
slouken@419
    81
		}
slouken@419
    82
		mikmod.MikMod_errno =
slouken@419
    83
			(int*)
slouken@419
    84
			SDL_LoadFunction(mikmod.handle, "MikMod_errno");
slouken@419
    85
		if ( mikmod.MikMod_errno == NULL ) {
slouken@419
    86
			SDL_UnloadObject(mikmod.handle);
slouken@419
    87
			return -1;
slouken@419
    88
		}
slouken@419
    89
		mikmod.MikMod_strerror =
slouken@419
    90
			(char* (*)(int))
slouken@419
    91
			SDL_LoadFunction(mikmod.handle, "MikMod_strerror");
slouken@419
    92
		if ( mikmod.MikMod_strerror == NULL ) {
slouken@419
    93
			SDL_UnloadObject(mikmod.handle);
slouken@419
    94
			return -1;
slouken@419
    95
		}
slouken@419
    96
		mikmod.Player_Active =
slouken@419
    97
			(BOOL (*)(void))
slouken@419
    98
			SDL_LoadFunction(mikmod.handle, "Player_Active");
slouken@419
    99
		if ( mikmod.Player_Active == NULL ) {
slouken@419
   100
			SDL_UnloadObject(mikmod.handle);
slouken@419
   101
			return -1;
slouken@419
   102
		}
slouken@419
   103
		mikmod.Player_Free =
slouken@419
   104
			(void (*)(MODULE*))
slouken@419
   105
			SDL_LoadFunction(mikmod.handle, "Player_Free");
slouken@419
   106
		if ( mikmod.Player_Free == NULL ) {
slouken@419
   107
			SDL_UnloadObject(mikmod.handle);
slouken@419
   108
			return -1;
slouken@419
   109
		}
slouken@419
   110
		mikmod.Player_LoadGeneric =
slouken@419
   111
			(MODULE* (*)(MREADER*,int,BOOL))
slouken@419
   112
			SDL_LoadFunction(mikmod.handle, "Player_LoadGeneric");
slouken@419
   113
		if ( mikmod.Player_LoadGeneric == NULL ) {
slouken@419
   114
			SDL_UnloadObject(mikmod.handle);
slouken@419
   115
			return -1;
slouken@419
   116
		}
slouken@419
   117
		mikmod.Player_SetPosition =
slouken@419
   118
			(void (*)(UWORD))
slouken@419
   119
			SDL_LoadFunction(mikmod.handle, "Player_SetPosition");
slouken@419
   120
		if ( mikmod.Player_SetPosition == NULL ) {
slouken@419
   121
			SDL_UnloadObject(mikmod.handle);
slouken@419
   122
			return -1;
slouken@419
   123
		}
slouken@419
   124
		mikmod.Player_SetVolume =
slouken@419
   125
			(void (*)(SWORD))
slouken@419
   126
			SDL_LoadFunction(mikmod.handle, "Player_SetVolume");
slouken@419
   127
		if ( mikmod.Player_SetVolume == NULL ) {
slouken@419
   128
			SDL_UnloadObject(mikmod.handle);
slouken@419
   129
			return -1;
slouken@419
   130
		}
slouken@419
   131
		mikmod.Player_Start =
slouken@419
   132
			(void (*)(MODULE*))
slouken@419
   133
			SDL_LoadFunction(mikmod.handle, "Player_Start");
slouken@419
   134
		if ( mikmod.Player_Start == NULL ) {
slouken@419
   135
			SDL_UnloadObject(mikmod.handle);
slouken@419
   136
			return -1;
slouken@419
   137
		}
slouken@419
   138
		mikmod.Player_Stop =
slouken@419
   139
			(void (*)(void))
slouken@419
   140
			SDL_LoadFunction(mikmod.handle, "Player_Stop");
slouken@419
   141
		if ( mikmod.Player_Stop == NULL ) {
slouken@419
   142
			SDL_UnloadObject(mikmod.handle);
slouken@419
   143
			return -1;
slouken@419
   144
		}
slouken@419
   145
		mikmod.VC_WriteBytes =
slouken@419
   146
			(ULONG (*)(SBYTE*,ULONG))
slouken@419
   147
			SDL_LoadFunction(mikmod.handle, "VC_WriteBytes");
slouken@419
   148
		if ( mikmod.VC_WriteBytes == NULL ) {
slouken@419
   149
			SDL_UnloadObject(mikmod.handle);
slouken@419
   150
			return -1;
slouken@419
   151
		}
slouken@419
   152
		mikmod.drv_nos =
slouken@419
   153
			(MDRIVER*)
slouken@419
   154
			SDL_LoadFunction(mikmod.handle, "drv_nos");
slouken@419
   155
		if ( mikmod.drv_nos == NULL ) {
slouken@419
   156
			SDL_UnloadObject(mikmod.handle);
slouken@419
   157
			return -1;
slouken@419
   158
		}
slouken@419
   159
		mikmod.md_device =
slouken@419
   160
			(UWORD*)
slouken@419
   161
			SDL_LoadFunction(mikmod.handle, "md_device");
slouken@419
   162
		if ( mikmod.md_device == NULL ) {
slouken@419
   163
			SDL_UnloadObject(mikmod.handle);
slouken@419
   164
			return -1;
slouken@419
   165
		}
slouken@419
   166
		mikmod.md_mixfreq =
slouken@419
   167
			(UWORD*)
slouken@419
   168
			SDL_LoadFunction(mikmod.handle, "md_mixfreq");
slouken@419
   169
		if ( mikmod.md_mixfreq == NULL ) {
slouken@419
   170
			SDL_UnloadObject(mikmod.handle);
slouken@419
   171
			return -1;
slouken@419
   172
		}
slouken@419
   173
		mikmod.md_mode =
slouken@419
   174
			(UWORD*)
slouken@419
   175
			SDL_LoadFunction(mikmod.handle, "md_mode");
slouken@419
   176
		if ( mikmod.md_mode == NULL ) {
slouken@419
   177
			SDL_UnloadObject(mikmod.handle);
slouken@419
   178
			return -1;
slouken@419
   179
		}
slouken@419
   180
		mikmod.md_musicvolume =
slouken@419
   181
			(UBYTE*)
slouken@419
   182
			SDL_LoadFunction(mikmod.handle, "md_musicvolume");
slouken@419
   183
		if ( mikmod.md_musicvolume == NULL ) {
slouken@419
   184
			SDL_UnloadObject(mikmod.handle);
slouken@419
   185
			return -1;
slouken@419
   186
		}
slouken@419
   187
		mikmod.md_pansep =
slouken@419
   188
			(UBYTE*)
slouken@419
   189
			SDL_LoadFunction(mikmod.handle, "md_pansep");
slouken@419
   190
		if ( mikmod.md_pansep == NULL ) {
slouken@419
   191
			SDL_UnloadObject(mikmod.handle);
slouken@419
   192
			return -1;
slouken@419
   193
		}
slouken@419
   194
		mikmod.md_reverb =
slouken@419
   195
			(UBYTE*)
slouken@419
   196
			SDL_LoadFunction(mikmod.handle, "md_reverb");
slouken@419
   197
		if ( mikmod.md_reverb == NULL ) {
slouken@419
   198
			SDL_UnloadObject(mikmod.handle);
slouken@419
   199
			return -1;
slouken@419
   200
		}
slouken@419
   201
		mikmod.md_sndfxvolume =
slouken@419
   202
			(UBYTE*)
slouken@419
   203
			SDL_LoadFunction(mikmod.handle, "md_sndfxvolume");
slouken@419
   204
		if ( mikmod.md_sndfxvolume == NULL ) {
slouken@419
   205
			SDL_UnloadObject(mikmod.handle);
slouken@419
   206
			return -1;
slouken@419
   207
		}
slouken@419
   208
		mikmod.md_volume =
slouken@419
   209
			(UBYTE*)
slouken@419
   210
			SDL_LoadFunction(mikmod.handle, "md_volume");
slouken@419
   211
		if ( mikmod.md_volume == NULL ) {
slouken@419
   212
			SDL_UnloadObject(mikmod.handle);
slouken@419
   213
			return -1;
slouken@419
   214
		}
slouken@419
   215
	}
slouken@419
   216
	++mikmod.loaded;
slouken@419
   217
slouken@419
   218
	return 0;
slouken@419
   219
}
slouken@419
   220
void Mix_QuitMOD()
slouken@419
   221
{
slouken@419
   222
	if ( mikmod.loaded == 0 ) {
slouken@419
   223
		return;
slouken@419
   224
	}
slouken@419
   225
	if ( mikmod.loaded == 1 ) {
slouken@419
   226
		SDL_UnloadObject(mikmod.handle);
slouken@419
   227
	}
slouken@419
   228
	--mikmod.loaded;
slouken@419
   229
}
slouken@419
   230
#else
slouken@419
   231
int Mix_InitMOD()
slouken@419
   232
{
slouken@419
   233
	if ( mikmod.loaded == 0 ) {
slouken@419
   234
		mikmod.MikMod_Exit = MikMod_Exit;
slouken@419
   235
		mikmod.MikMod_InfoDriver = MikMod_InfoDriver;
slouken@419
   236
		mikmod.MikMod_InfoLoader = MikMod_InfoLoader;
slouken@419
   237
		mikmod.MikMod_Init = MikMod_Init;
slouken@419
   238
		mikmod.MikMod_RegisterAllLoaders = MikMod_RegisterAllLoaders;
slouken@419
   239
		mikmod.MikMod_RegisterDriver = MikMod_RegisterDriver;
slouken@419
   240
		mikmod.MikMod_errno = &MikMod_errno;
slouken@419
   241
		mikmod.MikMod_strerror = MikMod_strerror;
slouken@419
   242
		mikmod.Player_Active = Player_Active;
slouken@419
   243
		mikmod.Player_Free = Player_Free;
slouken@419
   244
		mikmod.Player_LoadGeneric = Player_LoadGeneric;
slouken@419
   245
		mikmod.Player_SetPosition = Player_SetPosition;
slouken@419
   246
		mikmod.Player_SetVolume = Player_SetVolume;
slouken@419
   247
		mikmod.Player_Start = Player_Start;
slouken@419
   248
		mikmod.Player_Stop = Player_Stop;
slouken@419
   249
		mikmod.VC_WriteBytes = VC_WriteBytes;
slouken@419
   250
		mikmod.drv_nos = &drv_nos;
slouken@419
   251
		mikmod.md_device = &md_device;
slouken@419
   252
		mikmod.md_mixfreq = &md_mixfreq;
slouken@419
   253
		mikmod.md_mode = &md_mode;
slouken@419
   254
		mikmod.md_musicvolume = &md_musicvolume;
slouken@419
   255
		mikmod.md_pansep = &md_pansep;
slouken@419
   256
		mikmod.md_reverb = &md_reverb;
slouken@419
   257
		mikmod.md_sndfxvolume = &md_sndfxvolume;
slouken@419
   258
		mikmod.md_volume = &md_volume;
slouken@419
   259
	}
slouken@419
   260
	++mikmod.loaded;
slouken@419
   261
slouken@419
   262
	return 0;
slouken@419
   263
}
slouken@419
   264
void Mix_QuitMOD()
slouken@419
   265
{
slouken@419
   266
	if ( mikmod.loaded == 0 ) {
slouken@419
   267
		return;
slouken@419
   268
	}
slouken@419
   269
	if ( mikmod.loaded == 1 ) {
slouken@419
   270
	}
slouken@419
   271
	--mikmod.loaded;
slouken@419
   272
}
slouken@419
   273
#endif /* MOD_DYNAMIC */
slouken@419
   274
slouken@419
   275
#endif /* MOD_MUSIC */