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