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
slouken@314
     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@314
     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@314
     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@314
    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@314
    20
*/
slouken@314
    21
slouken@314
    22
#ifdef MP3_MUSIC
slouken@314
    23
slouken@314
    24
#include "SDL_loadso.h"
slouken@314
    25
slouken@314
    26
#include "dynamic_mp3.h"
slouken@314
    27
slouken@314
    28
smpeg_loader smpeg = {
slouken@314
    29
	0, NULL
slouken@314
    30
};
slouken@314
    31
slouken@314
    32
#ifdef MP3_DYNAMIC
slouken@314
    33
int Mix_InitMP3()
slouken@314
    34
{
slouken@314
    35
	if ( smpeg.loaded == 0 ) {
slouken@314
    36
		smpeg.handle = SDL_LoadObject(MP3_DYNAMIC);
slouken@314
    37
		if ( smpeg.handle == NULL ) {
slouken@314
    38
			return -1;
slouken@314
    39
		}
slouken@314
    40
		smpeg.SMPEG_actualSpec =
slouken@314
    41
			(void (*)( SMPEG *, SDL_AudioSpec * ))
slouken@314
    42
			SDL_LoadFunction(smpeg.handle, "SMPEG_actualSpec");
slouken@314
    43
		if ( smpeg.SMPEG_actualSpec == NULL ) {
slouken@314
    44
			SDL_UnloadObject(smpeg.handle);
slouken@314
    45
			return -1;
slouken@314
    46
		}
slouken@314
    47
		smpeg.SMPEG_delete =
slouken@314
    48
			(void (*)( SMPEG* ))
slouken@314
    49
			SDL_LoadFunction(smpeg.handle, "SMPEG_delete");
slouken@314
    50
		if ( smpeg.SMPEG_delete == NULL ) {
slouken@314
    51
			SDL_UnloadObject(smpeg.handle);
slouken@314
    52
			return -1;
slouken@314
    53
		}
slouken@314
    54
		smpeg.SMPEG_enableaudio =
slouken@314
    55
			(void (*)( SMPEG*, int ))
slouken@314
    56
			SDL_LoadFunction(smpeg.handle, "SMPEG_enableaudio");
slouken@314
    57
		if ( smpeg.SMPEG_enableaudio == NULL ) {
slouken@314
    58
			SDL_UnloadObject(smpeg.handle);
slouken@314
    59
			return -1;
slouken@314
    60
		}
slouken@314
    61
		smpeg.SMPEG_enablevideo =
slouken@314
    62
			(void (*)( SMPEG*, int ))
slouken@314
    63
			SDL_LoadFunction(smpeg.handle, "SMPEG_enablevideo");
slouken@314
    64
		if ( smpeg.SMPEG_enablevideo == NULL ) {
slouken@314
    65
			SDL_UnloadObject(smpeg.handle);
slouken@314
    66
			return -1;
slouken@314
    67
		}
slouken@314
    68
		smpeg.SMPEG_new =
slouken@314
    69
			(SMPEG* (*)(const char *, SMPEG_Info*, int))
slouken@314
    70
			SDL_LoadFunction(smpeg.handle, "SMPEG_new");
slouken@314
    71
		if ( smpeg.SMPEG_new == NULL ) {
slouken@314
    72
			SDL_UnloadObject(smpeg.handle);
slouken@314
    73
			return -1;
slouken@314
    74
		}
slouken@314
    75
		smpeg.SMPEG_new_rwops =
slouken@314
    76
			(SMPEG* (*)(SDL_RWops *, SMPEG_Info*, int))
slouken@314
    77
			SDL_LoadFunction(smpeg.handle, "SMPEG_new_rwops");
slouken@314
    78
		if ( smpeg.SMPEG_new_rwops == NULL ) {
slouken@314
    79
			SDL_UnloadObject(smpeg.handle);
slouken@314
    80
			return -1;
slouken@314
    81
		}
slouken@314
    82
		smpeg.SMPEG_play =
slouken@314
    83
			(void (*)( SMPEG* ))
slouken@314
    84
			SDL_LoadFunction(smpeg.handle, "SMPEG_play");
slouken@314
    85
		if ( smpeg.SMPEG_play == NULL ) {
slouken@314
    86
			SDL_UnloadObject(smpeg.handle);
slouken@314
    87
			return -1;
slouken@314
    88
		}
slouken@314
    89
		smpeg.SMPEG_playAudio =
slouken@314
    90
			(int (*)( SMPEG *, Uint8 *, int ))
slouken@314
    91
			SDL_LoadFunction(smpeg.handle, "SMPEG_playAudio");
slouken@314
    92
		if ( smpeg.SMPEG_playAudio == NULL ) {
slouken@314
    93
			SDL_UnloadObject(smpeg.handle);
slouken@314
    94
			return -1;
slouken@314
    95
		}
slouken@314
    96
		smpeg.SMPEG_rewind =
slouken@314
    97
			(void (*)( SMPEG* ))
slouken@314
    98
			SDL_LoadFunction(smpeg.handle, "SMPEG_rewind");
slouken@314
    99
		if ( smpeg.SMPEG_rewind == NULL ) {
slouken@314
   100
			SDL_UnloadObject(smpeg.handle);
slouken@314
   101
			return -1;
slouken@314
   102
		}
slouken@314
   103
		smpeg.SMPEG_setvolume =
slouken@314
   104
			(void (*)( SMPEG*, int ))
slouken@314
   105
			SDL_LoadFunction(smpeg.handle, "SMPEG_setvolume");
slouken@314
   106
		if ( smpeg.SMPEG_setvolume == NULL ) {
slouken@314
   107
			SDL_UnloadObject(smpeg.handle);
slouken@314
   108
			return -1;
slouken@314
   109
		}
slouken@314
   110
		smpeg.SMPEG_skip =
slouken@314
   111
			(void (*)( SMPEG*, float ))
slouken@314
   112
			SDL_LoadFunction(smpeg.handle, "SMPEG_skip");
slouken@314
   113
		if ( smpeg.SMPEG_skip == NULL ) {
slouken@314
   114
			SDL_UnloadObject(smpeg.handle);
slouken@314
   115
			return -1;
slouken@314
   116
		}
slouken@314
   117
		smpeg.SMPEG_status =
slouken@314
   118
			(SMPEGstatus (*)( SMPEG* ))
slouken@314
   119
			SDL_LoadFunction(smpeg.handle, "SMPEG_status");
slouken@314
   120
		if ( smpeg.SMPEG_status == NULL ) {
slouken@314
   121
			SDL_UnloadObject(smpeg.handle);
slouken@314
   122
			return -1;
slouken@314
   123
		}
slouken@314
   124
		smpeg.SMPEG_stop =
slouken@314
   125
			(void (*)( SMPEG* ))
slouken@314
   126
			SDL_LoadFunction(smpeg.handle, "SMPEG_stop");
slouken@314
   127
		if ( smpeg.SMPEG_stop == NULL ) {
slouken@314
   128
			SDL_UnloadObject(smpeg.handle);
slouken@314
   129
			return -1;
slouken@314
   130
		}
slouken@314
   131
	}
slouken@314
   132
	++smpeg.loaded;
slouken@314
   133
slouken@314
   134
	return 0;
slouken@314
   135
}
slouken@314
   136
void Mix_QuitMP3()
slouken@314
   137
{
slouken@314
   138
	if ( smpeg.loaded == 0 ) {
slouken@314
   139
		return;
slouken@314
   140
	}
slouken@314
   141
	if ( smpeg.loaded == 1 ) {
slouken@314
   142
		SDL_UnloadObject(smpeg.handle);
slouken@314
   143
	}
slouken@314
   144
	--smpeg.loaded;
slouken@314
   145
}
slouken@314
   146
#else
slouken@314
   147
int Mix_InitMP3()
slouken@314
   148
{
slouken@314
   149
	if ( smpeg.loaded == 0 ) {
slouken@314
   150
		smpeg.SMPEG_actualSpec = SMPEG_actualSpec;
slouken@314
   151
		smpeg.SMPEG_delete = SMPEG_delete;
slouken@314
   152
		smpeg.SMPEG_enableaudio = SMPEG_enableaudio;
slouken@314
   153
		smpeg.SMPEG_enablevideo = SMPEG_enablevideo;
slouken@314
   154
		smpeg.SMPEG_new = SMPEG_new;
slouken@314
   155
		smpeg.SMPEG_new_rwops = SMPEG_new_rwops;
slouken@314
   156
		smpeg.SMPEG_play = SMPEG_play;
slouken@314
   157
		smpeg.SMPEG_playAudio = SMPEG_playAudio;
slouken@314
   158
		smpeg.SMPEG_rewind = SMPEG_rewind;
slouken@314
   159
		smpeg.SMPEG_setvolume = SMPEG_setvolume;
slouken@314
   160
		smpeg.SMPEG_skip = SMPEG_skip;
slouken@314
   161
		smpeg.SMPEG_status = SMPEG_status;
slouken@314
   162
		smpeg.SMPEG_stop = SMPEG_stop;
slouken@314
   163
	}
slouken@314
   164
	++smpeg.loaded;
slouken@314
   165
slouken@314
   166
	return 0;
slouken@314
   167
}
slouken@314
   168
void Mix_QuitMP3()
slouken@314
   169
{
slouken@314
   170
	if ( smpeg.loaded == 0 ) {
slouken@314
   171
		return;
slouken@314
   172
	}
slouken@314
   173
	if ( smpeg.loaded == 1 ) {
slouken@314
   174
	}
slouken@314
   175
	--smpeg.loaded;
slouken@314
   176
}
slouken@314
   177
#endif /* MP3_DYNAMIC */
slouken@314
   178
slouken@314
   179
#endif /* MP3_MUSIC */