Skip to content

Commit

Permalink
Add OpenMPT support
Browse files Browse the repository at this point in the history
  • Loading branch information
SiegeLordEx authored and SiegeLord committed Apr 25, 2024
1 parent 90d9131 commit bcf1b3b
Show file tree
Hide file tree
Showing 7 changed files with 396 additions and 1 deletion.
33 changes: 33 additions & 0 deletions addons/acodec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ option(WANT_VORBIS "Enable Ogg Vorbis support using libvorbis" on)
option(WANT_TREMOR "Enable Ogg Vorbis support using Tremor" off)
option(WANT_OPUS "Enable Opus support using libopus" on)
option(WANT_MODAUDIO "Enable MOD Audio support" on)
option(WANT_OPENMPT "Enable OpenMPT Audio support" on)
option(WANT_ACODEC_DYNAMIC_LOAD "Enable DLL loading in acodec (Windows)" off)
option(WANT_MP3 "Enable MP3 support" on)

Expand Down Expand Up @@ -204,6 +205,38 @@ endif()

acodec_summary(" - DUMB" SUPPORT_MODAUDIO)

if(WANT_OPENMPT)
find_package(OpenMPT)
if(OPENMPT_FOUND)
set(CMAKE_REQUIRED_INCLUDES ${OPENMPT_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${OPENMPT_LIBRARIES})
run_c_compile_test("
#include <libopenmpt/libopenmpt.h>
#include <libopenmpt/libopenmpt_stream_callbacks_file.h>
int main(void)
{
openmpt_stream_get_file_callbacks();
return 0;
}"
OPENMPT_COMPILES)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_LIBRARIES)
if(OPENMPT_COMPILES)
set(SUPPORT_OPENMPT 1)
endif()
endif()
endif()

if(SUPPORT_OPENMPT)
include_directories(SYSTEM ${OPENMPT_INCLUDE_DIR})
set(ALLEGRO_CFG_ACODEC_OPENMPT 1)
list(APPEND ACODEC_SOURCES openmpt.c)
list(APPEND ACODEC_INCLUDE_DIRECTORIES ${OPENMPT_INCLUDE_DIR})
list(APPEND ACODEC_LIBRARIES ${OPENMPT_LIBRARIES})
endif()

acodec_summary(" - OpenMPT" SUPPORT_OPENMPT)

#
# Vorbis/Tremor
#
Expand Down
6 changes: 5 additions & 1 deletion addons/acodec/acodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ bool al_init_acodec_addon(void)
#endif

#ifdef ALLEGRO_CFG_ACODEC_MODAUDIO
ret &= _al_register_dumb_loaders();
//ret &= _al_register_dumb_loaders();
#endif

#ifdef ALLEGRO_CFG_ACODEC_OPENMPT
ret &= _al_register_openmpt_loaders();
#endif

/* MP3 will mis-identify a lot of mod files, so put its identifier last */
Expand Down
4 changes: 4 additions & 0 deletions addons/acodec/acodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ ALLEGRO_AUDIO_STREAM *_al_load_ogg_opus_audio_stream_f(ALLEGRO_FILE* file,
bool _al_identify_ogg_opus(ALLEGRO_FILE *f);
#endif

#ifdef ALLEGRO_CFG_ACODEC_OPENMPT
bool _al_register_openmpt_loaders(void);
#endif

#ifdef ALLEGRO_CFG_ACODEC_MP3
ALLEGRO_SAMPLE *_al_load_mp3(const char *filename);
ALLEGRO_SAMPLE *_al_load_mp3_f(ALLEGRO_FILE *f);
Expand Down
1 change: 1 addition & 0 deletions addons/acodec/allegro5/internal/aintern_acodec_cfg.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#cmakedefine ALLEGRO_CFG_ACODEC_VORBIS
#cmakedefine ALLEGRO_CFG_ACODEC_TREMOR
#cmakedefine ALLEGRO_CFG_ACODEC_OPUS
#cmakedefine ALLEGRO_CFG_ACODEC_OPENMPT
#cmakedefine ALLEGRO_CFG_ACODEC_MP3


Expand Down
2 changes: 2 additions & 0 deletions addons/acodec/modaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,10 @@ static size_t modaudio_stream_update(ALLEGRO_AUDIO_STREAM *stream, void *data,
size_to_read = 0;
manual_loop = true;
}
size_t old_written = written;
written += lib.duh_render(df->sig, 16, 0, 1.0, 65536.0 / 44100.0,
size_to_read, &(((char *)data)[written])) * sample_size;
printf("%d\n", (int)(written - old_written));
/* For internal loops, we don't rewind. */
if (!internal_loop &&
((long)written < size_to_read * sample_size || manual_loop)) {
Expand Down
Loading

0 comments on commit bcf1b3b

Please sign in to comment.