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(CMAKE_PROJECT_VERSION_PATCH 0)
set(BUILD_GUI_DEFAULT ON) set(BUILD_GUI_DEFAULT ON)
set(USE_SDL2_DEFAULT ON)
set(USE_SNDFILE_DEFAULT ON)
set(SYSTEM_SDL2_DEFAULT OFF) set(SYSTEM_SDL2_DEFAULT OFF)
if (ANDROID) if (ANDROID)
@ -35,7 +37,9 @@ else()
endif() endif()
option(BUILD_GUI "Build the tracker (disable to build only a headless player)" ${BUILD_GUI_DEFAULT}) 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(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_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) 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") message(STATUS "Using vendored fmt")
endif() endif()
if (USE_SNDFILE)
list(APPEND DEPENDENCIES_DEFINES HAVE_SNDFILE)
if (SYSTEM_LIBSNDFILE) if (SYSTEM_LIBSNDFILE)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBSNDFILE REQUIRED sndfile) pkg_check_modules(LIBSNDFILE REQUIRED sndfile)
@ -113,6 +119,9 @@ else()
list(APPEND DEPENDENCIES_LIBRARIES sndfile) list(APPEND DEPENDENCIES_LIBRARIES sndfile)
message(STATUS "Using vendored libsndfile") message(STATUS "Using vendored libsndfile")
endif() endif()
else()
message(STATUS "Not using libsndfile")
endif()
if (USE_RTMIDI) if (USE_RTMIDI)
if (SYSTEM_RTMIDI) if (SYSTEM_RTMIDI)
@ -154,10 +163,12 @@ else()
message(STATUS "Using vendored zlib") message(STATUS "Using vendored zlib")
endif() endif()
if (USE_SDL2)
if (SYSTEM_SDL2) if (SYSTEM_SDL2)
if (PKG_CONFIG_FOUND) if (PKG_CONFIG_FOUND)
pkg_check_modules(SDL2 sdl2>=${SYSTEM_SDL_MIN_VER}) pkg_check_modules(SDL2 sdl2>=${SYSTEM_SDL_MIN_VER})
if (SDL2_FOUND) if (SDL2_FOUND)
list(APPEND DEPENDENCIES_DEFINES HAVE_SDL2)
list(APPEND DEPENDENCIES_INCLUDE_DIRS ${SDL2_INCLUDE_DIRS}) list(APPEND DEPENDENCIES_INCLUDE_DIRS ${SDL2_INCLUDE_DIRS})
list(APPEND DEPENDENCIES_COMPILE_OPTIONS ${SDL2_CFLAGS_OTHER}) list(APPEND DEPENDENCIES_COMPILE_OPTIONS ${SDL2_CFLAGS_OTHER})
list(APPEND DEPENDENCIES_LIBRARIES ${SDL2_LIBRARIES}) list(APPEND DEPENDENCIES_LIBRARIES ${SDL2_LIBRARIES})
@ -168,6 +179,7 @@ if (SYSTEM_SDL2)
endif() endif()
if (NOT SDL2_FOUND) if (NOT SDL2_FOUND)
find_package(SDL2 ${SYSTEM_SDL_MIN_VER} REQUIRED) 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_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})
list(APPEND DEPENDENCIES_LIBRARIES ${SDL2_LIBRARY}) list(APPEND DEPENDENCIES_LIBRARIES ${SDL2_LIBRARY})
endif() endif()
@ -186,6 +198,7 @@ else()
# This should probably go in a FAQ. # 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) 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) add_subdirectory(extern/SDL EXCLUDE_FROM_ALL)
list(APPEND DEPENDENCIES_DEFINES HAVE_SDL2)
list(APPEND DEPENDENCIES_INCLUDE_DIRS extern/SDL/include) list(APPEND DEPENDENCIES_INCLUDE_DIRS extern/SDL/include)
if (ANDROID) if (ANDROID)
list(APPEND DEPENDENCIES_LIBRARIES SDL2) list(APPEND DEPENDENCIES_LIBRARIES SDL2)
@ -198,13 +211,22 @@ else()
endif() endif()
message(STATUS "Using vendored SDL2") message(STATUS "Using vendored SDL2")
endif() 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 set(AUDIO_SOURCES
src/audio/abstract.cpp src/audio/abstract.cpp
src/audio/midi.cpp src/audio/midi.cpp
src/audio/sdl.cpp
) )
if (USE_SDL2)
list(APPEND AUDIO_SOURCES src/audio/sdl.cpp)
endif()
if (WITH_JACK) if (WITH_JACK)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(JACK REQUIRED jack) pkg_check_modules(JACK REQUIRED jack)

View file

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

View file

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

View file

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