Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.8KB

  1. /*
  2. * Thread-safe fftw
  3. * Copyright (C) 2018-2022 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef THREAD_SAFE_FFTW_HPP_INCLUDED
  18. #define THREAD_SAFE_FFTW_HPP_INCLUDED
  19. #include "CarlaDefines.h"
  20. #ifdef CARLA_OS_UNIX
  21. // --------------------------------------------------------------------------------------------------------------------
  22. // Thread-safe fftw
  23. #include "CarlaLibUtils.hpp"
  24. class ThreadSafeFFTW
  25. {
  26. public:
  27. typedef void (*void_func)(void);
  28. ThreadSafeFFTW()
  29. : libfftw3(nullptr),
  30. libfftw3f(nullptr),
  31. libfftw3l(nullptr),
  32. libfftw3q(nullptr)
  33. {
  34. if ((libfftw3 = lib_open("libfftw3_threads.so.3")) != nullptr)
  35. if (const void_func func = lib_symbol<void_func>(libfftw3, "fftw_make_planner_thread_safe"))
  36. func();
  37. if ((libfftw3f = lib_open("libfftw3f_threads.so.3")) != nullptr)
  38. if (const void_func func = lib_symbol<void_func>(libfftw3f, "fftwf_make_planner_thread_safe"))
  39. func();
  40. if ((libfftw3l = lib_open("libfftw3l_threads.so.3")) != nullptr)
  41. if (const void_func func = lib_symbol<void_func>(libfftw3l, "fftwl_make_planner_thread_safe"))
  42. func();
  43. if ((libfftw3q = lib_open("libfftw3q_threads.so.3")) != nullptr)
  44. if (const void_func func = lib_symbol<void_func>(libfftw3q, "fftwq_make_planner_thread_safe"))
  45. func();
  46. }
  47. ~ThreadSafeFFTW()
  48. {
  49. if (libfftw3 != nullptr)
  50. {
  51. lib_close(libfftw3);
  52. libfftw3 = nullptr;
  53. }
  54. if (libfftw3f != nullptr)
  55. {
  56. lib_close(libfftw3f);
  57. libfftw3f = nullptr;
  58. }
  59. if (libfftw3l != nullptr)
  60. {
  61. lib_close(libfftw3l);
  62. libfftw3l = nullptr;
  63. }
  64. if (libfftw3q != nullptr)
  65. {
  66. lib_close(libfftw3q);
  67. libfftw3q = nullptr;
  68. }
  69. }
  70. private:
  71. lib_t libfftw3;
  72. lib_t libfftw3f;
  73. lib_t libfftw3l;
  74. lib_t libfftw3q;
  75. CARLA_DECLARE_NON_COPYABLE(ThreadSafeFFTW)
  76. };
  77. #endif
  78. // --------------------------------------------------------------------------------------------------------------------
  79. #endif // THREAD_SAFE_FFTW_HPP_INCLUDED