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

조회 수: 5 (최근 30일)
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
Jimmy Lapierre
Jimmy Lapierre 2022년 11월 14일
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 2022년 11월 25일
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)];
}
}

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Code Generation and Deployment에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by