MATLAB Answers

pCompiledNumChannels error in audio plugin generation

7 views (last 30 days)
Pablo Panitta
Pablo Panitta on 18 Oct 2020
Commented: Pablo Panitta on 20 Oct 2020
Hi
I´m trying to use crossoverFilter function as part of a more elaborated signal process plugin, but I find the following error message when I try to generate the audio plugin:
"Failed to compute constant value for nontunable property 'pCompiledNumChannels'. In code generation,nontunable properties can only be assigned constant values".
No issues at all when I run it through audioTestBench, but it does when I try to compile.
The code is really long, but as an example, I reproduce the same with a basic code attached. So, even when this one is not useful at all, I think help to reproduce the error easily.
classdef (StrictDefaults)CrossTest < matlab.System & audioPlugin
% CrossOver plugin test
properties
FCross=100;
end
properties (Constant, Hidden)
% Define the plugin interface
PluginInterface = audioPluginInterface( ...
'InputChannels',2,...
'OutputChannels',2,...
'PluginName','CrossOver Test',...
audioPluginParameter('FCross', ...
'DisplayName', 'Frequency Cutoff', ...
'Mapping', { 'int', 20, 18000}, ...
'Style', 'rotaryknob'))
end
properties (Access = private)
xFilt;
NumCrossovers = 1;
hpf;
pSR;
end
methods
% Constructor
function plugin = CrossTest
fs = getSampleRate(plugin);
plugin.xFilt=crossoverFilter("SampleRate",fs,"NumCrossovers",1,"CrossoverFrequencies",100,"CrossoverSlopes",6);
plugin.hpf=dsp.HighpassFilter('FilterType','IIR','PassbandFrequency',300,'StopbandFrequency',100,'StopbandAttenuation',40); % <<--- Agregado
end
function set.FCross (plugin,val)
plugin.FCross=val;
plugin.crossdesign;
end
end
methods(Access = protected)
%% OUT
function out = stepImpl(plugin, in)
infilt=plugin.hpf(in); % Filter the input signal
[O1,O2]=plugin.xFilt(infilt); % CrossOver the filtered Signal
out=O1+O2;
end
function resetImpl(plugin)
reset(plugin.xFilt);
end
end
methods (Access = private)
function crossdesign(plugin)
plugin.xFilt.CrossoverFrequencies=plugin.FCross;
end
end
end
I would really appreciate if someone give me a hint about how to overcome this.
Thanks
Pablo

  0 Comments

Sign in to comment.

Accepted Answer

jibrahim
jibrahim on 20 Oct 2020
Hi Pablo,
The corssover filter object is complaining that the number of channels is unknown. This is because the code generation compiler interprets the input to the crossover as having a varying 2nd dimension.
Modify the call to your crossover in stepImpl to this:
[O1,O2]=plugin.xFilt(infilt(:,1:2)); % CrossOver the filtered Signal

  3 Comments

Pablo Panitta
Pablo Panitta on 20 Oct 2020
Hi Jilbrahim
Thanks a lot for your prompt an effective answer.
As you said, this solve the problem. However is still not clear to me why we need to do this maneuver, since infilt is well defined at all time (128,2). Is it something related with the way we pass the info to compiler? If I hadn´t applied hp filtered before (e.g and just make a gain change of in), I woudn´t have had the error.
Thanks again!
Pablo
jibrahim
jibrahim on 20 Oct 2020
Hi Pablo,
This is indeed related to the way inputs are defined in the plugin.
When the plugin is generated, the input is set to have variable-size frame length (the number of rows). This is to enable the genenrated plugin for any frame size selected by the user. The number of channels (columns) is fixed, but dsp.HighpassFilter's output will be variable-sized in both dimensions, even though only the first dimension of the input is varsize. This is a limitation of the object.
This can be illustrated by an example.
Consider this function:
function [O1,O2] = foo(x)
fs = 16e3;
xFilt=crossoverFilter("SampleRate",fs,"NumCrossovers",1,"CrossoverFrequencies",100,"CrossoverSlopes",6);
hpf=dsp.HighpassFilter('FilterType','IIR','PassbandFrequency',300,'StopbandFrequency',100,'StopbandAttenuation',40); % <<--- Agregado
infilt=hpf(x); % Filter the input signal
[O1,O2]=xFilt(infilt(:,1:2)); % CrossOver the filtered Signal
Generate code with a varsize input (frame length varies):
x = coder.typeof(0,[1024 2],[1 0]);
codegen foo -args x -report
Hover over the infilt variable, and you will see that it is now varsize in both dimensions (the ':' before the dimension means it is not constant-size):
We can look into seeing if the output of the highpass filter (and other objects) is :1024x2 instead of :1024x:2, but this is why you are seeing this behavior.
Pablo Panitta
Pablo Panitta on 20 Oct 2020
Hi jibrahim
Outsanding explanation! Now I see why pre placing the hpf caused the issue. I didn´t know about the bahaviour of this object, but now is clear!
Thanks a lot!
br
Pablo

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!