Internal jack client needs it, so let's share it Signed-off-by: falkTX <falktx@falktx.com>tags/v2.1-rc1
| @@ -26,10 +26,7 @@ | |||
| #include "CarlaBackendUtils.hpp" | |||
| #include "CarlaBase64Utils.hpp" | |||
| #ifdef CARLA_OS_UNIX | |||
| # include "CarlaLibUtils.hpp" | |||
| #endif | |||
| #include "ThreadSafeFFTW.hpp" | |||
| #ifdef BUILD_BRIDGE | |||
| # include "water/files/File.h" | |||
| @@ -107,102 +104,6 @@ struct CarlaBackendStandalone { | |||
| CarlaBackendStandalone gStandalone; | |||
| #ifdef CARLA_OS_UNIX | |||
| // -------------------------------------------------------------------------------------------------------------------- | |||
| // Thread-safe fftw | |||
| typedef void (*void_func)(void); | |||
| class ThreadSafeFFTW | |||
| { | |||
| public: | |||
| struct Deinitializer { | |||
| Deinitializer(ThreadSafeFFTW& s) | |||
| : tsfftw(s) {} | |||
| ~Deinitializer() | |||
| { | |||
| tsfftw.deinit(); | |||
| } | |||
| ThreadSafeFFTW& tsfftw; | |||
| }; | |||
| ThreadSafeFFTW() | |||
| : initialized(false), | |||
| libfftw3(nullptr), | |||
| libfftw3f(nullptr), | |||
| libfftw3l(nullptr), | |||
| libfftw3q(nullptr) {} | |||
| ~ThreadSafeFFTW() | |||
| { | |||
| CARLA_SAFE_ASSERT(libfftw3 == nullptr); | |||
| } | |||
| void init() | |||
| { | |||
| if (initialized) | |||
| return; | |||
| initialized = true; | |||
| if ((libfftw3 = lib_open("libfftw3_threads.so.3")) != nullptr) | |||
| if (const void_func func = lib_symbol<void_func>(libfftw3, "fftw_make_planner_thread_safe")) | |||
| func(); | |||
| if ((libfftw3f = lib_open("libfftw3f_threads.so.3")) != nullptr) | |||
| if (const void_func func = lib_symbol<void_func>(libfftw3f, "fftwf_make_planner_thread_safe")) | |||
| func(); | |||
| if ((libfftw3l = lib_open("libfftw3l_threads.so.3")) != nullptr) | |||
| if (const void_func func = lib_symbol<void_func>(libfftw3l, "fftwl_make_planner_thread_safe")) | |||
| func(); | |||
| if ((libfftw3q = lib_open("libfftw3q_threads.so.3")) != nullptr) | |||
| if (const void_func func = lib_symbol<void_func>(libfftw3q, "fftwq_make_planner_thread_safe")) | |||
| func(); | |||
| } | |||
| void deinit() | |||
| { | |||
| if (! initialized) | |||
| return; | |||
| initialized = false; | |||
| if (libfftw3 != nullptr) | |||
| { | |||
| lib_close(libfftw3); | |||
| libfftw3 = nullptr; | |||
| } | |||
| if (libfftw3f != nullptr) | |||
| { | |||
| lib_close(libfftw3f); | |||
| libfftw3f = nullptr; | |||
| } | |||
| if (libfftw3l != nullptr) | |||
| { | |||
| lib_close(libfftw3l); | |||
| libfftw3l = nullptr; | |||
| } | |||
| if (libfftw3q != nullptr) | |||
| { | |||
| lib_close(libfftw3q); | |||
| libfftw3q = nullptr; | |||
| } | |||
| } | |||
| private: | |||
| bool initialized; | |||
| lib_t libfftw3; | |||
| lib_t libfftw3f; | |||
| lib_t libfftw3l; | |||
| lib_t libfftw3q; | |||
| CARLA_DECLARE_NON_COPY_CLASS(ThreadSafeFFTW) | |||
| }; | |||
| static ThreadSafeFFTW sThreadSafeFFTW; | |||
| #endif | |||
| @@ -27,6 +27,23 @@ | |||
| #include "jackey.h" | |||
| #ifdef USING_JUCE | |||
| # if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) | |||
| # pragma GCC diagnostic push | |||
| # pragma GCC diagnostic ignored "-Wconversion" | |||
| # pragma GCC diagnostic ignored "-Weffc++" | |||
| # pragma GCC diagnostic ignored "-Wsign-conversion" | |||
| # pragma GCC diagnostic ignored "-Wundef" | |||
| # endif | |||
| # include "AppConfig.h" | |||
| # include "juce_events/juce_events.h" | |||
| # if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) | |||
| # pragma GCC diagnostic pop | |||
| # endif | |||
| #endif | |||
| #ifdef __SSE2_MATH__ | |||
| # include <xmmintrin.h> | |||
| #endif | |||
| @@ -2920,6 +2937,11 @@ int jack_initialize (jack_client_t *client, const char *load_init); | |||
| CARLA_EXPORT | |||
| void jack_finish(void *arg); | |||
| #ifdef CARLA_OS_UNIX | |||
| # include "ThreadSafeFFTW.hpp" | |||
| static ThreadSafeFFTW sThreadSafeFFTW; | |||
| #endif | |||
| // ----------------------------------------------------------------------- | |||
| CARLA_EXPORT | |||
| @@ -2933,7 +2955,7 @@ int jack_initialize(jack_client_t* const client, const char* const load_init) | |||
| else | |||
| mode = ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS; | |||
| #if 0 //def USING_JUCE | |||
| #ifdef USING_JUCE | |||
| juce::initialiseJuce_GUI(); | |||
| #endif | |||
| @@ -2954,7 +2976,7 @@ int jack_initialize(jack_client_t* const client, const char* const load_init) | |||
| if (engine->initInternal(client)) | |||
| { | |||
| #if 0 //def CARLA_OS_UNIX | |||
| #ifdef CARLA_OS_UNIX | |||
| sThreadSafeFFTW.init(); | |||
| #endif | |||
| @@ -2963,7 +2985,7 @@ int jack_initialize(jack_client_t* const client, const char* const load_init) | |||
| else | |||
| { | |||
| delete engine; | |||
| #if 0 //def USING_JUCE | |||
| #ifdef USING_JUCE | |||
| juce::shutdownJuce_GUI(); | |||
| #endif | |||
| return 1; | |||
| @@ -2978,7 +3000,7 @@ void jack_finish(void *arg) | |||
| CarlaEngineJack* const engine = (CarlaEngineJack*)arg;; | |||
| CARLA_SAFE_ASSERT_RETURN(engine != nullptr,); | |||
| #if 0 //def CARLA_OS_UNIX | |||
| #ifdef CARLA_OS_UNIX | |||
| const ThreadSafeFFTW::Deinitializer tsfftwde(sThreadSafeFFTW); | |||
| #endif | |||
| @@ -2987,7 +3009,7 @@ void jack_finish(void *arg) | |||
| engine->close(); | |||
| delete engine; | |||
| #if 0 //def USING_JUCE | |||
| #ifdef USING_JUCE | |||
| juce::shutdownJuce_GUI(); | |||
| #endif | |||
| } | |||
| @@ -0,0 +1,125 @@ | |||
| /* | |||
| * Thread-safe fftw | |||
| * Copyright (C) 2018-2019 Filipe Coelho <falktx@falktx.com> | |||
| * | |||
| * This program is free software; you can redistribute it and/or | |||
| * modify it under the terms of the GNU General Public License as | |||
| * published by the Free Software Foundation; either version 2 of | |||
| * the License, or any later version. | |||
| * | |||
| * This program is distributed in the hope that it will be useful, | |||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
| * GNU General Public License for more details. | |||
| * | |||
| * For a full copy of the GNU General Public License see the doc/GPL.txt file. | |||
| */ | |||
| #ifndef THREAD_SAFE_FFTW_HPP_INCLUDED | |||
| #define THREAD_SAFE_FFTW_HPP_INCLUDED | |||
| #include "CarlaDefines.h" | |||
| #ifdef CARLA_OS_UNIX | |||
| // -------------------------------------------------------------------------------------------------------------------- | |||
| // Thread-safe fftw | |||
| #include "CarlaLibUtils.hpp" | |||
| class ThreadSafeFFTW | |||
| { | |||
| public: | |||
| typedef void (*void_func)(void); | |||
| struct Deinitializer { | |||
| Deinitializer(ThreadSafeFFTW& s) | |||
| : tsfftw(s) {} | |||
| ~Deinitializer() | |||
| { | |||
| tsfftw.deinit(); | |||
| } | |||
| ThreadSafeFFTW& tsfftw; | |||
| }; | |||
| ThreadSafeFFTW() | |||
| : initialized(false), | |||
| libfftw3(nullptr), | |||
| libfftw3f(nullptr), | |||
| libfftw3l(nullptr), | |||
| libfftw3q(nullptr) {} | |||
| ~ThreadSafeFFTW() | |||
| { | |||
| CARLA_SAFE_ASSERT(libfftw3 == nullptr); | |||
| } | |||
| void init() | |||
| { | |||
| if (initialized) | |||
| return; | |||
| initialized = true; | |||
| if ((libfftw3 = lib_open("libfftw3_threads.so.3")) != nullptr) | |||
| if (const void_func func = lib_symbol<void_func>(libfftw3, "fftw_make_planner_thread_safe")) | |||
| func(); | |||
| if ((libfftw3f = lib_open("libfftw3f_threads.so.3")) != nullptr) | |||
| if (const void_func func = lib_symbol<void_func>(libfftw3f, "fftwf_make_planner_thread_safe")) | |||
| func(); | |||
| if ((libfftw3l = lib_open("libfftw3l_threads.so.3")) != nullptr) | |||
| if (const void_func func = lib_symbol<void_func>(libfftw3l, "fftwl_make_planner_thread_safe")) | |||
| func(); | |||
| if ((libfftw3q = lib_open("libfftw3q_threads.so.3")) != nullptr) | |||
| if (const void_func func = lib_symbol<void_func>(libfftw3q, "fftwq_make_planner_thread_safe")) | |||
| func(); | |||
| } | |||
| void deinit() | |||
| { | |||
| if (! initialized) | |||
| return; | |||
| initialized = false; | |||
| if (libfftw3 != nullptr) | |||
| { | |||
| lib_close(libfftw3); | |||
| libfftw3 = nullptr; | |||
| } | |||
| if (libfftw3f != nullptr) | |||
| { | |||
| lib_close(libfftw3f); | |||
| libfftw3f = nullptr; | |||
| } | |||
| if (libfftw3l != nullptr) | |||
| { | |||
| lib_close(libfftw3l); | |||
| libfftw3l = nullptr; | |||
| } | |||
| if (libfftw3q != nullptr) | |||
| { | |||
| lib_close(libfftw3q); | |||
| libfftw3q = nullptr; | |||
| } | |||
| } | |||
| private: | |||
| bool initialized; | |||
| lib_t libfftw3; | |||
| lib_t libfftw3f; | |||
| lib_t libfftw3l; | |||
| lib_t libfftw3q; | |||
| CARLA_DECLARE_NON_COPY_CLASS(ThreadSafeFFTW) | |||
| }; | |||
| #endif | |||
| // -------------------------------------------------------------------------------------------------------------------- | |||
| #endif // THREAD_SAFE_FFTW_HPP_INCLUDED | |||