Make FFTW3 optional; liquid-dsp is performing better on it's own..

This commit is contained in:
Charles J. Cliffe 2016-03-20 18:56:13 -04:00
parent 71cbdd3164
commit 020145c705
11 changed files with 277 additions and 43 deletions

View File

@ -38,6 +38,12 @@ ADD_DEFINITIONS(
ENDIF()
ENDIF()
SET (ENABLE_FFTW3 OFF CACHE BOOL "Use fftw3 instead of liquid-dsp internal fft.")
IF(ENABLE_FFTW3)
ADD_DEFINITIONS(
-DUSE_FFTW3=1
)
ENDIF()
set(USE_HAMLIB OFF CACHE BOOL "Support hamlib for radio control functions.")
@ -114,9 +120,11 @@ SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/${EX_PLATFORM_
IF (MSVC)
include_directories ("${PROJECT_SOURCE_DIR}/external/wglext")
SET(FFTW_INCLUDES "${PROJECT_SOURCE_DIR}/external/fftw-3.3.4/" CACHE STRING "FFTW Include Directory")
SET(FFTW_LIBRARIES "${PROJECT_SOURCE_DIR}/external/fftw-3.3.4/${EX_PLATFORM}/libfftw3f-3.lib" CACHE STRING "FFTW Library")
SET(FFTW_DLL "${PROJECT_SOURCE_DIR}/external/fftw-3.3.4/${EX_PLATFORM}/libfftw3f-3.dll" CACHE STRING "FFTW DLL")
IF(ENABLE_FFTW3)
SET(FFTW_INCLUDES "${PROJECT_SOURCE_DIR}/external/fftw-3.3.4/" CACHE STRING "FFTW Include Directory")
SET(FFTW_LIBRARIES "${PROJECT_SOURCE_DIR}/external/fftw-3.3.4/${EX_PLATFORM}/libfftw3f-3.lib" CACHE STRING "FFTW Library")
SET(FFTW_DLL "${PROJECT_SOURCE_DIR}/external/fftw-3.3.4/${EX_PLATFORM}/libfftw3f-3.dll" CACHE STRING "FFTW DLL")
ENDIF()
SET(LIQUID_INCLUDES "${PROJECT_SOURCE_DIR}/external/liquid-dsp/include/" CACHE STRING "Liquid-DSP include directory")
SET(LIQUID_LIBRARIES "${PROJECT_SOURCE_DIR}/external/liquid-dsp/msvc/${EX_PLATFORM}/libliquid.lib" CACHE STRING "Liquid-DSP Library")
SET(LIQUID_DLL "${PROJECT_SOURCE_DIR}/external/liquid-dsp/msvc/${EX_PLATFORM}/libliquid.dll" CACHE STRING "Liquid-DSP DLL")
@ -128,12 +136,16 @@ ELSE (MSVC)
ENDIF(MSVC)
find_package(OpenGL REQUIRED)
#IF (NOT WIN32)
find_package(FFTW REQUIRED)
IF(ENABLE_FFTW3)
find_package(FFTW REQUIRED)
include_directories(${FFTW_INCLUDES})
SET(OTHER_LIBRARIES ${OTHER_LIBRARIES} ${FFTW_LIBRARIES})
ENDIF()
find_package(Liquid REQUIRED)
include_directories(${LIQUID_INCLUDES} ${FFTW_INCLUDES})
SET(OTHER_LIBRARIES ${OTHER_LIBRARIES} ${LIQUID_LIBRARIES} ${FFTW_LIBRARIES})
#ENDIF()
include_directories(${LIQUID_INCLUDES})
SET(OTHER_LIBRARIES ${OTHER_LIBRARIES} ${LIQUID_LIBRARIES})
find_package(wxWidgets COMPONENTS gl core propgrid adv base REQUIRED)
set(wxWidgets_CONFIGURATION mswu)
@ -198,7 +210,10 @@ IF (UNIX AND NOT APPLE)
SET(USE_AUDIO_ALSA OFF CACHE BOOL "Use ALSA Audio")
SET(USE_AUDIO_OSS OFF CACHE BOOL "Use OSS Audio")
SET(FFTW_LIB fftw3f)
IF(ENABLE_FFTW3)
SET(FFTW_LIB fftw3f)
ENDIF()
SET(LIQUID_LIB liquid)
SET(OTHER_LIBRARIES ${OTHER_LIBRARIES} dl)
@ -240,7 +255,10 @@ ENDIF(UNIX AND NOT APPLE)
IF (APPLE)
SET(CMAKE_OSX_DEPLOYMENT_TARGET, "10.9")
SET(FFTW_LIB fftw3f)
IF(ENABLE_FFTW3)
SET(FFTW_LIB fftw3f)
ENDIF()
SET(LIQUID_LIB liquid)
link_directories(/usr/local/lib)
link_directories(/opt/local/lib)
@ -560,11 +578,16 @@ IF (NOT BUNDLE_APP)
configure_files(${PROJECT_SOURCE_DIR}/font ${CMAKE_BINARY_DIR}/${EX_PLATFORM_NAME} "*.png")
configure_files(${PROJECT_SOURCE_DIR}/icon ${CMAKE_BINARY_DIR}/${EX_PLATFORM_NAME} CubicSDR.ico)
IF(MSVC)
configure_files(${PROJECT_SOURCE_DIR}/external/fftw-3.3.4/${EX_PLATFORM}/ ${CMAKE_BINARY_DIR}/${EX_PLATFORM_NAME} "*.dll")
IF(ENABLE_FFTW3)
configure_files(${PROJECT_SOURCE_DIR}/external/fftw-3.3.4/${EX_PLATFORM}/ ${CMAKE_BINARY_DIR}/${EX_PLATFORM_NAME} "*.dll")
ENDIF()
configure_files(${PROJECT_SOURCE_DIR}/external/liquid-dsp/msvc/${EX_PLATFORM}/ ${CMAKE_BINARY_DIR}/${EX_PLATFORM_NAME} "*.dll")
ENDIF()
add_executable(CubicSDR ${cubicsdr_sources} ${cubicsdr_headers} ${RES_FILES})
target_link_libraries(CubicSDR ${LIQUID_LIB} ${FFTW_LIB} ${wxWidgets_LIBRARIES} ${OPENGL_LIBRARIES} ${OTHER_LIBRARIES})
IF(ENABLE_FFTW3)
target_link_libraries(CubicSDR ${FFTW_LIB})
ENDIF()
target_link_libraries(CubicSDR ${LIQUID_LIB} ${wxWidgets_LIBRARIES} ${OPENGL_LIBRARIES} ${OTHER_LIBRARIES})
ENDIF (NOT BUNDLE_APP)
IF (MSVC)
@ -624,7 +647,11 @@ IF (APPLE AND BUNDLE_APP)
MACOSX_PACKAGE_LOCATION Resources
)
target_link_libraries(CubicSDR ${LIQUID_LIB} ${FFTW_LIB} ${wxWidgets_LIBRARIES} ${OPENGL_LIBRARIES} ${OTHER_LIBRARIES})
IF(ENABLE_FFTW3)
target_link_libraries(CubicSDR ${FFTW_LIB})
ENDIF()
target_link_libraries(CubicSDR ${LIQUID_LIB} ${wxWidgets_LIBRARIES} ${OPENGL_LIBRARIES} ${OTHER_LIBRARIES})
SET_TARGET_PROPERTIES(CubicSDR PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_STRING "CubicSDR Open-Source Software-Defined Radio Application"
@ -779,9 +806,15 @@ IF (WIN32 AND NOT BUILD_INSTALLER)
INSTALL(TARGETS CubicSDR DESTINATION bin)
INSTALL(FILES
${FFTW_DLL}
${LIQUID_DLL}
DESTINATION bin)
IF(ENABLE_FFTW3)
INSTALL(FILES
${FFTW_DLL}
DESTINATION bin)
ENDIF()
INSTALL(FILES
${CUBICSDR_RESOURCES}
${PROJECT_SOURCE_DIR}/src/CubicSDR.png
@ -817,10 +850,15 @@ IF (WIN32 AND BUILD_INSTALLER)
install(FILES
${CUBICSDR_RESOURCES}
${PROJECT_SOURCE_DIR}/icon/CubicSDR.ico
${FFTW_DLL}
${LIQUID_DLL}
DESTINATION .)
IF(ENABLE_FFTW3)
install(FILES
${FFTW_DLL}
DESTINATION .)
ENDIF()
IF (BUNDLE_SOAPY_MODS)
ADD_DEFINITIONS(
-DBUNDLE_SOAPY_MODS=1
@ -854,7 +892,10 @@ ENDIF (WIN32 AND BUILD_INSTALLER)
IF (UNIX AND NOT APPLE AND BUILD_DEB)
set(CPACK_GENERATOR DEB)
set(CPACK_PACKAGE_NAME "CubicSDR")
SET(CPACK_DEBIAN_PACKAGE_DEPENDS " libfftw3-single3, libwxgtk3.0-0, libpulse0")
SET(CPACK_DEBIAN_PACKAGE_DEPENDS " libwxgtk3.0-0, libpulse0")
IF(ENABLE_FFTW3)
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libfftw3-single3")
ENDIF()
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Charles J. Cliffe <cj@cubicproductions.com>")
SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION "CubicSDR Software Defined Radio application v${CUBICSDR_VERSION}")
SET(CPACK_DEBIAN_PACKAGE_SECTION "comm")

View File

@ -2,31 +2,54 @@
#include <cstring>
#include <string>
ScopeVisualProcessor::ScopeVisualProcessor(): outputBuffers("ScopeVisualProcessorBuffers"), fftInData(NULL), fftwOutput(NULL), fftw_plan(NULL), maxScopeSamples(1024) {
ScopeVisualProcessor::ScopeVisualProcessor(): outputBuffers("ScopeVisualProcessorBuffers") {
scopeEnabled.store(true);
spectrumEnabled.store(true);
fft_average_rate = 0.65;
fft_ceil_ma = fft_ceil_maa = 0;
fft_floor_ma = fft_floor_maa = 0;
maxScopeSamples = 1024;
#if USE_FFTW3
fftInData = nullptr;
fftwOutput = nullptr;
fftw_plan = nullptr;
#else
fftInData = nullptr;
fftOutput = nullptr;
fftPlan = nullptr;
#endif
}
ScopeVisualProcessor::~ScopeVisualProcessor() {
/*if (fftInData) {
#if USE_FFTW3
if (fftw_plan) {
fftwf_destroy_plan(fftw_plan);
}
if (fftInData) {
free(fftInData);
}
if (fftwOutput) {
free(fftwOutput);
}*/
if (fftw_plan) {
fftwf_destroy_plan(fftw_plan);
}
#else
if (fftPlan) {
fft_destroy_plan(fftPlan);
}
if (fftInData) {
free(fftInData);
}
if (fftOutput) {
free(fftOutput);
}
#endif
}
void ScopeVisualProcessor::setup(int fftSize_in) {
fftSize = fftSize_in;
desiredInputSize = fftSize;
#if USE_FFTW3
if (fftInData) {
free(fftInData);
}
@ -39,9 +62,20 @@ void ScopeVisualProcessor::setup(int fftSize_in) {
fftwf_destroy_plan(fftw_plan);
}
fftw_plan = fftwf_plan_dft_r2c_1d(fftSize, fftInData, fftwOutput, FFTW_ESTIMATE);
//(fftSize, fftInData, fftwOutput, 0);
//(fftSize, fftwInput, fftwOutput, FFTW_R2HC, FFTW_ESTIMATE);
#else
if (fftInData) {
free(fftInData);
}
fftInData = (liquid_float_complex*) malloc(sizeof(liquid_float_complex) * fftSize);
if (fftOutput) {
free(fftOutput);
}
fftOutput = (liquid_float_complex*) malloc(sizeof(liquid_float_complex) * fftSize);
if (fftPlan) {
fft_destroy_plan(fftPlan);
}
fftPlan = fft_create_plan(fftSize, fftInData, fftOutput, LIQUID_FFT_FORWARD, 0);
#endif
}
void ScopeVisualProcessor::setScopeEnabled(bool scopeEnable) {
@ -130,6 +164,7 @@ void ScopeVisualProcessor::process() {
if (spectrumEnabled) {
iMax = audioInputData->data.size();
#if USE_FFTW3
if (audioInputData->channels==1) {
for (i = 0; i < fftSize; i++) {
if (i < iMax) {
@ -148,6 +183,29 @@ void ScopeVisualProcessor::process() {
}
}
}
#else
if (audioInputData->channels==1) {
for (i = 0; i < fftSize; i++) {
if (i < iMax) {
fftInData[i].real = audioInputData->data[i];
fftInData[i].imag = 0;
} else {
fftInData[i].real = 0;
}
}
} else if (audioInputData->channels==2) {
iMax = iMax/2;
for (i = 0; i < fftSize; i++) {
if (i < iMax) {
fftInData[i].real = audioInputData->data[i] + audioInputData->data[iMax+i];
fftInData[i].imag = 0;
} else {
fftInData[i].real = 0;
fftInData[i].imag = 0;
}
}
}
#endif
renderData = outputBuffers.getBuffer();
@ -156,9 +214,7 @@ void ScopeVisualProcessor::process() {
renderData->sampleRate = audioInputData->sampleRate;
audioInputData->decRefCount();
fftwf_execute(fftw_plan);
float fft_ceil = 0, fft_floor = 1;
if (fft_result.size() < (fftSize/2)) {
@ -166,12 +222,23 @@ void ScopeVisualProcessor::process() {
fft_result_ma.resize((fftSize/2));
fft_result_maa.resize((fftSize/2));
}
#if USE_FFTW3
fftwf_execute(fftw_plan);
for (i = 0; i < (fftSize/2); i++) {
float a = fftwOutput[i][0];
float b = fftwOutput[i][1];
fft_result[i] = sqrt( a * a + b * b);
}
#else
fft_execute(fftPlan);
for (i = 0; i < (fftSize/2); i++) {
float a = fftOutput[i].real;
float b = fftOutput[i].imag;
fft_result[i] = sqrt( a * a + b * b);
}
#endif
for (i = 0; i < (fftSize/2); i++) {
fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * fft_average_rate;

View File

@ -2,9 +2,12 @@
#include "VisualProcessor.h"
#include "AudioThread.h"
#include "fftw3.h"
#include "ScopePanel.h"
#if USE_FFTW3
#include "fftw3.h"
#endif
class ScopeRenderData: public ReferenceCounter {
public:
std::vector<float> waveform_points;
@ -33,9 +36,16 @@ protected:
std::atomic_bool scopeEnabled;
std::atomic_bool spectrumEnabled;
#if USE_FFTW3
float *fftInData;
fftwf_complex *fftwOutput;
fftwf_plan fftw_plan;
#else
liquid_float_complex *fftInData;
liquid_float_complex *fftOutput;
fftplan fftPlan;
#endif
unsigned int fftSize;
int desiredInputSize;
unsigned int maxScopeSamples;

View File

@ -2,7 +2,26 @@
#include "CubicSDR.h"
SpectrumVisualProcessor::SpectrumVisualProcessor() : outputBuffers("SpectrumVisualProcessorBuffers"), lastInputBandwidth(0), lastBandwidth(0), fftwInput(NULL), fftwOutput(NULL), fftInData(NULL), fftLastData(NULL), lastDataSize(0), fftw_plan(NULL), resampler(NULL), resamplerRatio(0) {
SpectrumVisualProcessor::SpectrumVisualProcessor() : outputBuffers("SpectrumVisualProcessorBuffers") {
lastInputBandwidth = 0;
lastBandwidth = 0;
lastDataSize = 0;
resampler = nullptr;
resamplerRatio = 0;
#if USE_FFTW3
fftwInput = nullptr;
fftwOutput = nullptr;
fftInData = nullptr;
fftLastData = nullptr;
fftw_plan = nullptr;
#else
fftInput = nullptr;
fftOutput = nullptr;
fftInData = nullptr;
fftLastData = nullptr;
fftPlan = nullptr;
#endif
is_view.store(false);
fftSize.store(0);
@ -23,6 +42,7 @@ SpectrumVisualProcessor::SpectrumVisualProcessor() : outputBuffers("SpectrumVisu
lastView = false;
peakHold.store(false);
peakReset.store(false);
}
SpectrumVisualProcessor::~SpectrumVisualProcessor() {
@ -101,7 +121,8 @@ void SpectrumVisualProcessor::setup(unsigned int fftSize_in) {
fftSize = fftSize_in;
fftSizeInternal = fftSize_in * SPECTRUM_VZM;
lastDataSize = 0;
#if USE_FFTW3
int memSize = sizeof(fftwf_complex) * fftSizeInternal;
if (fftwInput) {
@ -136,6 +157,39 @@ void SpectrumVisualProcessor::setup(unsigned int fftSize_in) {
fftwf_destroy_plan(fftw_plan);
}
fftw_plan = fftwf_plan_dft_1d(fftSizeInternal, fftwInput, fftwOutput, FFTW_FORWARD, FFTW_ESTIMATE);
#else
int memSize = sizeof(liquid_float_complex) * fftSizeInternal;
if (fftInput) {
free(fftInput);
}
fftInput = (liquid_float_complex*)malloc(memSize);
memset(fftInput,0,memSize);
if (fftInData) {
free(fftInData);
}
fftInData = (liquid_float_complex*)malloc(memSize);
memset(fftInput,0,memSize);
if (fftLastData) {
free(fftLastData);
}
fftLastData = (liquid_float_complex*)malloc(memSize);
memset(fftInput,0,memSize);
if (fftOutput) {
free(fftOutput);
}
fftOutput = (liquid_float_complex*)malloc(memSize);
memset(fftInput,0,memSize);
if (fftPlan) {
fft_destroy_plan(fftPlan);
}
fftPlan = fft_create_plan(fftSizeInternal, fftInput, fftOutput, LIQUID_FFT_FORWARD, 0);
#endif
busy_run.unlock();
}
@ -311,6 +365,7 @@ void SpectrumVisualProcessor::process() {
msresamp_crcf_execute(resampler, &shiftBuffer[0], desired_input_size, &resampleBuffer[0], &num_written);
#if USE_FFTW3
if (num_written < fftSizeInternal) {
for (unsigned int i = 0; i < num_written; i++) {
fftInData[i][0] = resampleBuffer[i].real;
@ -326,10 +381,19 @@ void SpectrumVisualProcessor::process() {
fftInData[i][1] = resampleBuffer[i].imag;
}
}
#else
if (num_written < fftSizeInternal) {
memcpy(fftInData, resampleBuffer.data(), num_written * sizeof(liquid_float_complex));
memset(&(fftInData[num_written]), 0, (fftSizeInternal-num_written) * sizeof(liquid_float_complex));
} else {
memcpy(fftInData, resampleBuffer.data(), fftSizeInternal * sizeof(liquid_float_complex));
}
#endif
} else {
this->desiredInputSize.store(fftSizeInternal);
num_written = data->size();
#if USE_FFTW3
if (data->size() < fftSizeInternal) {
for (size_t i = 0, iMax = data->size(); i < iMax; i++) {
fftInData[i][0] = (*data)[i].real;
@ -345,10 +409,19 @@ void SpectrumVisualProcessor::process() {
fftInData[i][1] = (*data)[i].imag;
}
}
#else
if (data->size() < fftSizeInternal) {
memcpy(fftInData, data->data(), data->size() * sizeof(liquid_float_complex));
memset(&fftInData[data->size()], 0, (fftSizeInternal - data->size()) * sizeof(liquid_float_complex));
} else {
memcpy(fftInData, data->data(), fftSizeInternal * sizeof(liquid_float_complex));
}
#endif
}
bool execute = false;
#if USE_FFTW3
if (num_written >= fftSizeInternal) {
execute = true;
memcpy(fftwInput, fftInData, fftSizeInternal * sizeof(fftwf_complex));
@ -370,6 +443,29 @@ void SpectrumVisualProcessor::process() {
execute = true;
}
}
#else
if (num_written >= fftSizeInternal) {
execute = true;
memcpy(fftInput, fftInData, fftSizeInternal * sizeof(liquid_float_complex));
memcpy(fftLastData, fftInput, fftSizeInternal * sizeof(liquid_float_complex));
} else {
if (lastDataSize + num_written < fftSizeInternal) { // priming
unsigned int num_copy = fftSizeInternal - lastDataSize;
if (num_written > num_copy) {
num_copy = num_written;
}
memcpy(fftLastData, fftInData, num_copy * sizeof(liquid_float_complex));
lastDataSize += num_copy;
} else {
unsigned int num_last = (fftSizeInternal - num_written);
memcpy(fftInput, fftLastData + (lastDataSize - num_last), num_last * sizeof(liquid_float_complex));
memcpy(fftInput + num_last, fftInData, num_written * sizeof(liquid_float_complex));
memcpy(fftLastData, fftInput, fftSizeInternal * sizeof(liquid_float_complex));
execute = true;
}
}
#endif
if (execute) {
SpectrumVisualData *output = outputBuffers.getBuffer();
@ -385,9 +481,10 @@ void SpectrumVisualProcessor::process() {
output->spectrum_hold_points.resize(0);
}
fftwf_execute(fftw_plan);
float fft_ceil = 0, fft_floor = 1;
#if USE_FFTW3
fftwf_execute(fftw_plan);
for (int i = 0, iMax = fftSizeInternal / 2; i < iMax; i++) {
float a = fftwOutput[i][0];
@ -401,6 +498,22 @@ void SpectrumVisualProcessor::process() {
fft_result[i] = (z);
fft_result[fftSizeInternal / 2 + i] = (c);
}
#else
fft_execute(fftPlan);
for (int i = 0, iMax = fftSizeInternal / 2; i < iMax; i++) {
float a = fftOutput[i].real;
float b = fftOutput[i].imag;
float c = sqrt(a * a + b * b);
float x = fftOutput[fftSizeInternal / 2 + i].real;
float y = fftOutput[fftSizeInternal / 2 + i].imag;
float z = sqrt(x * x + y * y);
fft_result[i] = (z);
fft_result[fftSizeInternal / 2 + i] = (c);
}
#endif
if (newResampler && lastView) {
if (bwDiff < 0) {

View File

@ -2,9 +2,12 @@
#include "VisualProcessor.h"
#include "DemodDefs.h"
#include "fftw3.h"
#include <cmath>
#if USE_FFTW3
#include "fftw3.h"
#endif
#define SPECTRUM_VZM 2
#define PEAK_RESET_COUNT 30
@ -63,10 +66,16 @@ private:
long lastInputBandwidth;
long lastBandwidth;
bool lastView;
#if USE_FFTW3
fftwf_complex *fftwInput, *fftwOutput, *fftInData, *fftLastData;
unsigned int lastDataSize;
fftwf_plan fftw_plan;
#else
liquid_float_complex *fftInput, *fftOutput, *fftInData, *fftLastData;
fftplan fftPlan;
#endif
unsigned int lastDataSize;
double fft_ceil_ma, fft_ceil_maa;
double fft_floor_ma, fft_floor_maa;

View File

@ -10,7 +10,6 @@
#include "UITestContext.h"
#include "MouseTracker.h"
#include "fftw3.h"
#include "Timer.h"
class UITestCanvas: public InteractiveCanvas {

View File

@ -11,7 +11,6 @@
#include "GLPanel.h"
#include "PrimaryGLContext.h"
#include "fftw3.h"
#include "Timer.h"
class GainInfo {

View File

@ -10,7 +10,6 @@
#include "MeterContext.h"
#include "MouseTracker.h"
#include "fftw3.h"
#include "Timer.h"
class MeterCanvas: public InteractiveCanvas {

View File

@ -10,7 +10,6 @@
#include "ModeSelectorContext.h"
#include "MouseTracker.h"
#include "fftw3.h"
#include "Timer.h"
class ModeSelectorMode {

View File

@ -10,7 +10,6 @@
#include "ScopeVisualProcessor.h"
#include "ScopePanel.h"
#include "SpectrumPanel.h"
#include "fftw3.h"
#include "InteractiveCanvas.h"
class ScopeCanvas: public InteractiveCanvas {

View File

@ -10,7 +10,6 @@
#include "TuningContext.h"
#include "MouseTracker.h"
#include "fftw3.h"
#include "Timer.h"
class TuningCanvas: public InteractiveCanvas {