diff --git a/CMakeLists.txt b/CMakeLists.txt index 07b3d027a..941506bed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,6 +101,7 @@ set(CMAKE_CXX_STANDARD 11) # ------ ----------- ---- option(RELEASE "Release build" OFF) option(DYNAREC "Dynamic recompiler" ON) +option(OPENAL "OpenAL" ON) option(FLUIDSYNTH "FluidSynth" ON) option(MUNT "MUNT" ON) option(VRAMDUMP "Video RAM dumping" OFF) diff --git a/src/86box.c b/src/86box.c index 4c6e06488..bdd5f4ffa 100644 --- a/src/86box.c +++ b/src/86box.c @@ -932,7 +932,9 @@ pc_reset_hard_close(void) scsi_disk_close(); +#ifdef USE_OPENAL closeal(); +#endif video_reset_close(); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c3ed435d8..8bb53a5d2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -87,9 +87,11 @@ if(APPLE) target_link_libraries(86Box Freetype::Freetype) endif() -find_package(OpenAL REQUIRED) -include_directories(${OPENAL_INCLUDE_DIR}) -target_link_libraries(86Box ${OPENAL_LIBRARY}) +if(OPENAL) + find_package(OpenAL REQUIRED) + include_directories(${OPENAL_INCLUDE_DIR}) + target_link_libraries(86Box ${OPENAL_LIBRARY}) +endif() find_package(SDL2 REQUIRED) include_directories(${SDL2_INCLUDE_DIRS}) diff --git a/src/sound/CMakeLists.txt b/src/sound/CMakeLists.txt index e3420ac01..d7da82713 100644 --- a/src/sound/CMakeLists.txt +++ b/src/sound/CMakeLists.txt @@ -13,12 +13,17 @@ # Copyright 2020,2021 David Hrdlička. # -add_library(snd OBJECT sound.c openal.c snd_opl.c snd_opl_nuked.c snd_resid.cc +add_library(snd OBJECT sound.c snd_opl.c snd_opl_nuked.c snd_resid.cc midi.c midi_rtmidi.cpp snd_speaker.c snd_pssj.c snd_lpt_dac.c snd_ac97_codec.c snd_ac97_via.c snd_lpt_dss.c snd_adlib.c snd_adlibgold.c snd_ad1848.c snd_audiopci.c snd_azt2316a.c snd_cms.c snd_cs423x.c snd_gus.c snd_sb.c snd_sb_dsp.c snd_emu8k.c snd_mpu401.c snd_sn76489.c snd_ssi2001.c snd_wss.c snd_ym7128.c) +if(OPENAL) + target_compile_definitions(snd PRIVATE USE_OPENAL) + target_sources(snd PRIVATE openal.c) +endif() + if(FLUIDSYNTH) target_compile_definitions(snd PRIVATE USE_FLUIDSYNTH) target_sources(snd PRIVATE midi_fluidsynth.c) diff --git a/src/sound/midi_fluidsynth.c b/src/sound/midi_fluidsynth.c index a93618cd4..1a3ae2764 100644 --- a/src/sound/midi_fluidsynth.c +++ b/src/sound/midi_fluidsynth.c @@ -40,8 +40,10 @@ enum fluid_interp { }; +#ifdef USE_OPENAL extern void givealbuffer_midi(void *buf, uint32_t size); extern void al_set_midi(int freq, int buf_size); +#endif static void *fluidsynth_handle; /* handle to FluidSynth DLL */ @@ -150,7 +152,9 @@ static void fluidsynth_thread(void *param) buf_pos += buf_size; if (buf_pos >= data->buf_size) { +#ifdef USE_OPENAL givealbuffer_midi(data->buffer, data->buf_size / sizeof(float)); +#endif buf_pos = 0; } } @@ -163,7 +167,9 @@ static void fluidsynth_thread(void *param) buf_pos += buf_size; if (buf_pos >= data->buf_size) { +#ifdef USE_OPENAL givealbuffer_midi(data->buffer_int16, data->buf_size / sizeof(int16_t)); +#endif buf_pos = 0; } } @@ -314,7 +320,9 @@ void* fluidsynth_init(const device_t *info) data->buffer_int16 = malloc(data->buf_size); } +#ifdef USE_OPENAL al_set_midi(data->samplerate, data->buf_size); +#endif dev = malloc(sizeof(midi_device_t)); memset(dev, 0, sizeof(midi_device_t)); diff --git a/src/sound/midi_mt32.c b/src/sound/midi_mt32.c index 8ade99b51..ed87411cc 100644 --- a/src/sound/midi_mt32.c +++ b/src/sound/midi_mt32.c @@ -13,8 +13,10 @@ #include <86box/midi.h> +#ifdef USE_OPENAL extern void givealbuffer_midi(void *buf, uint32_t size); extern void al_set_midi(int freq, int buf_size); +#endif static const mt32emu_report_handler_i_v0 handler_v0 = { /** Returns the actual interface version ID */ @@ -136,7 +138,9 @@ static void mt32_thread(void *param) buf_pos += bsize; if (buf_pos >= buf_size) { +#ifdef USE_OPENAL givealbuffer_midi(buffer, buf_size / sizeof(float)); +#endif buf_pos = 0; } } @@ -148,7 +152,9 @@ static void mt32_thread(void *param) buf_pos += bsize; if (buf_pos >= buf_size) { +#ifdef USE_OPENAL givealbuffer_midi(buffer_int16, buf_size / sizeof(int16_t)); +#endif buf_pos = 0; } } @@ -200,7 +206,9 @@ void* mt32emu_init(char *control_rom, char *pcm_rom) mt32emu_set_reversed_stereo_enabled(context, device_get_config_int("reversed_stereo")); mt32emu_set_nice_amp_ramp_enabled(context, device_get_config_int("nice_ramp")); +#ifdef USE_OPENAL al_set_midi(samplerate, buf_size); +#endif dev = malloc(sizeof(midi_device_t)); memset(dev, 0, sizeof(midi_device_t)); diff --git a/src/sound/sound.c b/src/sound/sound.c index 4ab9cf58e..af9a91460 100644 --- a/src/sound/sound.c +++ b/src/sound/sound.c @@ -323,10 +323,12 @@ sound_cd_thread(void *param) } } +#ifdef USE_OPENAL if (sound_is_float) givealbuffer_cd(cd_out_buffer); else givealbuffer_cd(cd_out_buffer_int16); +#endif } } @@ -430,10 +432,12 @@ sound_poll(void *priv) } } +#ifdef USE_OPENAL if (sound_is_float) givealbuffer(outbuffer_ex); else givealbuffer(outbuffer_ex_int16); +#endif if (cd_thread_enable) { cd_buf_update--; @@ -462,7 +466,9 @@ sound_reset(void) midi_device_init(); midi_in_device_init(); +#ifdef USE_OPENAL inital(); +#endif timer_add(&sound_poll_timer, sound_poll, NULL, 1);