From 126dbeaa1eeaa2abbd952353892e31e33608c292 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 24 Jan 2011 21:18:22 -0800 Subject: [PATCH] Move decoder (de)initialization into their respective classes --- include/main.h | 9 +- src/alure.cpp | 327 ++--------------------------------------------- src/codec_aiff.cpp | 5 + src/codec_dumb.cpp | 43 ++++++- src/codec_flac.cpp | 36 +++++- src/codec_fluidsynth.cpp | 45 ++++++- src/codec_modplug.cpp | 32 ++++- src/codec_mpg123.cpp | 43 ++++++- src/codec_sndfile.cpp | 32 ++++- src/codec_vorbisfile.cpp | 34 ++++- src/codec_wav.cpp | 5 + 11 files changed, 272 insertions(+), 339 deletions(-) diff --git a/include/main.h b/include/main.h index 5599e38..c5f7618 100644 --- a/include/main.h +++ b/include/main.h @@ -104,7 +104,7 @@ if(!(p##x)) \ { \ CloseLib((h)); \ (h) = NULL; \ - break; \ + return; \ } #endif @@ -328,11 +328,16 @@ protected: template struct DecoderDecl : public Decoder { - DecoderDecl() { AddList(Factory); } + DecoderDecl() + { + T::Init(); + AddList(Factory); + } ~DecoderDecl() { ListType &list = AddList(NULL); list.erase(std::find(list.begin(), list.end(), Factory)); + T::Deinit(); } private: diff --git a/src/alure.cpp b/src/alure.cpp index 621d596..e481758 100644 --- a/src/alure.cpp +++ b/src/alure.cpp @@ -44,117 +44,6 @@ CRITICAL_SECTION cs_StreamPlay; alureStream::ListType alureStream::StreamList; -#ifdef HAS_SNDFILE -#include -#endif -#ifdef HAS_VORBISFILE -#include -#endif -#ifdef HAS_FLAC -#include -#endif -#ifdef HAS_MPG123 -#include -#endif -#ifdef HAS_DUMB -#include -#endif -#ifdef HAS_MODPLUG -#include -#endif -#ifdef HAS_FLUIDSYNTH -#include -#endif - -#define MAKE_FUNC(x) extern typeof(x)* p##x -#ifdef HAS_VORBISFILE -extern void *vorbisfile_handle; -MAKE_FUNC(ov_clear); -MAKE_FUNC(ov_info); -MAKE_FUNC(ov_open_callbacks); -MAKE_FUNC(ov_pcm_seek); -MAKE_FUNC(ov_read); -#endif -#ifdef HAS_FLAC -extern void *flac_handle; -MAKE_FUNC(FLAC__stream_decoder_get_state); -MAKE_FUNC(FLAC__stream_decoder_finish); -MAKE_FUNC(FLAC__stream_decoder_new); -MAKE_FUNC(FLAC__stream_decoder_seek_absolute); -MAKE_FUNC(FLAC__stream_decoder_delete); -MAKE_FUNC(FLAC__stream_decoder_process_single); -MAKE_FUNC(FLAC__stream_decoder_init_stream); -#endif -#ifdef HAS_DUMB -extern void *dumb_handle; -MAKE_FUNC(dumbfile_open_ex); -MAKE_FUNC(dumbfile_close); -MAKE_FUNC(dumb_read_mod); -MAKE_FUNC(dumb_read_s3m); -MAKE_FUNC(dumb_read_xm); -MAKE_FUNC(dumb_read_it); -MAKE_FUNC(dumb_silence); -MAKE_FUNC(duh_sigrenderer_generate_samples); -MAKE_FUNC(duh_get_it_sigrenderer); -MAKE_FUNC(duh_end_sigrenderer); -MAKE_FUNC(unload_duh); -MAKE_FUNC(dumb_it_start_at_order); -MAKE_FUNC(dumb_it_set_loop_callback); -MAKE_FUNC(dumb_it_sr_get_speed); -MAKE_FUNC(dumb_it_sr_set_speed); -#endif -#ifdef HAS_MODPLUG -extern void *mod_handle; -MAKE_FUNC(ModPlug_Load); -MAKE_FUNC(ModPlug_Unload); -MAKE_FUNC(ModPlug_Read); -MAKE_FUNC(ModPlug_SeekOrder); -#endif -#ifdef HAS_MPG123 -extern void *mp123_handle; -MAKE_FUNC(mpg123_read); -MAKE_FUNC(mpg123_init); -MAKE_FUNC(mpg123_open_feed); -MAKE_FUNC(mpg123_new); -MAKE_FUNC(mpg123_delete); -MAKE_FUNC(mpg123_feed); -MAKE_FUNC(mpg123_exit); -MAKE_FUNC(mpg123_getformat); -MAKE_FUNC(mpg123_format_none); -MAKE_FUNC(mpg123_decode); -MAKE_FUNC(mpg123_format); -#endif -#ifdef HAS_SNDFILE -extern void *sndfile_handle; -MAKE_FUNC(sf_close); -MAKE_FUNC(sf_open_virtual); -MAKE_FUNC(sf_readf_short); -MAKE_FUNC(sf_seek); -#endif -#ifdef HAS_FLUIDSYNTH -extern void *fsynth_handle; -MAKE_FUNC(fluid_settings_setstr); -MAKE_FUNC(fluid_synth_program_change); -MAKE_FUNC(fluid_synth_sfload); -MAKE_FUNC(fluid_settings_setnum); -MAKE_FUNC(fluid_synth_sysex); -MAKE_FUNC(fluid_synth_cc); -MAKE_FUNC(fluid_synth_pitch_bend); -MAKE_FUNC(fluid_synth_channel_pressure); -MAKE_FUNC(fluid_synth_write_float); -MAKE_FUNC(new_fluid_synth); -MAKE_FUNC(delete_fluid_settings); -MAKE_FUNC(delete_fluid_synth); -MAKE_FUNC(fluid_synth_program_reset); -MAKE_FUNC(fluid_settings_setint); -MAKE_FUNC(new_fluid_settings); -MAKE_FUNC(fluid_synth_write_s16); -MAKE_FUNC(fluid_synth_noteoff); -MAKE_FUNC(fluid_synth_sfunload); -MAKE_FUNC(fluid_synth_noteon); -#endif -#undef MAKE_FUNC - #ifdef HAVE_GCC_CONSTRUCTOR static void init_alure(void) __attribute__((constructor)); static void deinit_alure(void) __attribute__((destructor)); @@ -201,6 +90,16 @@ static struct MyConstructorClass { } MyConstructor; #endif +static void init_alure(void) +{ + InitializeCriticalSection(&cs_StreamPlay); +} + +static void deinit_alure(void) +{ + DeleteCriticalSection(&cs_StreamPlay); +} + #ifndef DYNLOAD void *OpenLib(const char*) @@ -245,218 +144,14 @@ void CloseLib(void *hdl) { dlclose(hdl); } #endif -static void init_alure(void) -{ - InitializeCriticalSection(&cs_StreamPlay); - -#ifdef _WIN32 -#define VORBISFILE_LIB "vorbisfile.dll" -#define FLAC_LIB "libFLAC.dll" -#define DUMB_LIB "libdumb.dll" -#define MODPLUG_LIB "libmodplug.dll" -#define MPG123_LIB "libmpg123.dll" -#define SNDFILE_LIB "libsndfile-1.dll" -#define FLUIDSYNTH_LIB "libfluidsynth.dll" -#elif defined(__APPLE__) -#define VORBISFILE_LIB "libvorbisfile.3.dylib" -#define FLAC_LIB "libFLAC.8.dylib" -#define DUMB_LIB "libdumb.dylib" -#define MODPLUG_LIB "libmodplug.1.dylib" -#define MPG123_LIB "libmpg123.0.dylib" -#define SNDFILE_LIB "libsndfile.1.dylib" -#define FLUIDSYNTH_LIB "libfluidsynth.1.dylib" -#else -#define VORBISFILE_LIB "libvorbisfile.so.3" -#define FLAC_LIB "libFLAC.so.8" -#define DUMB_LIB "libdumb.so" -#define MODPLUG_LIB "libmodplug.so.1" -#define MPG123_LIB "libmpg123.so.0" -#define SNDFILE_LIB "libsndfile.so.1" -#define FLUIDSYNTH_LIB "libfluidsynth.so.1" -#endif - -#ifdef HAS_VORBISFILE - vorbisfile_handle = OpenLib(VORBISFILE_LIB); - while(vorbisfile_handle) - { - LOAD_FUNC(vorbisfile_handle, ov_clear); - LOAD_FUNC(vorbisfile_handle, ov_info); - LOAD_FUNC(vorbisfile_handle, ov_open_callbacks); - LOAD_FUNC(vorbisfile_handle, ov_pcm_seek); - LOAD_FUNC(vorbisfile_handle, ov_read); - break; - } -#endif - -#ifdef HAS_FLAC - flac_handle = OpenLib(FLAC_LIB); - while(flac_handle) - { - LOAD_FUNC(flac_handle, FLAC__stream_decoder_get_state); - LOAD_FUNC(flac_handle, FLAC__stream_decoder_finish); - LOAD_FUNC(flac_handle, FLAC__stream_decoder_new); - LOAD_FUNC(flac_handle, FLAC__stream_decoder_seek_absolute); - LOAD_FUNC(flac_handle, FLAC__stream_decoder_delete); - LOAD_FUNC(flac_handle, FLAC__stream_decoder_process_single); - LOAD_FUNC(flac_handle, FLAC__stream_decoder_init_stream); - break; - } -#endif - -#ifdef HAS_DUMB - dumb_handle = OpenLib(DUMB_LIB); - while(dumb_handle) - { - LOAD_FUNC(dumb_handle, dumbfile_open_ex); - LOAD_FUNC(dumb_handle, dumbfile_close); - LOAD_FUNC(dumb_handle, dumb_read_mod); - LOAD_FUNC(dumb_handle, dumb_read_s3m); - LOAD_FUNC(dumb_handle, dumb_read_xm); - LOAD_FUNC(dumb_handle, dumb_read_it); - LOAD_FUNC(dumb_handle, dumb_silence); - LOAD_FUNC(dumb_handle, duh_sigrenderer_generate_samples); - LOAD_FUNC(dumb_handle, duh_get_it_sigrenderer); - LOAD_FUNC(dumb_handle, duh_end_sigrenderer); - LOAD_FUNC(dumb_handle, unload_duh); - LOAD_FUNC(dumb_handle, dumb_it_start_at_order); - LOAD_FUNC(dumb_handle, dumb_it_set_loop_callback); - LOAD_FUNC(dumb_handle, dumb_it_sr_get_speed); - LOAD_FUNC(dumb_handle, dumb_it_sr_set_speed); - break; - } -#endif - -#ifdef HAS_MODPLUG - mod_handle = OpenLib(MODPLUG_LIB); - while(mod_handle) - { - LOAD_FUNC(mod_handle, ModPlug_Load); - LOAD_FUNC(mod_handle, ModPlug_Unload); - LOAD_FUNC(mod_handle, ModPlug_Read); - LOAD_FUNC(mod_handle, ModPlug_SeekOrder); - break; - } -#endif - -#ifdef HAS_MPG123 - mp123_handle = OpenLib(MPG123_LIB); - while(mp123_handle) - { - LOAD_FUNC(mp123_handle, mpg123_read); - LOAD_FUNC(mp123_handle, mpg123_init); - LOAD_FUNC(mp123_handle, mpg123_open_feed); - LOAD_FUNC(mp123_handle, mpg123_new); - LOAD_FUNC(mp123_handle, mpg123_delete); - LOAD_FUNC(mp123_handle, mpg123_feed); - LOAD_FUNC(mp123_handle, mpg123_exit); - LOAD_FUNC(mp123_handle, mpg123_getformat); - LOAD_FUNC(mp123_handle, mpg123_format_none); - LOAD_FUNC(mp123_handle, mpg123_decode); - LOAD_FUNC(mp123_handle, mpg123_format); - pmpg123_init(); - break; - } -#endif - -#ifdef HAS_SNDFILE - sndfile_handle = OpenLib(SNDFILE_LIB); - while(sndfile_handle) - { - LOAD_FUNC(sndfile_handle, sf_close); - LOAD_FUNC(sndfile_handle, sf_open_virtual); - LOAD_FUNC(sndfile_handle, sf_readf_short); - LOAD_FUNC(sndfile_handle, sf_seek); - break; - } -#endif - -#ifdef HAS_FLUIDSYNTH - fsynth_handle = OpenLib(FLUIDSYNTH_LIB); - while(fsynth_handle) - { - LOAD_FUNC(fsynth_handle, fluid_settings_setstr); - LOAD_FUNC(fsynth_handle, fluid_synth_program_change); - LOAD_FUNC(fsynth_handle, fluid_synth_sfload); - LOAD_FUNC(fsynth_handle, fluid_settings_setnum); - LOAD_FUNC(fsynth_handle, fluid_synth_sysex); - LOAD_FUNC(fsynth_handle, fluid_synth_cc); - LOAD_FUNC(fsynth_handle, fluid_synth_pitch_bend); - LOAD_FUNC(fsynth_handle, fluid_synth_channel_pressure); - LOAD_FUNC(fsynth_handle, fluid_synth_write_float); - LOAD_FUNC(fsynth_handle, new_fluid_synth); - LOAD_FUNC(fsynth_handle, delete_fluid_settings); - LOAD_FUNC(fsynth_handle, delete_fluid_synth); - LOAD_FUNC(fsynth_handle, fluid_synth_program_reset); - LOAD_FUNC(fsynth_handle, fluid_settings_setint); - LOAD_FUNC(fsynth_handle, new_fluid_settings); - LOAD_FUNC(fsynth_handle, fluid_synth_write_s16); - LOAD_FUNC(fsynth_handle, fluid_synth_noteoff); - LOAD_FUNC(fsynth_handle, fluid_synth_sfunload); - LOAD_FUNC(fsynth_handle, fluid_synth_noteon); - break; - } -#endif - -#undef VORBISFILE_LIB -#undef FLAC_LIB -#undef DUMB_LIB -#undef MPG123_LIB -#undef SNDFILE_LIB -#undef LOAD_FUNC -} - -static void deinit_alure(void) -{ -#ifdef HAS_VORBISFILE - if(vorbisfile_handle) - CloseLib(vorbisfile_handle); - vorbisfile_handle = NULL; -#endif -#ifdef HAS_FLAC - if(flac_handle) - CloseLib(flac_handle); - flac_handle = NULL; -#endif -#ifdef HAS_DUMB - if(dumb_handle) - CloseLib(dumb_handle); - dumb_handle = NULL; -#endif -#ifdef HAS_MODPLUG - if(mod_handle) - CloseLib(mod_handle); - mod_handle = NULL; -#endif -#ifdef HAS_MPG123 - if(mp123_handle) - { - pmpg123_exit(); - CloseLib(mp123_handle); - } - mp123_handle = NULL; -#endif -#ifdef HAS_SNDFILE - if(sndfile_handle) - CloseLib(sndfile_handle); - sndfile_handle = NULL; -#endif -#ifdef HAS_FLUIDSYNTH - if(fsynth_handle) - CloseLib(fsynth_handle); - fsynth_handle = NULL; -#endif - - DeleteCriticalSection(&cs_StreamPlay); -} - static const ALchar *last_error = "No error"; - void SetError(const char *err) { last_error = err; } + ALuint DetectBlockAlignment(ALenum format) { switch(format) diff --git a/src/codec_aiff.cpp b/src/codec_aiff.cpp index a03d70c..6c3001c 100644 --- a/src/codec_aiff.cpp +++ b/src/codec_aiff.cpp @@ -32,6 +32,7 @@ struct aiffStream : public alureStream { +private: ALenum format; int samplerate; int blockAlign; @@ -40,6 +41,10 @@ struct aiffStream : public alureStream { long dataLen; size_t remLen; +public: + static void Init() { } + static void Deinit() { } + virtual bool IsValid() { return (dataStart > 0 && format != AL_NONE); } diff --git a/src/codec_dumb.cpp b/src/codec_dumb.cpp index afbabac..4d19958 100644 --- a/src/codec_dumb.cpp +++ b/src/codec_dumb.cpp @@ -33,9 +33,16 @@ #include -void *dumb_handle; - -#define MAKE_FUNC(x) typeof(x)* p##x +#ifdef _WIN32 +#define DUMB_LIB "libdumb.dll" +#elif defined(__APPLE__) +#define DUMB_LIB "libdumb.dylib" +#else +#define DUMB_LIB "libdumb.so" +#endif + +static void *dumb_handle; +#define MAKE_FUNC(x) static typeof(x)* p##x MAKE_FUNC(dumbfile_open_ex); MAKE_FUNC(dumbfile_close); MAKE_FUNC(dumb_read_mod); @@ -55,6 +62,7 @@ MAKE_FUNC(dumb_it_sr_set_speed); struct dumbStream : public alureStream { +private: DUMBFILE_SYSTEM vfs; DUMBFILE *dumbFile; DUH *duh; @@ -64,6 +72,35 @@ struct dumbStream : public alureStream { ALenum format; ALCint samplerate; +public: + static void Init() + { + dumb_handle = OpenLib(DUMB_LIB); + if(!dumb_handle) return; + + LOAD_FUNC(dumb_handle, dumbfile_open_ex); + LOAD_FUNC(dumb_handle, dumbfile_close); + LOAD_FUNC(dumb_handle, dumb_read_mod); + LOAD_FUNC(dumb_handle, dumb_read_s3m); + LOAD_FUNC(dumb_handle, dumb_read_xm); + LOAD_FUNC(dumb_handle, dumb_read_it); + LOAD_FUNC(dumb_handle, dumb_silence); + LOAD_FUNC(dumb_handle, duh_sigrenderer_generate_samples); + LOAD_FUNC(dumb_handle, duh_get_it_sigrenderer); + LOAD_FUNC(dumb_handle, duh_end_sigrenderer); + LOAD_FUNC(dumb_handle, unload_duh); + LOAD_FUNC(dumb_handle, dumb_it_start_at_order); + LOAD_FUNC(dumb_handle, dumb_it_set_loop_callback); + LOAD_FUNC(dumb_handle, dumb_it_sr_get_speed); + LOAD_FUNC(dumb_handle, dumb_it_sr_set_speed); + } + static void Deinit() + { + if(dumb_handle) + CloseLib(dumb_handle); + dumb_handle = NULL; + } + virtual bool IsValid() { return renderer != NULL; } diff --git a/src/codec_flac.cpp b/src/codec_flac.cpp index a391142..c73cae3 100644 --- a/src/codec_flac.cpp +++ b/src/codec_flac.cpp @@ -33,9 +33,16 @@ #include -void *flac_handle; - -#define MAKE_FUNC(x) typeof(x)* p##x +#ifdef _WIN32 +#define FLAC_LIB "libFLAC.dll" +#elif defined(__APPLE__) +#define FLAC_LIB "libFLAC.8.dylib" +#else +#define FLAC_LIB "libFLAC.so.8" +#endif + +static void *flac_handle; +#define MAKE_FUNC(x) static typeof(x)* p##x MAKE_FUNC(FLAC__stream_decoder_get_state); MAKE_FUNC(FLAC__stream_decoder_finish); MAKE_FUNC(FLAC__stream_decoder_new); @@ -45,7 +52,9 @@ MAKE_FUNC(FLAC__stream_decoder_process_single); MAKE_FUNC(FLAC__stream_decoder_init_stream); #undef MAKE_FUNC + struct flacStream : public alureStream { +private: FLAC__StreamDecoder *flacFile; ALenum format; ALuint samplerate; @@ -58,6 +67,27 @@ struct flacStream : public alureStream { ALuint outLen; ALuint outTotal; +public: + static void Init() + { + flac_handle = OpenLib(FLAC_LIB); + if(!flac_handle) return; + + LOAD_FUNC(flac_handle, FLAC__stream_decoder_get_state); + LOAD_FUNC(flac_handle, FLAC__stream_decoder_finish); + LOAD_FUNC(flac_handle, FLAC__stream_decoder_new); + LOAD_FUNC(flac_handle, FLAC__stream_decoder_seek_absolute); + LOAD_FUNC(flac_handle, FLAC__stream_decoder_delete); + LOAD_FUNC(flac_handle, FLAC__stream_decoder_process_single); + LOAD_FUNC(flac_handle, FLAC__stream_decoder_init_stream); + } + static void Deinit() + { + if(flac_handle) + CloseLib(flac_handle); + flac_handle = NULL; + } + virtual bool IsValid() { return flacFile != NULL; } diff --git a/src/codec_fluidsynth.cpp b/src/codec_fluidsynth.cpp index d8c37f0..d1d6547 100644 --- a/src/codec_fluidsynth.cpp +++ b/src/codec_fluidsynth.cpp @@ -33,9 +33,16 @@ #include -void *fsynth_handle; - -#define MAKE_FUNC(x) typeof(x)* p##x +#ifdef _WIN32 +#define FLUIDSYNTH_LIB "libfluidsynth.dll" +#elif defined(__APPLE__) +#define FLUIDSYNTH_LIB "libfluidsynth.1.dylib" +#else +#define FLUIDSYNTH_LIB "libfluidsynth.so.1" +#endif + +static void *fsynth_handle; +#define MAKE_FUNC(x) static typeof(x)* p##x MAKE_FUNC(fluid_settings_setstr); MAKE_FUNC(fluid_synth_program_change); MAKE_FUNC(fluid_synth_sfload); @@ -140,6 +147,38 @@ private: int fontID; public: + static void Init() + { + fsynth_handle = OpenLib(FLUIDSYNTH_LIB); + if(!fsynth_handle) + + LOAD_FUNC(fsynth_handle, fluid_settings_setstr); + LOAD_FUNC(fsynth_handle, fluid_synth_program_change); + LOAD_FUNC(fsynth_handle, fluid_synth_sfload); + LOAD_FUNC(fsynth_handle, fluid_settings_setnum); + LOAD_FUNC(fsynth_handle, fluid_synth_sysex); + LOAD_FUNC(fsynth_handle, fluid_synth_cc); + LOAD_FUNC(fsynth_handle, fluid_synth_pitch_bend); + LOAD_FUNC(fsynth_handle, fluid_synth_channel_pressure); + LOAD_FUNC(fsynth_handle, fluid_synth_write_float); + LOAD_FUNC(fsynth_handle, new_fluid_synth); + LOAD_FUNC(fsynth_handle, delete_fluid_settings); + LOAD_FUNC(fsynth_handle, delete_fluid_synth); + LOAD_FUNC(fsynth_handle, fluid_synth_program_reset); + LOAD_FUNC(fsynth_handle, fluid_settings_setint); + LOAD_FUNC(fsynth_handle, new_fluid_settings); + LOAD_FUNC(fsynth_handle, fluid_synth_write_s16); + LOAD_FUNC(fsynth_handle, fluid_synth_noteoff); + LOAD_FUNC(fsynth_handle, fluid_synth_sfunload); + LOAD_FUNC(fsynth_handle, fluid_synth_noteon); + } + static void Deinit() + { + if(fsynth_handle) + CloseLib(fsynth_handle); + fsynth_handle = NULL; + } + virtual bool IsValid() { return fluidSynth != NULL; } diff --git a/src/codec_modplug.cpp b/src/codec_modplug.cpp index 184885a..01ebf3f 100644 --- a/src/codec_modplug.cpp +++ b/src/codec_modplug.cpp @@ -33,9 +33,16 @@ #include -void *mod_handle; - -#define MAKE_FUNC(x) typeof(x)* p##x +#ifdef _WIN32 +#define MODPLUG_LIB "libmodplug.dll" +#elif defined(__APPLE__) +#define MODPLUG_LIB "libmodplug.1.dylib" +#else +#define MODPLUG_LIB "libmodplug.so.1" +#endif + +static void *mod_handle; +#define MAKE_FUNC(x) static typeof(x)* p##x MAKE_FUNC(ModPlug_Load); MAKE_FUNC(ModPlug_Unload); MAKE_FUNC(ModPlug_Read); @@ -44,9 +51,28 @@ MAKE_FUNC(ModPlug_SeekOrder); struct modStream : public alureStream { +private: ModPlugFile *modFile; int lastOrder; +public: + static void Init() + { + mod_handle = OpenLib(MODPLUG_LIB); + if(!mod_handle) return; + + LOAD_FUNC(mod_handle, ModPlug_Load); + LOAD_FUNC(mod_handle, ModPlug_Unload); + LOAD_FUNC(mod_handle, ModPlug_Read); + LOAD_FUNC(mod_handle, ModPlug_SeekOrder); + } + static void Deinit() + { + if(mod_handle) + CloseLib(mod_handle); + mod_handle = NULL; + } + virtual bool IsValid() { return modFile != NULL; } diff --git a/src/codec_mpg123.cpp b/src/codec_mpg123.cpp index 057b526..f77d7bd 100644 --- a/src/codec_mpg123.cpp +++ b/src/codec_mpg123.cpp @@ -33,9 +33,16 @@ #include -void *mp123_handle; - -#define MAKE_FUNC(x) typeof(x)* p##x +#ifdef _WIN32 +#define MPG123_LIB "libmpg123.dll" +#elif defined(__APPLE__) +#define MPG123_LIB "libmpg123.0.dylib" +#else +#define MPG123_LIB "libmpg123.so.0" +#endif + +static void *mp123_handle; +#define MAKE_FUNC(x) static typeof(x)* p##x MAKE_FUNC(mpg123_read); MAKE_FUNC(mpg123_init); MAKE_FUNC(mpg123_open_feed); @@ -51,6 +58,7 @@ MAKE_FUNC(mpg123_format); struct mp3Stream : public alureStream { +private: mpg123_handle *mp3File; long samplerate; int channels; @@ -58,6 +66,35 @@ struct mp3Stream : public alureStream { std::ios::pos_type dataStart; std::ios::pos_type dataEnd; +public: + static void Init() + { + mp123_handle = OpenLib(MPG123_LIB); + if(!mp123_handle) return; + + LOAD_FUNC(mp123_handle, mpg123_read); + LOAD_FUNC(mp123_handle, mpg123_init); + LOAD_FUNC(mp123_handle, mpg123_open_feed); + LOAD_FUNC(mp123_handle, mpg123_new); + LOAD_FUNC(mp123_handle, mpg123_delete); + LOAD_FUNC(mp123_handle, mpg123_feed); + LOAD_FUNC(mp123_handle, mpg123_exit); + LOAD_FUNC(mp123_handle, mpg123_getformat); + LOAD_FUNC(mp123_handle, mpg123_format_none); + LOAD_FUNC(mp123_handle, mpg123_decode); + LOAD_FUNC(mp123_handle, mpg123_format); + pmpg123_init(); + } + static void Deinit() + { + if(mp123_handle) + { + pmpg123_exit(); + CloseLib(mp123_handle); + } + mp123_handle = NULL; + } + virtual bool IsValid() { return mp3File != NULL; } diff --git a/src/codec_sndfile.cpp b/src/codec_sndfile.cpp index 610b6bc..908f30e 100644 --- a/src/codec_sndfile.cpp +++ b/src/codec_sndfile.cpp @@ -33,9 +33,16 @@ #include -void *sndfile_handle; - -#define MAKE_FUNC(x) typeof(x)* p##x +#ifdef _WIN32 +#define SNDFILE_LIB "libsndfile-1.dll" +#elif defined(__APPLE__) +#define SNDFILE_LIB "libsndfile.1.dylib" +#else +#define SNDFILE_LIB "libsndfile.so.1" +#endif + +static void *sndfile_handle; +#define MAKE_FUNC(x) static typeof(x)* p##x MAKE_FUNC(sf_close); MAKE_FUNC(sf_open_virtual); MAKE_FUNC(sf_readf_short); @@ -44,10 +51,29 @@ MAKE_FUNC(sf_seek); struct sndStream : public alureStream { +private: SNDFILE *sndFile; SF_INFO sndInfo; ALenum format; +public: + static void Init() + { + sndfile_handle = OpenLib(SNDFILE_LIB); + if(!sndfile_handle) return; + + LOAD_FUNC(sndfile_handle, sf_close); + LOAD_FUNC(sndfile_handle, sf_open_virtual); + LOAD_FUNC(sndfile_handle, sf_readf_short); + LOAD_FUNC(sndfile_handle, sf_seek); + } + static void Deinit() + { + if(sndfile_handle) + CloseLib(sndfile_handle); + sndfile_handle = NULL; + } + virtual bool IsValid() { return sndFile != NULL; } diff --git a/src/codec_vorbisfile.cpp b/src/codec_vorbisfile.cpp index 64ed89a..0c4bff6 100644 --- a/src/codec_vorbisfile.cpp +++ b/src/codec_vorbisfile.cpp @@ -33,22 +33,50 @@ #include -void *vorbisfile_handle; - -#define MAKE_FUNC(x) typeof(x)* p##x +#ifdef _WIN32 +#define VORBISFILE_LIB "vorbisfile.dll" +#elif defined(__APPLE__) +#define VORBISFILE_LIB "libvorbisfile.3.dylib" +#else +#define VORBISFILE_LIB "libvorbisfile.so.3" +#endif + +static void *vorbisfile_handle; +#define MAKE_FUNC(x) static typeof(x)* p##x MAKE_FUNC(ov_clear); MAKE_FUNC(ov_info); MAKE_FUNC(ov_open_callbacks); MAKE_FUNC(ov_pcm_seek); MAKE_FUNC(ov_read); +#undef MAKE_FUNC struct oggStream : public alureStream { +private: OggVorbis_File oggFile; vorbis_info *oggInfo; int oggBitstream; ALenum format; +public: + static void Init() + { + vorbisfile_handle = OpenLib(VORBISFILE_LIB); + if(!vorbisfile_handle) return; + + LOAD_FUNC(vorbisfile_handle, ov_clear); + LOAD_FUNC(vorbisfile_handle, ov_info); + LOAD_FUNC(vorbisfile_handle, ov_open_callbacks); + LOAD_FUNC(vorbisfile_handle, ov_pcm_seek); + LOAD_FUNC(vorbisfile_handle, ov_read); + } + static void Deinit() + { + if(vorbisfile_handle) + CloseLib(vorbisfile_handle); + vorbisfile_handle = NULL; + } + virtual bool IsValid() { return oggInfo != NULL; } diff --git a/src/codec_wav.cpp b/src/codec_wav.cpp index 14f3723..fc9ef21 100644 --- a/src/codec_wav.cpp +++ b/src/codec_wav.cpp @@ -32,6 +32,7 @@ struct wavStream : public alureStream { +private: ALenum format; int samplerate; int blockAlign; @@ -40,6 +41,10 @@ struct wavStream : public alureStream { long dataLen; size_t remLen; +public: + static void Init() { } + static void Deinit() { } + virtual bool IsValid() { return (dataStart > 0 && format != AL_NONE); } -- 2.11.4.GIT