commit 6a10d76235c8193952e60e1459fa5e39193c133c
parent 0dade375d51148fd0fc43a211a316eeb9b9d34df
Author: Johannes Lorenz <j.git@lorenz-ho.me>
Date: Sat, 18 Dec 2021 22:31:42 +0100
FFTwrapper: Use float precision
Diffstat:
8 files changed, 41 insertions(+), 43 deletions(-)
diff --git a/cmake/FindFFTW.cmake b/cmake/FindFFTW.cmake
@@ -1,17 +0,0 @@
-#Find FFTW
-
-find_path(FFTW_INCLUDE_DIR
- NAMES fftw3.h
- PATHS ${FFTW_INCLUDE_DIRS}
- )
-
-find_library(FFTW_LIBRARIES
- NAMES fftw3
- PATHS ${FFTW_LIBRARY_DIRS}
- )
-
-set(FFTW_PROCESS_INCLUDES FFTW_INCLUDE_DIR)
-set(FFTW_PROCESS_LIBS FFTW_LIBRARIES)
-include(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(FFTW DEFAULT_MSG
- FFTW_INCLUDE_DIR FFTW_LIBRARIES)
diff --git a/cmake/FindFFTW3F.cmake b/cmake/FindFFTW3F.cmake
@@ -0,0 +1,17 @@
+#Find FFTW3F
+
+find_path(FFTW3F_INCLUDE_DIR
+ NAMES fftw3.h
+ PATHS ${FFTW3F_INCLUDE_DIRS}
+ )
+
+find_library(FFTW3F_LIBRARIES
+ NAMES fftw3f
+ PATHS ${FFTW3F_LIBRARY_DIRS}
+ )
+
+set(FFTW3F_PROCESS_INCLUDES FFTW3F_INCLUDE_DIR)
+set(FFTW3F_PROCESS_LIBS FFTW3F_LIBRARIES)
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(FFTW3F DEFAULT_MSG
+ FFTW3F_INCLUDE_DIR FFTW3F_LIBRARIES)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
@@ -27,7 +27,7 @@ if(PKG_CONFIG_FOUND AND NOT (${CMAKE_SYSTEM_NAME} STREQUAL "Windows"))
pkg_check_modules(NTK ntk)
pkg_check_modules(NTK_IMAGES ntk_images)
- pkg_check_modules(FFTW REQUIRED fftw3)
+ pkg_check_modules(FFTW3F REQUIRED fftw3f)
pkg_check_modules(MXML REQUIRED mxml)
pkg_search_module(LASH lash-1.0)
@@ -37,7 +37,7 @@ if(PKG_CONFIG_FOUND AND NOT (${CMAKE_SYSTEM_NAME} STREQUAL "Windows"))
pkg_search_module(LIBLO liblo>=0.26 REQUIRED)
mark_as_advanced(LIBLO_LIBRARIES)
else()
- find_package(FFTW REQUIRED)
+ find_package(FFTW3F REQUIRED)
find_package(MXML REQUIRED)
find_package(LIBLO REQUIRED)
find_package(PORTAUDIO)
@@ -516,7 +516,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zyn-version.h.in
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zyn-config.h.in
${CMAKE_CURRENT_BINARY_DIR}/zyn-config.h)
-link_directories(${AUDIO_LIBRARY_DIRS} ${ZLIB_LIBRARY_DIRS} ${FFTW_LIBRARY_DIRS} ${MXML_LIBRARY_DIRS} ${FLTK_LIBRARY_DIRS} ${NTK_LIBRARY_DIRS} ${X11_LIBRARY_DIRS})
+link_directories(${AUDIO_LIBRARY_DIRS} ${ZLIB_LIBRARY_DIRS} ${FFTW3F_LIBRARY_DIRS} ${MXML_LIBRARY_DIRS} ${FLTK_LIBRARY_DIRS} ${NTK_LIBRARY_DIRS} ${X11_LIBRARY_DIRS})
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
@@ -573,7 +573,7 @@ endif()
target_link_libraries(zynaddsubfx_core
${ZLIB_LIBRARIES}
- ${FFTW_LIBRARIES}
+ ${FFTW3F_LIBRARIES}
${MXML_LIBRARIES}
${OS_LIBRARIES}
${PTHREAD_LIBRARY}
@@ -663,7 +663,7 @@ endmacro()
package_status(PKG_CONFIG_FOUND "PkgConfig" "found" ${Red})
package_status(ZLIB_FOUND "zlib " "found" ${Red})
package_status(MXML_FOUND "mxml " "found" ${Red})
-package_status(FFTW_FOUND "fftw3 " "found" ${Red})
+package_status(FFTW3F_FOUND "fftw3f " "found" ${Red})
package_status(LIBLO_FOUND "liblo " "found" ${Red})
package_status(X11_FOUND "x11 " "found" ${Yellow})
package_status(X11_Xpm_FOUND "xpm " "found" ${Yellow})
@@ -688,4 +688,4 @@ package_status(SndioEnable "SNDIO " "enabled" ${Yellow})
package_status(HAVE_ASYNC "c++ async" "usable" ${Yellow})
-message(STATUS "Link libraries: ${ZLIB_LIBRARY} ${FFTW_LIBRARY} ${MXML_LIBRARIES} ${AUDIO_LIBRARIES} ${OS_LIBRARIES}")
+message(STATUS "Link libraries: ${ZLIB_LIBRARY} ${FFTW3F_LIBRARY} ${MXML_LIBRARIES} ${AUDIO_LIBRARIES} ${OS_LIBRARIES}")
diff --git a/src/DSP/FFTwrapper.cpp b/src/DSP/FFTwrapper.cpp
@@ -32,13 +32,13 @@ FFTwrapper::FFTwrapper(int fftsize_)
fftsize = fftsize_;
time = new fftw_real[fftsize];
- fft = new fftw_complex[fftsize + 1];
+ fft = new fftwf_complex[fftsize + 1];
pthread_mutex_lock(mutex);
- planfftw = fftw_plan_dft_r2c_1d(fftsize,
+ planfftw = fftwf_plan_dft_r2c_1d(fftsize,
time,
fft,
FFTW_ESTIMATE);
- planfftw_inv = fftw_plan_dft_c2r_1d(fftsize,
+ planfftw_inv = fftwf_plan_dft_c2r_1d(fftsize,
fft,
time,
FFTW_ESTIMATE);
@@ -48,8 +48,8 @@ FFTwrapper::FFTwrapper(int fftsize_)
FFTwrapper::~FFTwrapper()
{
pthread_mutex_lock(mutex);
- fftw_destroy_plan(planfftw);
- fftw_destroy_plan(planfftw_inv);
+ fftwf_destroy_plan(planfftw);
+ fftwf_destroy_plan(planfftw_inv);
pthread_mutex_unlock(mutex);
delete [] time;
@@ -59,36 +59,34 @@ FFTwrapper::~FFTwrapper()
void FFTwrapper::smps2freqs(const float *smps, fft_t *freqs)
{
//Load data
- for(int i = 0; i < fftsize; ++i)
- time[i] = static_cast<double>(smps[i]);
+ memcpy((void *)time, (const void *)smps, fftsize * sizeof(float));
//DFT
- fftw_execute(planfftw);
+ fftwf_execute(planfftw);
//Grab data
- memcpy((void *)freqs, (const void *)fft, fftsize * sizeof(double));
+ memcpy((void *)freqs, (const void *)fft, fftsize * sizeof(float));
}
void FFTwrapper::freqs2smps(const fft_t *freqs, float *smps)
{
//Load data
- memcpy((void *)fft, (const void *)freqs, fftsize * sizeof(double));
+ memcpy((void *)fft, (const void *)freqs, fftsize * sizeof(float));
//clear unused freq channel
fft[fftsize / 2][0] = 0.0f;
fft[fftsize / 2][1] = 0.0f;
//IDFT
- fftw_execute(planfftw_inv);
+ fftwf_execute(planfftw_inv);
//Grab data
- for(int i = 0; i < fftsize; ++i)
- smps[i] = static_cast<float>(time[i]);
+ memcpy((void*)smps, (const void*)time, fftsize * sizeof(float));
}
void FFT_cleanup()
{
- fftw_cleanup();
+ fftwf_cleanup();
pthread_mutex_destroy(mutex);
delete mutex;
mutex = NULL;
diff --git a/src/DSP/FFTwrapper.h b/src/DSP/FFTwrapper.h
@@ -35,9 +35,9 @@ class FFTwrapper
void freqs2smps(const fft_t *freqs, float *smps);
private:
int fftsize;
- fftw_real *time;
- fftw_complex *fft;
- fftw_plan planfftw, planfftw_inv;
+ fftw_real *time;
+ fftwf_complex *fft;
+ fftwf_plan planfftw, planfftw_inv;
};
/*
diff --git a/src/Synth/OscilGen.cpp b/src/Synth/OscilGen.cpp
@@ -968,7 +968,7 @@ void OscilGen::adaptiveharmonicpostprocess(fft_t *f, int size)
par = 1.0f - powf((1.0f - par), 1.5f);
for(int i = 0; i < size; ++i) {
- inf[i] = f[i] * double(par);
+ inf[i] = f[i] * par;
f[i] *= (1.0f - par);
}
diff --git a/src/Tests/CMakeLists.txt b/src/Tests/CMakeLists.txt
@@ -15,7 +15,7 @@ add_definitions(-DSOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
#Extra libraries added to make test and full compilation use the same library
#links for quirky compilers
-set(test_lib zynaddsubfx_core ${GUI_LIBRARIES} ${ZLIB_LIBRARY} ${FFTW_LIBRARIES}
+set(test_lib zynaddsubfx_core ${GUI_LIBRARIES} ${ZLIB_LIBRARY} ${FFTW3F_LIBRARIES}
${MXML_LIBRARIES} pthread "-Wl,--no-as-needed -lpthread")
message(STATUS "Linking tests with: ${test_lib}")
diff --git a/src/globals.h b/src/globals.h
@@ -73,7 +73,7 @@ class SVFilter;
class FormantFilter;
class ModFilter;
-typedef double fftw_real;
+typedef float fftw_real;
typedef std::complex<fftw_real> fft_t;
/**