File: dynamic_mp3.c

package info (click to toggle)
sdl-mixer1.2 1.2.12-15
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 13,732 kB
  • sloc: ansic: 18,763; sh: 9,453; objc: 1,482; cpp: 238; csh: 219; makefile: 145
file content (171 lines) | stat: -rw-r--r-- 4,553 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
  SDL_mixer:  An audio mixer library based on the SDL library
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.
*/

#ifdef MP3_MUSIC

#include "SDL_loadso.h"

#include "dynamic_mp3.h"

smpeg_loader smpeg = {
	0, NULL
};

#ifdef MP3_DYNAMIC
int Mix_InitMP3()
{
	if ( smpeg.loaded == 0 ) {
		smpeg.handle = SDL_LoadObject(MP3_DYNAMIC);
		if ( smpeg.handle == NULL ) {
			return -1;
		}
		smpeg.SMPEG_actualSpec =
			(void (*)( SMPEG *, SDL_AudioSpec * ))
			SDL_LoadFunction(smpeg.handle, "SMPEG_actualSpec");
		if ( smpeg.SMPEG_actualSpec == NULL ) {
			SDL_UnloadObject(smpeg.handle);
			return -1;
		}
		smpeg.SMPEG_delete =
			(void (*)( SMPEG* ))
			SDL_LoadFunction(smpeg.handle, "SMPEG_delete");
		if ( smpeg.SMPEG_delete == NULL ) {
			SDL_UnloadObject(smpeg.handle);
			return -1;
		}
		smpeg.SMPEG_enableaudio =
			(void (*)( SMPEG*, int ))
			SDL_LoadFunction(smpeg.handle, "SMPEG_enableaudio");
		if ( smpeg.SMPEG_enableaudio == NULL ) {
			SDL_UnloadObject(smpeg.handle);
			return -1;
		}
		smpeg.SMPEG_enablevideo =
			(void (*)( SMPEG*, int ))
			SDL_LoadFunction(smpeg.handle, "SMPEG_enablevideo");
		if ( smpeg.SMPEG_enablevideo == NULL ) {
			SDL_UnloadObject(smpeg.handle);
			return -1;
		}
		smpeg.SMPEG_new_rwops =
			(SMPEG* (*)(SDL_RWops *, SMPEG_Info*, int))
			SDL_LoadFunction(smpeg.handle, "SMPEG_new_rwops");
		if ( smpeg.SMPEG_new_rwops == NULL ) {
			SDL_UnloadObject(smpeg.handle);
			return -1;
		}
		smpeg.SMPEG_play =
			(void (*)( SMPEG* ))
			SDL_LoadFunction(smpeg.handle, "SMPEG_play");
		if ( smpeg.SMPEG_play == NULL ) {
			SDL_UnloadObject(smpeg.handle);
			return -1;
		}
		smpeg.SMPEG_playAudio =
			(int (*)( SMPEG *, Uint8 *, int ))
			SDL_LoadFunction(smpeg.handle, "SMPEG_playAudio");
		if ( smpeg.SMPEG_playAudio == NULL ) {
			SDL_UnloadObject(smpeg.handle);
			return -1;
		}
		smpeg.SMPEG_rewind =
			(void (*)( SMPEG* ))
			SDL_LoadFunction(smpeg.handle, "SMPEG_rewind");
		if ( smpeg.SMPEG_rewind == NULL ) {
			SDL_UnloadObject(smpeg.handle);
			return -1;
		}
		smpeg.SMPEG_setvolume =
			(void (*)( SMPEG*, int ))
			SDL_LoadFunction(smpeg.handle, "SMPEG_setvolume");
		if ( smpeg.SMPEG_setvolume == NULL ) {
			SDL_UnloadObject(smpeg.handle);
			return -1;
		}
		smpeg.SMPEG_skip =
			(void (*)( SMPEG*, float ))
			SDL_LoadFunction(smpeg.handle, "SMPEG_skip");
		if ( smpeg.SMPEG_skip == NULL ) {
			SDL_UnloadObject(smpeg.handle);
			return -1;
		}
		smpeg.SMPEG_status =
			(SMPEGstatus (*)( SMPEG* ))
			SDL_LoadFunction(smpeg.handle, "SMPEG_status");
		if ( smpeg.SMPEG_status == NULL ) {
			SDL_UnloadObject(smpeg.handle);
			return -1;
		}
		smpeg.SMPEG_stop =
			(void (*)( SMPEG* ))
			SDL_LoadFunction(smpeg.handle, "SMPEG_stop");
		if ( smpeg.SMPEG_stop == NULL ) {
			SDL_UnloadObject(smpeg.handle);
			return -1;
		}
	}
	++smpeg.loaded;

	return 0;
}
void Mix_QuitMP3()
{
	if ( smpeg.loaded == 0 ) {
		return;
	}
	if ( smpeg.loaded == 1 ) {
		SDL_UnloadObject(smpeg.handle);
	}
	--smpeg.loaded;
}
#else
int Mix_InitMP3()
{
	if ( smpeg.loaded == 0 ) {
		smpeg.SMPEG_actualSpec = SMPEG_actualSpec;
		smpeg.SMPEG_delete = SMPEG_delete;
		smpeg.SMPEG_enableaudio = SMPEG_enableaudio;
		smpeg.SMPEG_enablevideo = SMPEG_enablevideo;
		smpeg.SMPEG_new_rwops = SMPEG_new_rwops;
		smpeg.SMPEG_play = SMPEG_play;
		smpeg.SMPEG_playAudio = SMPEG_playAudio;
		smpeg.SMPEG_rewind = SMPEG_rewind;
		smpeg.SMPEG_setvolume = SMPEG_setvolume;
		smpeg.SMPEG_skip = SMPEG_skip;
		smpeg.SMPEG_status = SMPEG_status;
		smpeg.SMPEG_stop = SMPEG_stop;
	}
	++smpeg.loaded;

	return 0;
}
void Mix_QuitMP3()
{
	if ( smpeg.loaded == 0 ) {
		return;
	}
	if ( smpeg.loaded == 1 ) {
	}
	--smpeg.loaded;
}
#endif /* MP3_DYNAMIC */

#endif /* MP3_MUSIC */