diff --git a/.gitignore b/.gitignore index bbc4377..9840540 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build/ +build-tmp/ eval/ *.bak doc/sassy.html @@ -9,3 +10,6 @@ audioinit/x64/ 3rdpartytools/bin2coff.exe akwf/akwf_sorted.obj akwf/akwf_sorted.raw +/sassy +/sassy.exe +/sassy.ini diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e945715 --- /dev/null +++ b/Makefile @@ -0,0 +1,91 @@ +#!/usr/bin/make -f +# Makefile for sassy # +# ------------------ # +# Created by falkTX +# + +include Makefile.mk + +DESTDIR = +PREFIX = /usr + +# --------------------------------------------------------------------------------------------------------------------- + +BUILD_CXX_FLAGS += -Isrc/fftreal +BUILD_CXX_FLAGS += -Isrc/libsamplerate +BUILD_CXX_FLAGS += -Isrc/ocornut_imgui +BUILD_CXX_FLAGS += -Isrc/ocornut_imgui/backends +BUILD_CXX_FLAGS += -Isrc/rtmidi +BUILD_CXX_FLAGS += -Isrc/tinyfiledialogs + +BUILD_CXX_FLAGS += -Wno-shadow +BUILD_CXX_FLAGS += -Wno-unused-parameter + +BUILD_CXX_FLAGS += $(shell pkg-config --cflags sdl2) -pthread +LINK_FLAGS += $(shell pkg-config --libs sdl2) -pthread + +ifeq ($(MACOS),true) +BUILD_CXX_FLAGS += -D__MACOSX_CORE__ +LINK_FLAGS += -framework CoreMIDI +else ifeq ($(WINDOWS),true) +BUILD_CXX_FLAGS += -D__WINDOWS_MM__ +LINK_FLAGS += -lwinmm +else +BUILD_CXX_FLAGS += -D__LINUX_ALSA__ +BUILD_CXX_FLAGS += $(shell pkg-config --cflags alsa gl) -pthread +LINK_FLAGS += $(shell pkg-config --libs alsa gl) -pthread +endif + +# --------------------------------------------------------------------------------------------------------------------- + +FILES = src/sassy.cpp +FILES += src/akwfdata.c +FILES += src/well512.cpp +FILES += src/ayumi/ayumi.c +FILES += src/klatt/darray.cpp +FILES += src/klatt/klatt.cpp +FILES += src/klatt/resonator.cpp +FILES += src/klatt/tts.cpp +FILES += src/padsynth/PADsynth.cpp +FILES += src/rtmidi/RtMidi.cpp +FILES += src/stb/stb_vorbis.c +FILES += src/tinyfiledialogs/tinyfiledialogs.c +FILES += $(wildcard src/eval_impl_*.cpp) +FILES += $(wildcard src/sassy_*.cpp) +FILES += $(wildcard src/libsamplerate/*.c) +FILES += $(wildcard src/ocornut_imgui/*.cpp) +FILES += $(wildcard src/ocornut_imgui/backends/*.cpp) + +OBJS = $(FILES:%=build-tmp/%.o) + +# --------------------------------------------------------------------------------------------------------------------- + +all: sassy$(APP_EXT) + +clean: + rm -f $(OBJS) + rm -rf build-tmp + +# --------------------------------------------------------------------------------------------------------------------- + +sassy$(APP_EXT): $(OBJS) + @echo "Linking $@" + $(SILENT)$(CXX) $^ $(LINK_FLAGS) -o $@ + +# --------------------------------------------------------------------------------------------------------------------- + +build-tmp/%.c.o: %.c + -@mkdir -p $(shell dirname $@) + @echo "Compiling $<" + $(SILENT)$(CC) $< $(BUILD_C_FLAGS) -c -o $@ + +build-tmp/%.cpp.o: %.cpp + -@mkdir -p $(shell dirname $@) + @echo "Compiling $<" + $(SILENT)$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ + +# --------------------------------------------------------------------------------------------------------------------- + +-include $(OBJS:%.o=%.d) + +# --------------------------------------------------------------------------------------------------------------------- diff --git a/Makefile.mk b/Makefile.mk new file mode 100644 index 0000000..62c5d56 --- /dev/null +++ b/Makefile.mk @@ -0,0 +1,297 @@ +#!/usr/bin/make -f +# Makefile for sassy # +# ------------------ # +# Created by falkTX +# + +AR ?= ar +CC ?= gcc +CXX ?= g++ + +# --------------------------------------------------------------------------------------------------------------------- +# Protect against multiple inclusion + +ifneq ($(MAKEFILE_BASE_INCLUDED),true) + +MAKEFILE_BASE_INCLUDED = true + +# --------------------------------------------------------------------------------------------------------------------- +# Auto-detect OS if not defined + +TARGET_MACHINE := $(shell $(CC) -dumpmachine) + +ifneq ($(BSD),true) +ifneq ($(HAIKU),true) +ifneq ($(HURD),true) +ifneq ($(LINUX),true) +ifneq ($(MACOS),true) +ifneq ($(WINDOWS),true) + +ifneq (,$(findstring bsd,$(TARGET_MACHINE))) +BSD=true +else ifneq (,$(findstring haiku,$(TARGET_MACHINE))) +HAIKU=true +else ifneq (,$(findstring linux,$(TARGET_MACHINE))) +LINUX=true +else ifneq (,$(findstring gnu,$(TARGET_MACHINE))) +HURD=true +else ifneq (,$(findstring apple,$(TARGET_MACHINE))) +MACOS=true +else ifneq (,$(findstring mingw,$(TARGET_MACHINE))) +WINDOWS=true +else ifneq (,$(findstring windows,$(TARGET_MACHINE))) +WINDOWS=true +endif + +endif +endif +endif +endif +endif +endif + +# --------------------------------------------------------------------------------------------------------------------- +# Auto-detect the processor + +TARGET_PROCESSOR := $(firstword $(subst -, ,$(TARGET_MACHINE))) + +ifneq (,$(filter i%86,$(TARGET_PROCESSOR))) +CPU_I386=true +CPU_I386_OR_X86_64=true +endif +ifneq (,$(filter x86_64,$(TARGET_PROCESSOR))) +CPU_X86_64=true +CPU_I386_OR_X86_64=true +endif +ifneq (,$(filter arm%,$(TARGET_PROCESSOR))) +CPU_ARM=true +CPU_ARM_OR_AARCH64=true +endif +ifneq (,$(filter arm64%,$(TARGET_PROCESSOR))) +CPU_ARM64=true +CPU_ARM_OR_AARCH64=true +endif +ifneq (,$(filter aarch64%,$(TARGET_PROCESSOR))) +CPU_AARCH64=true +CPU_ARM_OR_AARCH64=true +endif + +# --------------------------------------------------------------------------------------------------------------------- +# Set PKG_CONFIG (can be overridden by environment variable) + +ifeq ($(WINDOWS),true) +# Build statically on Windows by default +PKG_CONFIG ?= pkg-config --static +else +PKG_CONFIG ?= pkg-config +endif + +# --------------------------------------------------------------------------------------------------------------------- +# Set LINUX_OR_MACOS + +ifeq ($(LINUX),true) +LINUX_OR_MACOS=true +endif + +ifeq ($(MACOS),true) +LINUX_OR_MACOS=true +endif + +# --------------------------------------------------------------------------------------------------------------------- +# Set MACOS_OR_WINDOWS and HAIKU_OR_MACOS_OR_WINDOWS + +ifeq ($(HAIKU),true) +HAIKU_OR_MACOS_OR_WINDOWS=true +endif + +ifeq ($(MACOS),true) +MACOS_OR_WINDOWS=true +HAIKU_OR_MACOS_OR_WINDOWS=true +endif + +ifeq ($(WINDOWS),true) +MACOS_OR_WINDOWS=true +HAIKU_OR_MACOS_OR_WINDOWS=true +endif + +# --------------------------------------------------------------------------------------------------------------------- +# Set UNIX + +ifeq ($(BSD),true) +UNIX=true +endif + +ifeq ($(HURD),true) +UNIX=true +endif + +ifeq ($(LINUX),true) +UNIX=true +endif + +ifeq ($(MACOS),true) +UNIX=true +endif + +# --------------------------------------------------------------------------------------------------------------------- +# Set build and link flags + +BASE_FLAGS = -Wall -Wextra -pipe -MD -MP +BASE_OPTS = -O3 -ffast-math -fno-finite-math-only -fdata-sections -ffunction-sections + +ifeq ($(CPU_I386_OR_X86_64),true) +BASE_OPTS += -mtune=generic -msse -msse2 -mfpmath=sse +endif + +ifeq ($(CPU_ARM),true) +ifneq ($(CPU_ARM64),true) +BASE_OPTS += -mfpu=neon-vfpv4 -mfloat-abi=hard +endif +endif + +ifeq ($(MACOS),true) +# MacOS linker flags +LINK_OPTS = -fdata-sections -ffunction-sections -Wl,-dead_strip -Wl,-dead_strip_dylibs +ifneq ($(SKIP_STRIPPING),true) +LINK_OPTS += -Wl,-x +endif +else +# Common linker flags +LINK_OPTS = -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-O1 -Wl,--as-needed +ifneq ($(SKIP_STRIPPING),true) +LINK_OPTS += -Wl,--strip-all +endif +endif + +ifeq ($(SKIP_STRIPPING),true) +BASE_FLAGS += -g +endif + +ifeq ($(NOOPT),true) +# Non-CPU-specific optimization flags +BASE_OPTS = -O2 -ffast-math -fno-finite-math-only -fdata-sections -ffunction-sections +endif + +ifneq ($(MACOS_OR_WINDOWS),true) +BASE_FLAGS += -fno-gnu-unique +endif + +ifeq ($(WINDOWS),true) +# Assume we want posix +BASE_FLAGS += -posix -D__STDC_FORMAT_MACROS +# Needed for windows, see https://github.com/falkTX/Carla/issues/855 +BASE_FLAGS += -mstackrealign +else +# Not needed for Windows +BASE_FLAGS += -fPIC -DPIC +endif + +ifeq ($(DEBUG),true) +BASE_FLAGS += -DDEBUG -O0 -g +LINK_OPTS = +else +BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden +CXXFLAGS += -fvisibility-inlines-hidden +endif + +ifeq ($(WITH_LTO),true) +BASE_FLAGS += -fno-strict-aliasing -flto +LINK_OPTS += -fno-strict-aliasing -flto -Werror=odr -Werror=lto-type-mismatch +endif + +BUILD_C_FLAGS = $(BASE_FLAGS) -std=gnu99 $(CFLAGS) +BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++11 $(CXXFLAGS) +LINK_FLAGS = $(LINK_OPTS) $(LDFLAGS) + +ifneq ($(MACOS),true) +# Not available on MacOS +LINK_FLAGS += -Wl,--no-undefined +endif + +ifeq ($(MACOS_OLD),true) +BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0 +endif + +ifeq ($(WINDOWS),true) +# Always build statically on windows +LINK_FLAGS += -static -static-libgcc -static-libstdc++ +endif + +# --------------------------------------------------------------------------------------------------------------------- +# Set app extension + +ifeq ($(WINDOWS),true) +APP_EXT = .exe +endif + +# --------------------------------------------------------------------------------------------------------------------- +# Set shared lib extension + +LIB_EXT = .so + +ifeq ($(MACOS),true) +LIB_EXT = .dylib +endif + +ifeq ($(WINDOWS),true) +LIB_EXT = .dll +endif + +# --------------------------------------------------------------------------------------------------------------------- +# Set shared library CLI arg + +ifeq ($(MACOS),true) +SHARED = -dynamiclib +else +SHARED = -shared +endif + +# --------------------------------------------------------------------------------------------------------------------- +# Handle the verbosity switch + +SILENT = + +ifeq ($(VERBOSE),1) +else ifeq ($(VERBOSE),y) +else ifeq ($(VERBOSE),yes) +else ifeq ($(VERBOSE),true) +else +SILENT = @ +endif + +# --------------------------------------------------------------------------------------------------------------------- +# all needs to be first + +all: + +# --------------------------------------------------------------------------------------------------------------------- +# helper to print what is available/possible to build + +print_available = @echo $(1): $(shell echo $($(1)) | grep -q true && echo Yes || echo No) + +features: + @echo === Detected CPU + $(call print_available,CPU_AARCH64) + $(call print_available,CPU_ARM) + $(call print_available,CPU_ARM64) + $(call print_available,CPU_ARM_OR_AARCH64) + $(call print_available,CPU_I386) + $(call print_available,CPU_I386_OR_X86_64) + @echo === Detected OS + $(call print_available,BSD) + $(call print_available,HAIKU) + $(call print_available,HURD) + $(call print_available,LINUX) + $(call print_available,MACOS) + $(call print_available,WINDOWS) + $(call print_available,HAIKU_OR_MACOS_OR_WINDOWS) + $(call print_available,LINUX_OR_MACOS) + $(call print_available,MACOS_OR_WINDOWS) + $(call print_available,UNIX) + +# --------------------------------------------------------------------------------------------------------------------- +# Protect against multiple inclusion + +endif # MAKEFILE_BASE_INCLUDED + +# --------------------------------------------------------------------------------------------------------------------- diff --git a/src/eval.cpp b/src/eval.cpp index 690fcb6..cf138ec 100644 --- a/src/eval.cpp +++ b/src/eval.cpp @@ -679,7 +679,7 @@ double eval(const char* s, int do_opt, int do_jit, int just_validate = 0) { double jres = jf(cellvals, cellvals); bool nanres = isnan(res) != isnan(jres); - double magnitude = max(abs(jres), abs(res)); + double magnitude = std::max(abs(jres), abs(res)); bool realres = abs(jres - res) > magnitude * 0.0001; if (isnan(res)) realres = false; @@ -727,14 +727,14 @@ std::string func2call(int func) return s; } -WELL512 random; +WELL512 gRandom; int fuzz() { std::string s; // - pick a random function // - build a func(v,v,v) sig - s = func2call(random.genrand_int31() % (FUNC_LAST - 1) + 1); + s = func2call(gRandom.genrand_int31() % (FUNC_LAST - 1) + 1); // - replace v:s randomly with functions or values bool changed = true; int maxfunc = 20; @@ -746,17 +746,17 @@ int fuzz() { if (s[i] == 'C' && maxfunc) { - if ((random.genrand_int31() % 10) > 1) + if ((gRandom.genrand_int31() % 10) > 1) { - d += func2call(random.genrand_int31() % (FUNC_LAST - 1) + 1); + d += func2call(gRandom.genrand_int31() % (FUNC_LAST - 1) + 1); } else { - int braces = random.genrand_int31() & 1; + int braces = gRandom.genrand_int31() & 1; if (braces) d += "("; d += "C"; - switch (random.genrand_int31() % 4) + switch (gRandom.genrand_int31() % 4) { case 0: d += "+"; break; case 1: d += "-"; break; @@ -774,7 +774,7 @@ int fuzz() if (s[i] == 'L' || (s[i] == 'C' && !maxfunc)) { char temp[16]; - sprintf(temp, "%3.5f", random.genrand_int31() * 0.001f); + sprintf(temp, "%3.5f", gRandom.genrand_int31() * 0.001f); d += temp; changed = true; } @@ -782,7 +782,7 @@ int fuzz() if (s[i] == 'V') { char temp[16]; - sprintf(temp, "%c%d", 'a'+ random.genrand_int31() %26, (random.genrand_int31() %32) + 1); + sprintf(temp, "%c%d", 'a'+ gRandom.genrand_int31() %26, (gRandom.genrand_int31() %32) + 1); d += temp; changed = true; } @@ -790,7 +790,7 @@ int fuzz() if (s[i] == 'A') { char temp[16]; - sprintf(temp, "%c%d:%c%d", 'a' + random.genrand_int31() % 26, (random.genrand_int31() % 32) + 1, 'a' + random.genrand_int31() % 26, (random.genrand_int31() % 32) + 1); + sprintf(temp, "%c%d:%c%d", 'a' + gRandom.genrand_int31() % 26, (gRandom.genrand_int31() % 32) + 1, 'a' + gRandom.genrand_int31() % 26, (gRandom.genrand_int31() % 32) + 1); d += temp; changed = true; } @@ -1115,7 +1115,7 @@ int main(int parc, char** pars) int cycle = 0; int mismatch = 0; int seed = GetTickCount(); - random.init_genrand(seed); + gRandom.init_genrand(seed); while (1) { cycle++; @@ -1161,4 +1161,4 @@ int main(int parc, char** pars) return 0; -} \ No newline at end of file +} diff --git a/src/eval.h b/src/eval.h index 70d6ae0..1608df4 100644 --- a/src/eval.h +++ b/src/eval.h @@ -22,6 +22,11 @@ namespace Xbyak // pow(2, 3/4.0) ~ 1.6817928305074290860622509524664297900800685247135690216264521719 #define POW_2_3_4TH 1.6817928305074290860622509524664297900800685247135690216264521719 +#ifndef _WIN32 +#define sprintf_s snprintf +#define _strdup strdup +#endif + extern const double note_to_freq[128]; struct Op diff --git a/src/sassy.cpp b/src/sassy.cpp index 1a03456..44acf94 100644 --- a/src/sassy.cpp +++ b/src/sassy.cpp @@ -404,7 +404,9 @@ void sdl2_audiomixer(void* , Uint8* stream, int len) memset(stream, 0, len); return; } +#ifdef _WIN32 _controlfp(_DN_FLUSH, _MCW_DN); +#endif /* SetThreadAffinityMask(GetCurrentThread(), 0xfe); // Avoid code #1 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); @@ -1032,7 +1034,9 @@ extern int editor_callback(ImGuiInputTextCallbackData* data); int main(int, char**) { printf("Initializing..\n"); +#ifdef _WIN32 _controlfp(_DN_FLUSH, _MCW_DN); +#endif gCelldata = new Celldata[MAXVAR]; gCellvalue = new double[MAXVAR]; diff --git a/src/sassy.h b/src/sassy.h index 477b2bc..1cd9c7c 100644 --- a/src/sassy.h +++ b/src/sassy.h @@ -36,7 +36,7 @@ some functions: #include #include #include "eval.h" -#include "rtmidi.h" +#include "RtMidi.h" #include "imgui.h" #include "imgui_impl_sdl.h" #include "imgui_impl_opengl2.h" diff --git a/src/well512.cpp b/src/well512.cpp index 52fc4a8..7c2b66d 100644 --- a/src/well512.cpp +++ b/src/well512.cpp @@ -11,7 +11,7 @@ #include //#include -#include "WELL512.h" +#include "well512.h"