How to store a matrix of impulse responses in a plugin? (re: Failed to compute constant value for nontunable property)
Show older comments
I'm trying a build a convolver plugin that will cycle through many impulse responses. I started with the audiopluginexample.FastConvolver plugin from the Audio Plugin Example Gallery. I modified it to read in a long array of concatentated impulse responses and then split them out into a matrix to read them more easily.
When I run it in audioTestBench it works fine. When I attempt to run validateAudioPlugin I get this error:
Checking plugin class 'ggConvolv'... passed.
Generating testbench file 'testbench_ggConvolv.m'... done.
Running testbench... passed.
Generating mex file 'testbench_ggConvolv_mex.mexmaci64'... Failed to compute constant value for nontunable property 'tdiMatrix'. In code generation, nontunable properties can only be assigned constant values.
Error in ==> ggConvolv Line: 38 Column: 13
Code generation failed: View Error Report
Error using coder.internal.generateAudioPlugin
Error in validateAudioPlugin
I don't understand the issue. tdiMatrix is a constant value, right?
Of course, I immediately tried simply making tdiMatrix tunable, which just produced another error:
Checking plugin class 'ggConvolv'... passed.
Generating testbench file 'testbench_ggConvolv.m'... done.
Running testbench... passed.
Generating mex file 'testbench_ggConvolv_mex.mexmaci64'... Failed to compute constant value for nontunable property 'pNumPartitions'. In code generation, nontunable properties can only be assigned constant values.
Error in ==> ggConvolv Line: 46 Column: 13
Code generation failed: View Error Report
Error using coder.internal.generateAudioPlugin
Error in validateAudioPlugin
Here is the current state of the plugin code:
classdef (StrictDefaults)ggConvolv < audioPlugin & matlab.System
properties(Nontunable)
concatenatedTdis44 = audioread('concatenatedTdis44.wav')';
concatenatedTdis48 = audioread('concatenatedTdis48.wav')';
PartitionSize = 1024;
end
properties (Constant, Hidden)
PluginInterface = audioPluginInterface(...
'InputChannels',1,...
'OutputChannels',1,...
'PluginName','GainGuardian'...
);
end
properties(Access = private, Nontunable)
pFIR
tdiMatrix
currentTDIIndex = 1;
sampleCounter = 0;
switchSamples % Number of samples to wait before switching
Fs
N
end
methods(Access = protected)
function setupImpl(plugin, u)
plugin.Fs = getSampleRate(plugin);
plugin.N = plugin.Fs / 3;
if plugin.Fs == 44100
concatenatedTdis = plugin.concatenatedTdis44;
elseif plugin.Fs == 48000
concatenatedTdis = plugin.concatenatedTdis48;
end
totalTdis = length(concatenatedTdis) / plugin.N;
plugin.tdiMatrix = reshape(concatenatedTdis, plugin.N, totalTdis)';
firstTdi = plugin.tdiMatrix(1,:);
plugin.pFIR = dsp.FrequencyDomainFIRFilter('Numerator', firstTdi, ...
'PartitionForReducedLatency', true, 'PartitionLength', plugin.PartitionSize);
setup(plugin.pFIR, u);
plugin.switchSamples = floor(11e-3 * getSampleRate(plugin)); % 11 milliseconds
plugin.sampleCounter = 0;
plugin.currentTDIIndex = 1;
end
function y = stepImpl(plugin,u)
plugin.sampleCounter = plugin.sampleCounter + size(u,1);
if plugin.sampleCounter >= plugin.switchSamples
plugin.sampleCounter = mod(plugin.sampleCounter, plugin.switchSamples);
plugin.currentTDIIndex = mod(plugin.currentTDIIndex, size(plugin.tdiMatrix, 1)) + 1;
plugin.pFIR.Numerator = plugin.tdiMatrix(plugin.currentTDIIndex, :);
end
y = step(plugin.pFIR,u);
end
function resetImpl(plugin)
reset(plugin.pFIR);
setLatencyInSamples(plugin, plugin.PartitionSize);
end
function flag = isInputSizeMutableImpl(~,~)
flag = true;
end
function s = saveObjectImpl(obj)
s = saveObjectImpl@matlab.System(obj);
s = savePluginProps(obj,s);
if isLocked(obj)
s.pFIR = matlab.System.saveObject(obj.pFIR);
end
end
function loadObjectImpl(obj, s, wasLocked)
if wasLocked
obj.pFIR = matlab.System.loadObject(s.pFIR);
end
loadObjectImpl@matlab.System(obj,s,wasLocked);
reload(obj,s);
end
%------------------------------------------------------------------
% Propagators
function varargout = isOutputComplexImpl(~)
varargout{1} = false;
end
function varargout = getOutputSizeImpl(obj)
varargout{1} = propagatedInputSize(obj, 1);
end
function varargout = getOutputDataTypeImpl(obj)
varargout{1} = propagatedInputDataType(obj, 1);
end
function varargout = isOutputFixedSizeImpl(obj)
varargout{1} = propagatedInputFixedSize(obj,1);
end
end
end
4 Comments
Nathan Lively
on 26 Feb 2024
Nathan Lively
on 26 Feb 2024
Nathan Lively
on 26 Feb 2024
Nathan Lively
on 26 Feb 2024
Accepted Answer
More Answers (0)
Categories
Find more on Audio Plugin Creation and Hosting in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!