Skip to content

AudYoFlo: Tutorial I: Step II: Involving a Signal Processing Library

jvxgit edited this page Apr 17, 2024 · 4 revisions

In the next step, a low-level signal processing library shall be added. That library is pretty simple for this demonstration as it only does the same that the algorithm did before: it copies input sample to output buffers.

In order to involve the library, we add a new folder Libraries to our sub-project,

grafik

In that folder, we store the signal processing library called ayfstarterlib:

grafik

The involved library is implemented purely in C. It contains a header file ayfstarterlib.h in folder include and a file ayfstarterlib.c in folder src. A CMakeLists.txt file contains the recipes to build the library.

The code is straight forward:

Header file ayfstarterlib.h

In the library header file a struct as well as the interface functions are declared:

grafik

Typically, the library is configured at first, then all required memory is allocated during prepare, and finally, the processing function is called on a frame-by-frame basis during processing. Once the processing is over, the previously allocated memory is deallocate in the postprocessing.

Implmentation in file ayfstarterlib.c

In the implementation of the library, the C functions are realized in file ayfstarterlib.c:

grafik

Besides the state transition functions, an update function is part of the library that allows to set asynchronous parameters to be set and read while in operation.

Involving the library in the sub-project

In order to involve the library, the local CMakeLists.txt file must be involved in the main ayfstarter/CMakeLists.txt file of our sub-project as shown in the following figure:

grafik

The required references are highlighted.

Referencing the library in the audio node

Now that the library is available and built during cmake build process, we need to reference it from within our audio node component. We therefore add some lines of code in the header file CayfAuNStarter:

grafik

In detail, we add the required include header in lines 14-17 and we re-implement the member functions

jvxErrorType process_buffers_icon(jvxSize mt_mask, jvxSize idx_stage)override;
jvxErrorType prepare_connect_icon(JVX_CONNECTION_FEEDBACK_TYPE(fdb)) override;
jvxErrorType postprocess_connect_icon(JVX_CONNECTION_FEEDBACK_TYPE(fdb))override;

The function prepare_connect_icon is called by the processing host whenever processing is about to be started, postprocess_connect_icon is called once processing is over and process_buffers_icon is the function to be called in the buffer-by-buffer processing.

The implementation of these functions can be found in the file CayfAuNStarter.cpp:

grafik

Obviously, the implementation mostly call the library functions provided by our library ayfstarterlib. In the prepare and postprocessing functions, the member functions of the base classes which we override are called explicitely:

jvxErrorType res = AYF_AUDIO_NODE_BASE_CLASS::prepare_connect_icon(JVX_CONNECTION_FEEDBACK_CALL(fdb));

and

jvxErrorType res = AYF_AUDIO_NODE_BASE_CLASS::postprocess_connect_icon(JVX_CONNECTION_FEEDBACK_CALL(fdb));

The process function involves two additional function calls:

Access to the audio data

A function is typically called to get access to the audio data frame-by-frame. It is good idea to use these functions to best support the buffer pipelining in the processing,

jvxData** buffers_in = jvx_process_icon_extract_input_buffers<jvxData>(_common_set_icon.theData_in, idx_stage);
jvxData** buffers_out = jvx_process_icon_extract_output_buffers<jvxData>(_common_set_ocon.theData_out);

The buffer pointers can be used safely until the end of this function.

Forwarding data in the processing chain

At the end of the processing function, the chain must be forwarded to propagate the data from input to output. Therefore, the call

return fwd_process_buffers_icon(mt_mask, idx_stage);

is required to involve the subsequent processing node in the processing chain.

back

Clone this wiki locally