Remove dynamic openmpt loading
This commit is contained in:
parent
caab60e9f0
commit
4a17e9ed9b
|
@ -364,8 +364,7 @@ CFLAGS+=$(LIBGME_CFLAGS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef HAVE_OPENMPT
|
ifdef HAVE_OPENMPT
|
||||||
# make libopenmpt optional
|
OPTS+=-DHAVE_OPENMPT
|
||||||
OPTS+=-DHAVE_OPENMPT -DOPENMPT_DYNAMIC
|
|
||||||
|
|
||||||
LIBOPENMPT_PKGCONFIG?=libopenmpt
|
LIBOPENMPT_PKGCONFIG?=libopenmpt
|
||||||
LIBOPENMPT_CFLAGS?=$(shell $(PKG_CONFIG) $(LIBOPENMPT_PKGCONFIG) --cflags)
|
LIBOPENMPT_CFLAGS?=$(shell $(PKG_CONFIG) $(LIBOPENMPT_PKGCONFIG) --cflags)
|
||||||
|
|
|
@ -79,7 +79,6 @@ ifdef NOMIXER
|
||||||
i_sound_o=$(OBJDIR)/sdl_sound.o
|
i_sound_o=$(OBJDIR)/sdl_sound.o
|
||||||
else
|
else
|
||||||
i_sound_o=$(OBJDIR)/mixer_sound.o
|
i_sound_o=$(OBJDIR)/mixer_sound.o
|
||||||
OBJS+=$(OBJDIR)/load_libraries.o
|
|
||||||
OPTS+=-DHAVE_MIXER
|
OPTS+=-DHAVE_MIXER
|
||||||
SDL_LDFLAGS+=-lSDL2_mixer
|
SDL_LDFLAGS+=-lSDL2_mixer
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -292,7 +292,6 @@
|
||||||
<ClInclude Include="endtxt.h" />
|
<ClInclude Include="endtxt.h" />
|
||||||
<ClInclude Include="hwsym_sdl.h" />
|
<ClInclude Include="hwsym_sdl.h" />
|
||||||
<ClInclude Include="i_ttf.h" />
|
<ClInclude Include="i_ttf.h" />
|
||||||
<ClInclude Include="load_libraries.h" />
|
|
||||||
<ClInclude Include="ogl_sdl.h" />
|
<ClInclude Include="ogl_sdl.h" />
|
||||||
<ClInclude Include="sdlmain.h" />
|
<ClInclude Include="sdlmain.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -467,7 +466,6 @@
|
||||||
<ClCompile Include="i_system.c" />
|
<ClCompile Include="i_system.c" />
|
||||||
<ClCompile Include="i_ttf.c" />
|
<ClCompile Include="i_ttf.c" />
|
||||||
<ClCompile Include="i_video.c" />
|
<ClCompile Include="i_video.c" />
|
||||||
<ClCompile Include="load_libraries.c" />
|
|
||||||
<ClCompile Include="mixer_sound.c" />
|
<ClCompile Include="mixer_sound.c" />
|
||||||
<ClCompile Include="ogl_sdl.c" />
|
<ClCompile Include="ogl_sdl.c" />
|
||||||
<ClCompile Include="SDL_main\SDL_windows_main.c" />
|
<ClCompile Include="SDL_main\SDL_windows_main.c" />
|
||||||
|
|
|
@ -447,9 +447,6 @@
|
||||||
<ClInclude Include="sdlmain.h">
|
<ClInclude Include="sdlmain.h">
|
||||||
<Filter>SDLApp</Filter>
|
<Filter>SDLApp</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="load_libraries.h">
|
|
||||||
<Filter>SDLApp</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<CustomBuild Include="..\tmap.nas">
|
<CustomBuild Include="..\tmap.nas">
|
||||||
|
@ -888,9 +885,6 @@
|
||||||
<ClCompile Include="SDL_main\SDL_windows_main.c">
|
<ClCompile Include="SDL_main\SDL_windows_main.c">
|
||||||
<Filter>SDLApp</Filter>
|
<Filter>SDLApp</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="load_libraries.c">
|
|
||||||
<Filter>SDLApp</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="Srb2SDL.ico">
|
<Image Include="Srb2SDL.ico">
|
||||||
|
|
|
@ -1,112 +0,0 @@
|
||||||
///
|
|
||||||
/// Dynamic Library Loading
|
|
||||||
///
|
|
||||||
|
|
||||||
#include "../doomdef.h"
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma warning(disable : 4214 4244)
|
|
||||||
#endif
|
|
||||||
#include "SDL.h"
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma warning(default : 4214 4244)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "load_libraries.h"
|
|
||||||
|
|
||||||
///
|
|
||||||
/// OpenMPT Loading
|
|
||||||
///
|
|
||||||
|
|
||||||
#ifdef HAVE_OPENMPT
|
|
||||||
|
|
||||||
openmpt_loader openmpt = {
|
|
||||||
0, NULL,
|
|
||||||
NULL, NULL, NULL, // errors
|
|
||||||
NULL, NULL, // module loading
|
|
||||||
NULL, // audio callback
|
|
||||||
NULL, NULL, NULL, // playback settings
|
|
||||||
NULL, NULL, NULL, NULL, NULL // positioning
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef OPENMPT_DYNAMIC
|
|
||||||
#define FUNCTION_LOADER(NAME, FUNC, SIG) \
|
|
||||||
openmpt.NAME = (SIG) SDL_LoadFunction(openmpt.handle, #FUNC); \
|
|
||||||
if (openmpt.NAME == NULL) { SDL_UnloadObject(openmpt.handle); openmpt.handle = NULL; return; }
|
|
||||||
#else
|
|
||||||
#define FUNCTION_LOADER(NAME, FUNC, SIG) \
|
|
||||||
openmpt.NAME = FUNC;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void load_openmpt(void)
|
|
||||||
{
|
|
||||||
if (openmpt.loaded)
|
|
||||||
return;
|
|
||||||
|
|
||||||
#ifdef OPENMPT_DYNAMIC
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
|
||||||
openmpt.handle = SDL_LoadObject("libopenmpt.dll");
|
|
||||||
#else
|
|
||||||
openmpt.handle = SDL_LoadObject("libopenmpt.so");
|
|
||||||
#endif
|
|
||||||
if (openmpt.handle == NULL)
|
|
||||||
{
|
|
||||||
CONS_Printf("libopenmpt not found, not loading.\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// errors
|
|
||||||
FUNCTION_LOADER(module_error_get_last, openmpt_module_error_get_last, int (*) ( openmpt_module * mod ))
|
|
||||||
FUNCTION_LOADER(error_string, openmpt_error_string, const char *(*) ( int error ))
|
|
||||||
FUNCTION_LOADER(get_string, openmpt_get_string, const char *(*) ( const char * key ))
|
|
||||||
|
|
||||||
// module loading
|
|
||||||
FUNCTION_LOADER(module_destroy, openmpt_module_destroy, void (*) ( openmpt_module * mod ))
|
|
||||||
FUNCTION_LOADER(module_create_from_memory2, openmpt_module_create_from_memory2, openmpt_module *(*) ( const void * filedata, size_t filesize, openmpt_log_func logfunc, void * loguser, openmpt_error_func errfunc, void * erruser, int * error, const char * * error_message, const openmpt_module_initial_ctl * ctls ))
|
|
||||||
|
|
||||||
// audio callback
|
|
||||||
FUNCTION_LOADER(module_read_interleaved_stereo, openmpt_module_read_interleaved_stereo, size_t (*) ( openmpt_module * mod, int32_t samplerate, size_t count, int16_t * interleaved_stereo ))
|
|
||||||
|
|
||||||
// playback settings
|
|
||||||
FUNCTION_LOADER(module_set_render_param, openmpt_module_set_render_param, int (*) ( openmpt_module * mod, int param, int32_t value ))
|
|
||||||
FUNCTION_LOADER(module_set_repeat_count, openmpt_module_set_repeat_count, int (*) ( openmpt_module * mod, int32_t repeat_count ))
|
|
||||||
FUNCTION_LOADER(module_ctl_set, openmpt_module_ctl_set, int (*) ( openmpt_module * mod, const char * ctl, const char * value ))
|
|
||||||
|
|
||||||
// positioning
|
|
||||||
FUNCTION_LOADER(module_get_duration_seconds, openmpt_module_get_duration_seconds, double (*) ( openmpt_module * mod ))
|
|
||||||
FUNCTION_LOADER(module_get_position_seconds, openmpt_module_get_position_seconds, double (*) ( openmpt_module * mod ))
|
|
||||||
FUNCTION_LOADER(module_set_position_seconds, openmpt_module_set_position_seconds, double (*) ( openmpt_module * mod, double seconds ))
|
|
||||||
FUNCTION_LOADER(module_get_num_subsongs, openmpt_module_get_num_subsongs, int32_t (*) ( openmpt_module * mod ))
|
|
||||||
FUNCTION_LOADER(module_select_subsong, openmpt_module_select_subsong, int (*) ( openmpt_module * mod, int32_t subsong ))
|
|
||||||
|
|
||||||
#ifdef OPENMPT_DYNAMIC
|
|
||||||
// this will be unset if a function failed to load
|
|
||||||
if (openmpt.handle == NULL)
|
|
||||||
{
|
|
||||||
CONS_Printf("libopenmpt found but failed to load.\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CONS_Printf("libopenmpt version: %s\n", openmpt.get_string("library_version"));
|
|
||||||
CONS_Printf("libopenmpt build date: %s\n", openmpt.get_string("build"));
|
|
||||||
|
|
||||||
openmpt.loaded = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void unload_openmpt(void)
|
|
||||||
{
|
|
||||||
#ifdef OPENMPT_DYNAMIC
|
|
||||||
if (openmpt.loaded)
|
|
||||||
{
|
|
||||||
SDL_UnloadObject(openmpt.handle);
|
|
||||||
openmpt.handle = NULL;
|
|
||||||
openmpt.loaded = 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef FUNCTION_LOADER
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,52 +0,0 @@
|
||||||
///
|
|
||||||
/// Dynamic Library Loading
|
|
||||||
///
|
|
||||||
|
|
||||||
///
|
|
||||||
/// OpenMPT Loading
|
|
||||||
///
|
|
||||||
|
|
||||||
#ifdef HAVE_OPENMPT
|
|
||||||
|
|
||||||
#include "libopenmpt/libopenmpt.h"
|
|
||||||
|
|
||||||
// Dynamic loading inspired by SDL Mixer
|
|
||||||
// Why: It's hard to compile for Windows without MSVC dependency, see https://trac.videolan.org/vlc/ticket/13055
|
|
||||||
// So let's not force that on the user, and they can download it if they want.
|
|
||||||
//
|
|
||||||
// ADD FUNCTIONS HERE AS YOU USE THEM!!!!!
|
|
||||||
typedef struct {
|
|
||||||
int loaded;
|
|
||||||
void *handle;
|
|
||||||
|
|
||||||
// errors
|
|
||||||
int (*module_error_get_last) ( openmpt_module * mod );
|
|
||||||
const char *(*error_string) ( int error );
|
|
||||||
const char *(*get_string) ( const char * key );
|
|
||||||
|
|
||||||
// module loading
|
|
||||||
void (*module_destroy) ( openmpt_module * mod );
|
|
||||||
openmpt_module *(*module_create_from_memory2) ( const void * filedata, size_t filesize, openmpt_log_func logfunc, void * loguser, openmpt_error_func errfunc, void * erruser, int * error, const char * * error_message, const openmpt_module_initial_ctl * ctls );
|
|
||||||
|
|
||||||
// audio callback
|
|
||||||
size_t (*module_read_interleaved_stereo) ( openmpt_module * mod, int32_t samplerate, size_t count, int16_t * interleaved_stereo );
|
|
||||||
|
|
||||||
// playback settings
|
|
||||||
int (*module_set_render_param) ( openmpt_module * mod, int param, int32_t value );
|
|
||||||
int (*module_set_repeat_count) ( openmpt_module * mod, int32_t repeat_count );
|
|
||||||
int (*module_ctl_set) ( openmpt_module * mod, const char * ctl, const char * value );
|
|
||||||
|
|
||||||
// positioning
|
|
||||||
double (*module_get_duration_seconds) ( openmpt_module * mod );
|
|
||||||
double (*module_get_position_seconds) ( openmpt_module * mod );
|
|
||||||
double (*module_set_position_seconds) ( openmpt_module * mod, double seconds );
|
|
||||||
int32_t (*module_get_num_subsongs) ( openmpt_module * mod );
|
|
||||||
int (*module_select_subsong) ( openmpt_module * mod, int32_t subsong );
|
|
||||||
} openmpt_loader;
|
|
||||||
|
|
||||||
extern openmpt_loader openmpt;
|
|
||||||
|
|
||||||
void load_openmpt(void);
|
|
||||||
void unload_openmpt(void);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -20,8 +20,6 @@
|
||||||
#include "../z_zone.h"
|
#include "../z_zone.h"
|
||||||
#include "../byteptr.h"
|
#include "../byteptr.h"
|
||||||
|
|
||||||
#include "load_libraries.h"
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(disable : 4214 4244)
|
#pragma warning(disable : 4214 4244)
|
||||||
#endif
|
#endif
|
||||||
|
@ -174,7 +172,8 @@ void I_StartupSound(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_OPENMPT
|
#ifdef HAVE_OPENMPT
|
||||||
load_openmpt();
|
CONS_Printf("libopenmpt version: %s\n", openmpt_get_string("library_version"));
|
||||||
|
CONS_Printf("libopenmpt build date: %s\n", openmpt_get_string("build"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sound_started = true;
|
sound_started = true;
|
||||||
|
@ -201,8 +200,7 @@ void I_ShutdownSound(void)
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_OPENMPT
|
#ifdef HAVE_OPENMPT
|
||||||
if (mod)
|
if (mod)
|
||||||
openmpt.module_destroy(mod);
|
openmpt_module_destroy(mod);
|
||||||
unload_openmpt();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -671,9 +669,9 @@ static void mix_openmpt(void *udata, Uint8 *stream, int len)
|
||||||
|
|
||||||
(void)udata;
|
(void)udata;
|
||||||
|
|
||||||
openmpt.module_set_render_param(mod, OPENMPT_MODULE_RENDER_INTERPOLATIONFILTER_LENGTH, cv_modfilter.value);
|
openmpt_module_set_render_param(mod, OPENMPT_MODULE_RENDER_INTERPOLATIONFILTER_LENGTH, cv_modfilter.value);
|
||||||
openmpt.module_set_repeat_count(mod, -1); // Always repeat
|
openmpt_module_set_repeat_count(mod, -1); // Always repeat
|
||||||
openmpt.module_read_interleaved_stereo(mod, SAMPLERATE, BUFFERSIZE, (short *)stream);
|
openmpt_module_read_interleaved_stereo(mod, SAMPLERATE, BUFFERSIZE, (short *)stream);
|
||||||
|
|
||||||
// apply volume to stream
|
// apply volume to stream
|
||||||
for (i = 0, p = (short *)stream; i < len/2; i++, p++)
|
for (i = 0, p = (short *)stream; i < len/2; i++, p++)
|
||||||
|
@ -762,7 +760,7 @@ boolean I_SetSongSpeed(float speed)
|
||||||
{
|
{
|
||||||
char modspd[16];
|
char modspd[16];
|
||||||
sprintf(modspd, "%g", speed);
|
sprintf(modspd, "%g", speed);
|
||||||
openmpt.module_ctl_set(mod, "play.tempo_factor", modspd);
|
openmpt_module_ctl_set(mod, "play.tempo_factor", modspd);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -811,7 +809,7 @@ UINT32 I_GetSongLength(void)
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_OPENMPT
|
#ifdef HAVE_OPENMPT
|
||||||
if (mod)
|
if (mod)
|
||||||
return (UINT32)(openmpt.module_get_duration_seconds(mod) * 1000.);
|
return (UINT32)(openmpt_module_get_duration_seconds(mod) * 1000.);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
if (!music || I_SongType() == MU_MOD || I_SongType() == MU_MID)
|
if (!music || I_SongType() == MU_MOD || I_SongType() == MU_MID)
|
||||||
|
@ -904,7 +902,7 @@ boolean I_SetSongPosition(UINT32 position)
|
||||||
{
|
{
|
||||||
// This isn't 100% correct because we don't account for loop points because we can't get them.
|
// This isn't 100% correct because we don't account for loop points because we can't get them.
|
||||||
// But if you seek past end of song, OpenMPT seeks to 0. So adjust the position anyway.
|
// But if you seek past end of song, OpenMPT seeks to 0. So adjust the position anyway.
|
||||||
openmpt.module_set_position_seconds(mod, (double)(get_adjusted_position(position)/1000.0L)); // returns new position
|
openmpt_module_set_position_seconds(mod, (double)(get_adjusted_position(position)/1000.0L)); // returns new position
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -970,8 +968,8 @@ UINT32 I_GetSongPosition(void)
|
||||||
if (mod)
|
if (mod)
|
||||||
// This will be incorrect if we adjust for length because we can't get loop points.
|
// This will be incorrect if we adjust for length because we can't get loop points.
|
||||||
// So return unadjusted. See note in SetMusicPosition: we adjust for that.
|
// So return unadjusted. See note in SetMusicPosition: we adjust for that.
|
||||||
return (UINT32)(openmpt.module_get_position_seconds(mod)*1000.);
|
return (UINT32)(openmpt_module_get_position_seconds(mod)*1000.);
|
||||||
//return get_adjusted_position((UINT32)(openmpt.module_get_position_seconds(mod)*1000.));
|
//return get_adjusted_position((UINT32)(openmpt_module_get_position_seconds(mod)*1000.));
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
if (!music || I_SongType() == MU_MID)
|
if (!music || I_SongType() == MU_MID)
|
||||||
|
@ -1141,13 +1139,11 @@ boolean I_LoadSong(char *data, size_t len)
|
||||||
{
|
{
|
||||||
case MUS_MODPLUG_UNUSED:
|
case MUS_MODPLUG_UNUSED:
|
||||||
case MUS_MOD:
|
case MUS_MOD:
|
||||||
if (openmpt.loaded)
|
mod = openmpt_module_create_from_memory2(data, len, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||||
{
|
|
||||||
mod = openmpt.module_create_from_memory2(data, len, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
|
||||||
if (!mod)
|
if (!mod)
|
||||||
{
|
{
|
||||||
mod_err = openmpt.module_error_get_last(mod);
|
mod_err = openmpt_module_error_get_last(mod);
|
||||||
mod_err_str = openmpt.error_string(mod_err);
|
mod_err_str = openmpt_error_string(mod_err);
|
||||||
CONS_Alert(CONS_ERROR, "openmpt_module_create_from_memory2: %s\n", mod_err_str);
|
CONS_Alert(CONS_ERROR, "openmpt_module_create_from_memory2: %s\n", mod_err_str);
|
||||||
Mix_FreeMusic(music);
|
Mix_FreeMusic(music);
|
||||||
music = NULL;
|
music = NULL;
|
||||||
|
@ -1160,8 +1156,6 @@ boolean I_LoadSong(char *data, size_t len)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
// else, fall through
|
|
||||||
case MUS_WAV:
|
case MUS_WAV:
|
||||||
case MUS_MID:
|
case MUS_MID:
|
||||||
case MUS_OGG:
|
case MUS_OGG:
|
||||||
|
@ -1274,7 +1268,7 @@ void I_UnloadSong(void)
|
||||||
#ifdef HAVE_OPENMPT
|
#ifdef HAVE_OPENMPT
|
||||||
if (mod)
|
if (mod)
|
||||||
{
|
{
|
||||||
openmpt.module_destroy(mod);
|
openmpt_module_destroy(mod);
|
||||||
mod = NULL;
|
mod = NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1300,7 +1294,7 @@ boolean I_PlaySong(boolean looping)
|
||||||
#ifdef HAVE_OPENMPT
|
#ifdef HAVE_OPENMPT
|
||||||
if (mod)
|
if (mod)
|
||||||
{
|
{
|
||||||
openmpt.module_select_subsong(mod, 0);
|
openmpt_module_select_subsong(mod, 0);
|
||||||
current_subsong = 0;
|
current_subsong = 0;
|
||||||
Mix_HookMusic(mix_openmpt, mod);
|
Mix_HookMusic(mix_openmpt, mod);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1444,9 +1438,9 @@ boolean I_SetSongTrack(int track)
|
||||||
if (current_subsong == track)
|
if (current_subsong == track)
|
||||||
return false;
|
return false;
|
||||||
SDL_LockAudio();
|
SDL_LockAudio();
|
||||||
if (track >= 0 && track < openmpt.module_get_num_subsongs(mod))
|
if (track >= 0 && track < openmpt_module_get_num_subsongs(mod))
|
||||||
{
|
{
|
||||||
openmpt.module_select_subsong(mod, track);
|
openmpt_module_select_subsong(mod, track);
|
||||||
current_subsong = track;
|
current_subsong = track;
|
||||||
SDL_UnlockAudio();
|
SDL_UnlockAudio();
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue