Skip to content

Commit

Permalink
Added exposed function in ayfStart node for tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
hkhauke committed Feb 23, 2024
1 parent 83cb4af commit 96ab183
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ if(JVX_USE_PART_MATLAB)
set(LOCAL_START_SCRIPT_MATLAB_SCRIPT_NAME "ayfStarter-mat")
set(LOCAL_START_SCRIPT_MATLAB ${CMAKE_CURRENT_SOURCE_DIR}/scripts/${JVX_OS}/start_mat)

set(JVX_MCG_LOCAL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/mcg/exports_project.mcg)

# Activate the secondary Matlab project
JVX_ACTIVATE_VERSION_MATLAB(${PROJECT_NAME} JVX_EXTERNAL_CALL_ENABLED)

# message(FATAL_ERROR "Hier")
endif()


Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
function [jvx_handle, jvx_out_frame] =jvxProcessOffline_local(jvx_handle, jvx_in_frame)
function [jvx_handle, jvx_out_frame_m] =jvxProcessOffline_local(jvx_handle, jvx_in_frame)

% Obtain processing handle
global inProcessing; % <- access to the current processing data struct, frame counter etc.
global jvx_host_call_global; % <- access to the underlying AudYoFlo host
% Access to the host
global jvx_host_call_global;

% Realize talkthrough
jvx_out_frame = jvx_in_frame * jvx_handle.volume;
% Version I: C function version
[a, jvx_out_frame_c] = jvx_host_call_global('external_call', 'CayfAuNStarter', 'ayf_starter_lib_process', jvx_in_frame);

% Version II: Matlab version
jvx_out_frame_m = jvx_in_frame * jvx_handle.volume;

% Optional: compare both outputs!
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
SECTION MATLAB_EXPORTS
{
//USE_MATLAB_CALL_AS_LIBRARY = "YES";
REFERENCE_CLASS = "CayfAuNStarter";
OUTPUTFILE_NAME = "CayfAuNStarter_external";
SECTION ayf_starter_lib_process
{
DESCRIPTION = "Simple example function to call core processing function";
ACCEPT_INPUT_TYPES = { "JVX_DATAFORMAT_DATA"};
DIMENSION_INPUT_FIELD = {"2D"};
DESCRIPTION_INPUT_PARAMETERS = { "Input signal, NxM"};
ACCEPT_INPUT_NUMBER_MIN = 1;
ACCEPT_INPUT_NUMBER_MAX = 1;
PRODUCE_OUTPUT_TYPES = {"JVX_DATAFORMAT_DATA"};
DIMENSION_OUTPUT_FIELD = {"2D"};
DESCRIPTION_INPUT_PARAMETERS = { "Output signal, NxM"};
ACCEPT_OUTPUT_NUMBER_MIN = 1;
ACCEPT_OUTPUT_NUMBER_MAX = 1;
INPUT_OUTPUT_CROSS_REFERENCE_X = {0};
INPUT_OUTPUT_CROSS_REFERENCE_Y = {0};
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ class CayfAuNStarter: public AYF_AUDIO_NODE_BASE_CLASS, public genStarter_node
// Step III: Define a property-set callback
JVX_PROPERTIES_FORWARD_C_CALLBACK_DECLARE(cb_async_set);


#ifdef JVX_EXTERNAL_CALL_ENABLED
#include "mcg_exports_project_prototypes.h"
void initExternalCall();
void terminateExternalCall();
#endif

};

#ifdef JVX_PROJECT_NAMESPACE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,61 @@
namespace JVX_PROJECT_NAMESPACE {
#endif

#include "mcg_exports_project.h"

void
CayfAuNStarter::initExternalCall()
{
std::string nameRegComponent;

// Obtain register name from generated code
requestExternalCallRegisterName(nameRegComponent);

// Set the string reference
_theExtCallObjectName = nameRegComponent;

// Request the handle
requestExternalCallHandle(_common_set_min.theHostRef, &_theExtCallHandler);

// Initialize it
initExternalCallhandler(_theExtCallHandler, static_cast<IjvxExternalCallTarget*>(this), _theExtCallObjectName);
}

void
CayfAuNStarter::terminateExternalCall()
{
// Unregister all local functions
terminateExternalCallhandler(_theExtCallHandler);

// NEVER derister the _theExtCallHandler instance here - it is still required by the base class
}

// ============================================================================================================
jvxErrorType CayfAuNStarter::ayf_starter_lib_process(
/* Input signal, NxM->*/ jvxData** paramIn0, jvxInt32 dimInY0, jvxInt32 dimInX0,
/* Output Parameter 0->*/ jvxData** paramOut0, jvxInt32 dimOutY0, jvxInt32 dimOutX0)
{
ayf_starter handle;
memset(&handle, 0, sizeof(handle));

if (dimInX0 != dimOutX0)
{
return JVX_ERROR_INVALID_SETTING;
}

ayf_starter_init(&handle);

handle.prmAsync.volume = processing_lib.prmAsync.volume;

ayf_starter_prepare(&handle);

ayf_starter_process(&handle, paramIn0, paramOut0, dimInY0, dimOutY0, dimInX0);

ayf_starter_postprocess(&handle);

return JVX_NO_ERROR;
}

#ifdef JVX_PROJECT_NAMESPACE
}
#endif
Expand Down

0 comments on commit 96ab183

Please sign in to comment.