allow building Furnace without SDL2 and libsndfile

for eventual libfurnace
This commit is contained in:
tildearrow 2022-05-22 19:01:50 -05:00
parent 16afb6d7be
commit e17c99dcdf
4 changed files with 121 additions and 61 deletions

View file

@ -18,6 +18,8 @@ set(CMAKE_PROJECT_VERSION_MINOR 6)
set(CMAKE_PROJECT_VERSION_PATCH 0)
set(BUILD_GUI_DEFAULT ON)
set(USE_SDL2_DEFAULT ON)
set(USE_SNDFILE_DEFAULT ON)
set(SYSTEM_SDL2_DEFAULT OFF)
if (ANDROID)
@ -35,7 +37,9 @@ else()
endif()
option(BUILD_GUI "Build the tracker (disable to build only a headless player)" ${BUILD_GUI_DEFAULT})
option(USE_RTMIDI "Build with MIDI support using RtMidi. Currently unfinished." ${USE_RTMIDI_DEFAULT})
option(USE_RTMIDI "Build with MIDI support using RtMidi." ${USE_RTMIDI_DEFAULT})
option(USE_SDL2 "Build with SDL2. Required to build with GUI." ${USE_SDL2_DEFAULT})
option(USE_SNDFILE "Build with libsndfile. Required in order to work with audio files." ${USE_SNDFILE_DEFAULT})
option(WITH_JACK "Whether to build with JACK support. Auto-detects if JACK is available" ${WITH_JACK_DEFAULT})
option(SYSTEM_FMT "Use a system-installed version of fmt instead of the vendored one" OFF)
option(SYSTEM_LIBSNDFILE "Use a system-installed version of libsndfile instead of the vendored one" OFF)
@ -93,6 +97,8 @@ else()
message(STATUS "Using vendored fmt")
endif()
if (USE_SNDFILE)
list(APPEND DEPENDENCIES_DEFINES HAVE_SNDFILE)
if (SYSTEM_LIBSNDFILE)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBSNDFILE REQUIRED sndfile)
@ -113,6 +119,9 @@ else()
list(APPEND DEPENDENCIES_LIBRARIES sndfile)
message(STATUS "Using vendored libsndfile")
endif()
else()
message(STATUS "Not using libsndfile")
endif()
if (USE_RTMIDI)
if (SYSTEM_RTMIDI)
@ -154,10 +163,12 @@ else()
message(STATUS "Using vendored zlib")
endif()
if (USE_SDL2)
if (SYSTEM_SDL2)
if (PKG_CONFIG_FOUND)
pkg_check_modules(SDL2 sdl2>=${SYSTEM_SDL_MIN_VER})
if (SDL2_FOUND)
list(APPEND DEPENDENCIES_DEFINES HAVE_SDL2)
list(APPEND DEPENDENCIES_INCLUDE_DIRS ${SDL2_INCLUDE_DIRS})
list(APPEND DEPENDENCIES_COMPILE_OPTIONS ${SDL2_CFLAGS_OTHER})
list(APPEND DEPENDENCIES_LIBRARIES ${SDL2_LIBRARIES})
@ -168,6 +179,7 @@ if (SYSTEM_SDL2)
endif()
if (NOT SDL2_FOUND)
find_package(SDL2 ${SYSTEM_SDL_MIN_VER} REQUIRED)
list(APPEND DEPENDENCIES_DEFINES HAVE_SDL2)
list(APPEND DEPENDENCIES_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})
list(APPEND DEPENDENCIES_LIBRARIES ${SDL2_LIBRARY})
endif()
@ -186,6 +198,7 @@ else()
# This should probably go in a FAQ.
set(SDL_LIBC ON CACHE BOOL "Tell SDL that we want it to use our C runtime (required for proper static linking)" FORCE)
add_subdirectory(extern/SDL EXCLUDE_FROM_ALL)
list(APPEND DEPENDENCIES_DEFINES HAVE_SDL2)
list(APPEND DEPENDENCIES_INCLUDE_DIRS extern/SDL/include)
if (ANDROID)
list(APPEND DEPENDENCIES_LIBRARIES SDL2)
@ -198,13 +211,22 @@ else()
endif()
message(STATUS "Using vendored SDL2")
endif()
else()
message(STATUS "Not using SDL2")
if (BUILD_GUI)
message(FATAL_ERROR "SDL2 is required in order to build with GUI! Disable BUILD_GUI otherwise.")
endif()
endif()
set(AUDIO_SOURCES
src/audio/abstract.cpp
src/audio/midi.cpp
src/audio/sdl.cpp
)
if (USE_SDL2)
list(APPEND AUDIO_SOURCES src/audio/sdl.cpp)
endif()
if (WITH_JACK)
find_package(PkgConfig REQUIRED)
pkg_check_modules(JACK REQUIRED jack)

View file

@ -23,7 +23,9 @@
#include "safeReader.h"
#include "../ta-log.h"
#include "../fileutils.h"
#ifdef HAVE_SDL2
#include "../audio/sdl.h"
#endif
#include <stdexcept>
#ifndef _WIN32
#include <unistd.h>
@ -34,7 +36,9 @@
#include "../audio/jack.h"
#endif
#include <math.h>
#ifdef HAVE_SNDFILE
#include <sndfile.h>
#endif
#include <fmt/printf.h>
void process(void* u, float** in, float** out, int inChans, int outChans, unsigned int size) {
@ -187,6 +191,7 @@ bool DivEngine::isExporting() {
#define EXPORT_BUFSIZE 2048
#ifdef HAVE_SNDFILE
void DivEngine::runExportThread() {
switch (exportMode) {
case DIV_EXPORT_MODE_ONE: {
@ -438,8 +443,16 @@ void DivEngine::runExportThread() {
}
stopExport=false;
}
#else
void DivEngine::runExportThread() {
}
#endif
bool DivEngine::saveAudio(const char* path, int loops, DivAudioExportModes mode) {
#ifndef HAVE_SNDFILE
logE("Furnace was not compiled with libsndfile. cannot export!");
return false;
#else
exportPath=path;
exportMode=mode;
if (exportMode!=DIV_EXPORT_MODE_ONE) {
@ -461,6 +474,7 @@ bool DivEngine::saveAudio(const char* path, int loops, DivAudioExportModes mode)
remainingLoops=loops;
exportThread=new std::thread(_runExportThread,this);
return true;
#endif
}
void DivEngine::waitAudioFile() {
@ -2015,6 +2029,10 @@ int DivEngine::addSampleFromFile(const char* path) {
}
}
#ifndef HAVE_SNDFILE
lastError="Furnace was not compiled with libsndfile!";
return -1;
#else
SF_INFO si;
SNDFILE* f=sf_open(path,SFM_READ,&si);
if (f==NULL) {
@ -2093,6 +2111,7 @@ int DivEngine::addSampleFromFile(const char* path) {
renderSamples();
BUSY_END;
return sampleCount;
#endif
}
void DivEngine::delSample(int index) {
@ -2743,13 +2762,23 @@ bool DivEngine::initAudioBackend() {
logE("Furnace was not compiled with JACK support!");
setConf("audioEngine","SDL");
saveConf();
#ifdef HAVE_SDL2
output=new TAAudioSDL;
#else
logE("Furnace was not compiled with SDL support either!");
output=new TAAudio;
#endif
#else
output=new TAAudioJACK;
#endif
break;
case DIV_AUDIO_SDL:
#ifdef HAVE_SDL2
output=new TAAudioSDL;
#else
logE("Furnace was not compiled with SDL support!");
output=new TAAudio;
#endif
break;
case DIV_AUDIO_DUMMY:
output=new TAAudio;
@ -2844,7 +2873,7 @@ bool DivEngine::init() {
// init config
#ifdef _WIN32
configPath=getWinConfigPath();
#elif defined(ANDROID)
#elif defined(IS_MOBILE)
configPath=SDL_GetPrefPath("tildearrow","furnace");
#else
struct stat st;

View file

@ -23,7 +23,9 @@
#include "engine.h"
#include "../ta-log.h"
#include <math.h>
#ifdef HAVE_SNDFILE
#include <sndfile.h>
#endif
constexpr int MASTER_CLOCK_PREC=(sizeof(void*)==8)?8:0;

View file

@ -21,7 +21,9 @@
#include "../ta-log.h"
#include <math.h>
#include <string.h>
#ifdef HAVE_SNDFILE
#include <sndfile.h>
#endif
#include "filter.h"
extern "C" {
@ -37,6 +39,10 @@ DivSampleHistory::~DivSampleHistory() {
}
bool DivSample::save(const char* path) {
#ifndef HAVE_SNDFILE
logE("Furnace was not compiled with libsndfile!");
return false;
#else
SNDFILE* f;
SF_INFO si;
memset(&si,0,sizeof(SF_INFO));
@ -76,6 +82,7 @@ bool DivSample::save(const char* path) {
sf_close(f);
return true;
#endif
}
// 16-bit memory is padded to 512, to make things easier for ADPCM-A/B.