-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1) Added enums for the numerical limit of options in C functions
2) Checked for type when converting config struct in Matlab integration 3) Catch exception in CjvxMexCalls calls that are interrupted by debugger quit in Matlab 4) Added Mex module for fft framework
- Loading branch information
Showing
9 changed files
with
646 additions
and
18 deletions.
There are no files selected for viewing
Empty file.
46 changes: 46 additions & 0 deletions
46
sources/jvxApplications/mex/jvxFFTFwk/cmake/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
set(PROJECT_NAME jvxFFTFwk) | ||
include(${JVX_CMAKE_DIR}/common_local_mex_head.cmake) | ||
|
||
include_directories( | ||
${CMAKE_CURRENT_SOURCE_DIR}/../src | ||
${JVX_BASE_ROOT}/sources/jvxLibraries/ayf-mex-connect/include | ||
${JVX_SUBPRODUCT_LIBS_INCLUDE_PATH}/jvx-dsp/include | ||
) | ||
|
||
set(LOCAL_SOURCES | ||
${CMAKE_CURRENT_SOURCE_DIR}/../target/entryMex.cpp | ||
|
||
${CMAKE_CURRENT_SOURCE_DIR}/../src/CjvxFFTFwk.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/../src/CjvxFFTFwk.h | ||
) | ||
|
||
set(LOCAL_LIBS "jvx-dsp_static") | ||
|
||
set(INSTALL_COMMON_MEX_TARGET_NAME "${PROJECT_NAME}") | ||
|
||
if(JVX_USE_PART_MATLAB) | ||
set(JVX_TARGET_NAME "${PROJECT_NAME}_m") | ||
set(LOCAL_MAT_LIBS ayf-mex-connect_m_static) | ||
set(INSTALL_TARGET_NAME_MATLAB ${JVX_TARGET_NAME}) | ||
set(BUILD_MEX_MATLAB TRUE) | ||
set(BUILD_MEX_OCTAVE FALSE) | ||
set(JVX_RENAME_RELEASE "${PROJECT_NAME}") | ||
include(${JVX_CMAKE_DIR}/common_local_mex_foot.cmake) | ||
endif() | ||
|
||
if(JVX_USE_PART_OCTAVE) | ||
|
||
set(JVX_TARGET_NAME "${PROJECT_NAME}_o") | ||
set(LOCAL_OCT_LIBS ayf-mex-connect_o_static) | ||
set(INSTALL_TARGET_NAME_OCTAVE ${JVX_TARGET_NAME}) | ||
set(BUILD_MEX_OCTAVE TRUE) | ||
set(BUILD_MEX_MATLAB FALSE) | ||
set(JVX_RENAME_RELEASE "${PROJECT_NAME}") | ||
include(${JVX_CMAKE_DIR}/common_local_mex_foot.cmake) | ||
if(JVX_USE_PART_MATLAB) | ||
add_dependencies(${PROJECT_NAME}_o ${PROJECT_NAME}_m) | ||
endif() | ||
endif() | ||
|
||
|
||
|
226 changes: 226 additions & 0 deletions
226
sources/jvxApplications/mex/jvxFFTFwk/src/CjvxFFTFwk.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
#include "CjvxFFTFwk.h" | ||
|
||
#include "CjvxMatlabToCConverter.h" | ||
|
||
CjvxFFTFwk::CjvxFFTFwk() | ||
{ | ||
} | ||
|
||
jvxErrorType | ||
CjvxFFTFwk::init_fft_fwk(const mxArray* arrCfg) | ||
{ | ||
if (core_inst != nullptr) | ||
{ | ||
return JVX_ERROR_WRONG_STATE; | ||
} | ||
|
||
JVX_SAFE_ALLOCATE_OBJECT_CPP_Z(core_inst, jvx_fft_signal_processing); | ||
jvx_fft_signal_processing_initCfg(core_inst); | ||
|
||
if (mxIsStruct(arrCfg)) | ||
{ | ||
mexPrintf("fft signal processing is configured by sub-struct <fft_processor>.\n"); | ||
const mxArray* arrFft = CjvxMatlabToCConverter::jvx_mex_lookup_strfield(arrCfg, "fft_processor"); | ||
const mxArray* val = nullptr; | ||
|
||
jvxErrorType res = JVX_NO_ERROR; | ||
|
||
jvxSize fftSize = 0; | ||
|
||
if (arrFft) | ||
{ | ||
std::string token; | ||
mexPrintf("--> Found struct field <fft_processor>, reading single values for fwk configuration.\n"); | ||
|
||
/* | ||
* -- Struct cfg -- | ||
* jvxFftTools_fwkType fftFrameworkType; -> selectFftFramework | ||
* jvxSize ifcf_length_max; -> ifcf_length_max | ||
* jvxSize ir_length_max; -> ir_length_max | ||
* jvxFFTSize fftType; | ||
* jvxSize hopsize; -> hopsize | ||
* jvxSize buffersize; -> buffersize | ||
* | ||
* jvxCBool allocateProcessingFft; | ||
* jvxCBool allocateAnalysisFft; | ||
* jvxCBool allocateWeightCorrection; | ||
* | ||
* jvx_windowType desiredWindowTypeWeightCorrection; | ||
* | ||
* -- Struct async -- | ||
* jvxCBool auto_aliasing; -> auto_anti_aliasing | ||
* jvxCBool employ_antialias_weight_processing; -> antialias | ||
* jvxSize ifcf_length; -> ifcf_length | ||
* | ||
* -- Struct sync -- | ||
* jvxInt32 percentAnalysisWinFftSize; -> percentAnalysisWinFftSize | ||
* jvx_windowType wintype; -> wintype | ||
* | ||
* | ||
* -> FFTSize | ||
* -> hopsize | ||
* -> buffersize | ||
* | ||
*/ | ||
JVX_MEX_READ_SINGLE_FROM_STRUCT(res, "fftsize", arrFft, fftSize); | ||
if (res != JVX_NO_ERROR) mexPrintf("--> Failed to read entry for <FFTSize> in struct.\n"); | ||
|
||
JVX_MEX_READ_SINGLE_FROM_STRUCT(res, "ifcf_length_max", arrFft, core_inst->cfg.ifcf_length_max); | ||
if (res != JVX_NO_ERROR) mexPrintf("--> Failed to read entry for <ifcf_length_max> in struct.\n"); | ||
|
||
JVX_MEX_READ_SINGLE_FROM_STRUCT(res, "ir_length_max", arrFft, core_inst->cfg.ir_length_max); | ||
if (res != JVX_NO_ERROR) mexPrintf("--> Failed to read entry for <ir_length_max> in struct.\n"); | ||
|
||
JVX_MEX_READ_SINGLE_FROM_STRUCT(res, "hopsize", arrFft, core_inst->cfg.hopsize); | ||
if (res != JVX_NO_ERROR) mexPrintf("--> Failed to read entry for <hopsize> in struct.\n"); | ||
|
||
JVX_MEX_READ_SINGLE_FROM_STRUCT(res, "buffersize", arrFft, core_inst->cfg.buffersize); | ||
if (res != JVX_NO_ERROR) mexPrintf("--> Failed to read entry for <buffersize> in struct.\n"); | ||
|
||
JVX_MEX_READ_SELECTION_FROM_STRUCT(res, "selectFftFramework", arrFft, core_inst->cfg.fftFrameworkType, JVX_FFT_TOOLS_FWK_LIMIT, jvxFftTools_fwkType); | ||
if (res != JVX_NO_ERROR) mexPrintf("--> Failed to read entry for <selectFftFramework> in struct.\n"); | ||
|
||
// ASYNC | ||
|
||
JVX_MEX_READ_SINGLE_FROM_STRUCT(res, "auto_anti_aliasing", arrFft, core_inst->async.auto_aliasing); | ||
if (res != JVX_NO_ERROR) mexPrintf("--> Failed to read entry for <auto_anti_aliasing> in struct.\n"); | ||
|
||
JVX_MEX_READ_SINGLE_FROM_STRUCT(res, "antialias", arrFft, core_inst->async.employ_antialias_weight_processing); | ||
if (res != JVX_NO_ERROR) mexPrintf("--> Failed to read entry for <antialias> in struct.\n"); | ||
|
||
JVX_MEX_READ_SINGLE_FROM_STRUCT(res, "ifcf_length", arrFft, core_inst->async.ifcf_length); | ||
if (res != JVX_NO_ERROR) mexPrintf("--> Failed to read entry for <ifcf_length> in struct.\n"); | ||
|
||
// ASYNC | ||
|
||
JVX_MEX_READ_SINGLE_FROM_STRUCT(res, "percentAnalysisWinFftSize", arrFft, core_inst->sync.percentAnalysisWinFftSize); | ||
if (res != JVX_NO_ERROR) mexPrintf("--> Failed to read entry for <percentAnalysisWinFftSize> in struct.\n"); | ||
|
||
JVX_MEX_READ_SELECTION_FROM_STRUCT(res, "wintype", arrFft, core_inst->sync.wintype, JVX_WINDOW_LIMIT, jvx_windowType); | ||
if (res != JVX_NO_ERROR) mexPrintf("--> Failed to read entry for <wintype> in struct.\n"); | ||
|
||
/* | ||
JVX_MEX_READ_SELECTION_FROM_STRUCT(res, "fftType/jvxSelection_value", arrFwk, fftType, jvxFFTSize::JVX_FFT_TOOLS_FFT_SIZE_8192, jvxFFTSize); | ||
/* | ||
JVX_MEX_READ_SINGLE_FROM_STRUCT(res, "FFTSize", arrFwk, R); | ||
if (res != JVX_NO_ERROR) mexPrintf("--> Failed to read entry for <R> in struct.\n"); | ||
JVX_MEX_READ_SELECTION_FROM_STRUCT(res, "fftType/jvxSelection_value", arrFwk, fftType, jvxFFTSize::JVX_FFT_TOOLS_FFT_SIZE_8192, jvxFFTSize); | ||
if (res != JVX_NO_ERROR) mexPrintf("--> Failed to read entry for <fftType/jvxSelection_value> in struct.\n"); | ||
*/ | ||
} | ||
|
||
// ================================================================================================================ | ||
jvxSize loc_fftsize; | ||
jvx_get_nearest_size_fft(&core_inst->cfg.fftType, fftSize, JVX_FFT_ROUND_NEAREST, &loc_fftsize); | ||
|
||
jvx_fft_signal_processing_updateCfg(&core_inst->derived, &core_inst->cfg); | ||
assert(core_inst->derived.fftsize == loc_fftsize); | ||
|
||
// FFT Size must be multiples of 2 | ||
if ( | ||
((core_inst->derived.fftsize % 2) == 1) || | ||
(core_inst->derived.fftsize < core_inst->cfg.buffersize) || | ||
(core_inst->derived.fftsize < core_inst->cfg.hopsize)) | ||
|
||
{ | ||
mexPrintf("--> Failed to initialize fft processor handle - invalid configuration.\n"); | ||
} | ||
|
||
|
||
// ================================================================================= | ||
// INITIALIZATION | ||
// ================================================================================= | ||
|
||
|
||
// Allocate global data for FFT usage (reuse twiddle factors in Mac cases) | ||
jvxErrorType resL = jvx_create_fft_ifft_global(&global_hdl, (jvxFFTSize)core_inst->cfg.fftType); | ||
assert(resL == JVX_DSP_NO_ERROR); | ||
|
||
/* | ||
-> updateCfg will be called in prepare!!! | ||
jvx_fft_signal_processing_updateCfg(&H->runtime.noise_signal_proc.cfg, &H->runtime.noise_signal_proc.cfg); | ||
jvx_fft_signal_processing_updateCfg(&H->runtime.announce_signal_proc.cfg); | ||
*/ | ||
|
||
// Configuration for noise signal | ||
core_inst->cfg.allocateAnalysisFft = true; | ||
core_inst->cfg.allocateWeightCorrection = true; | ||
core_inst->cfg.allocateProcessingFft = true; | ||
|
||
M2P1 = core_inst->derived.fftsize / 2 + 1; | ||
hopsize = core_inst->cfg.hopsize; | ||
|
||
jvx_fft_signal_processing_prepare(core_inst, global_hdl); | ||
|
||
} | ||
|
||
return JVX_NO_ERROR; | ||
} | ||
|
||
jvxErrorType | ||
CjvxFFTFwk::term_fft_fwk() | ||
{ | ||
if (core_inst == nullptr) | ||
{ | ||
return JVX_ERROR_WRONG_STATE; | ||
} | ||
|
||
jvx_fft_signal_processing_postprocess(core_inst); | ||
JVX_SAFE_DELETE_OBJECT(core_inst); | ||
|
||
return JVX_NO_ERROR; | ||
} | ||
|
||
jvxErrorType | ||
CjvxFFTFwk::process_fft_fwk_input(jvxData* input, jvxDataCplx* outputBufProc, jvxDataCplx* outputBufAna) | ||
{ | ||
int i; | ||
|
||
if (core_inst == nullptr) | ||
{ | ||
return JVX_ERROR_WRONG_STATE; | ||
} | ||
|
||
jvx_fft_signal_processing_input(core_inst, input, core_inst->cfg.hopsize); | ||
|
||
if (outputBufProc) | ||
{ | ||
memcpy(outputBufProc, core_inst->derived.outFftBuffer, sizeof(jvxDataCplx) * M2P1); | ||
} | ||
|
||
if (outputBufAna) | ||
{ | ||
if (core_inst->derived.outFftBufferAnalysis) | ||
{ | ||
memcpy(outputBufAna, core_inst->derived.outFftBufferAnalysis, sizeof(jvxDataCplx) * M2P1); | ||
} | ||
else | ||
{ | ||
memcpy(outputBufAna, core_inst->derived.outFftBuffer, sizeof(jvxDataCplx) * M2P1); | ||
} | ||
} | ||
|
||
return JVX_NO_ERROR; | ||
} | ||
|
||
jvxErrorType | ||
CjvxFFTFwk::process_fft_fwk_output(jvxDataCplx* input, jvxData* weights, jvxData* output) | ||
{ | ||
int i; | ||
if (core_inst == nullptr) | ||
{ | ||
return JVX_ERROR_WRONG_STATE; | ||
} | ||
|
||
if (input) | ||
{ | ||
memcpy(core_inst->derived.outFftBuffer, input, sizeof(jvxDataCplx) * M2P1); | ||
} | ||
|
||
jvx_fft_signal_processing_output(core_inst, output, weights, core_inst->cfg.hopsize); | ||
return JVX_NO_ERROR; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef __CJVXNECORE_H__ | ||
#define __CJVXNECORE_H__ | ||
|
||
#include "jvx.h" | ||
|
||
#include "localMexIncludes.h" | ||
|
||
extern "C" | ||
{ | ||
#include "jvx_fft_processing/jvx_fft_processing.h" | ||
} | ||
|
||
class CjvxFFTFwk | ||
{ | ||
protected: | ||
|
||
jvx_fft_signal_processing* core_inst = nullptr; | ||
jvxFFTGlobal* global_hdl = nullptr; | ||
|
||
public: | ||
|
||
CjvxFFTFwk(); | ||
jvxErrorType init_fft_fwk(const mxArray* arrCfg); | ||
jvxErrorType term_fft_fwk(); | ||
jvxErrorType process_fft_fwk_input(jvxData* input, jvxDataCplx* outputBufProc, jvxDataCplx* outputBufAna); | ||
jvxErrorType process_fft_fwk_output(jvxDataCplx* input, jvxData* weights, jvxData* output); | ||
|
||
jvxSize M2P1 = 0; | ||
jvxSize hopsize = 0; | ||
|
||
}; | ||
|
||
#endif |
Oops, something went wrong.