How can I preserve variable names in C++ code generated by 'generateAudioPlugin -juceproject'

5 views (last 30 days)
I am generating C++ code from my audio plugin using 'generateAudioPlugin -juceproject'. Unfortunatelly, variable names in the C++ code often do not correspond the variable names in MATLAB code due to memory usage optimizations. How can I force 'generateAudioPlugin' to keep variable names consistent between MATLAB code and C++ code?
If I was working directly with 'codegen', I could pass 'coder.CodeConfig' object with property 'PreserveVariableNames' set to 'UserNames', however, I cannot find an option to pass this object to 'generateAudioPlugin'.
Any help will be appreciated!
  2 Comments
Jimmy Lapierre
Jimmy Lapierre on 14 Nov 2022
There is no option to do this now. If you can share a simple enough example where it would make sense, we could look into it further and consider making this an option or change the current behavior.
Arkadiusz Lewandowski
Arkadiusz Lewandowski on 25 Nov 2022
Thanks for your reply!
Below is a very simple plugin code and an excerpt from the C++ code generated by 'generateAudioPlugin -juceproject'. As you can see some of the variable names are preserved ('Gain'), but the names of loop indices are not.
This is of course a very simple example and you can readily follow the MATLAB code along with the C++ code. However, I am working on a much more complicated piece of code, and when trying to do some tweeks in the C++ code, it becomes difficult to catch how it correponds to the MATLAB code. To make it harder, sometimes variables are reused to save memory and their names --- used in a different context --- do not make sense and cause some confusion. Thus, it would be very useful to be able to preserve the original MATLAB variable names in the generated C++ code.
---
MATLAB code:
classdef TestPlugin < audioPlugin
properties
Gain = 0.5;
end
properties (Constant)
PluginInterface = audioPluginInterface(...
audioPluginParameter('Gain',...
'DisplayName','Gain',...
'Mapping',{'lin',0,1}))
end
methods
function out = process(plugin, in)
out=TestPlugin.applyGain(in, plugin.Gain);
end
function set.Gain(plugin, val)
plugin.Gain = val;
end
end
methods(Static)
function out=applyGain(in, Gain)
coder.inline('never')
out=zeros(size(in));
numSamples=size(in,1);
for foo=1:numSamples
out(foo,1)=Gain*in(foo,1);
end
for bar=1:numSamples
out(bar,2)=Gain*in(bar,2);
end
end
end
end
Part of C++ code:
void TestPlugin::applyGain(const coder::array<double, 2U> &in, double Gain, coder::array<double, 2U> &out)
{
int i;
int loop_ub;
out.set_size(static_cast<int>(static_cast<short>(in.size(0))), 2);
loop_ub = static_cast<short>(in.size(0)) << 1;
for (i = 0; i < loop_ub; i++) {
out[i] = 0.0;
}
i = in.size(0);
for (loop_ub = 0; loop_ub < i; loop_ub++) {
out[loop_ub] = Gain * in[loop_ub];
}
i = in.size(0);
for (loop_ub = 0; loop_ub < i; loop_ub++) {
out[loop_ub + out.size(0)] = Gain * in[loop_ub + in.size(0)];
}
}

Sign in to comment.

Answers (0)

Categories

Find more on Code Generation and Deployment in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!