HRTF plugin Filter error
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Pablo Panitta
am 24 Mai 2020
Kommentiert: Pablo Panitta
am 27 Mai 2020
Hi
I´m trying to create a dll based on interporlatedHRTF function. Inside audioTestBench enviroment runs perfect, but when I try to compile it , the following error appears:
"Cannot compute constant value for argument #2 for this System object constructor. All arguments to the constructor of this System object must be constants for code generation....."
Seem is related to dsp.FIRFilter constructor, but I don´t know how to solve the situation. Coeficient must change during the process because location of the source must be able to change according to inputs parameter.
classdef HRTF_test < audioPlugin
properties
Sx=5;
Sy=8;
Rx=5;
Ry=5;
end
properties (Access = private)
azimuth
elevation
Tdata=load('S005_marl_NYU_DATA.mat');
Tposition=load ('S005_marl_NYU_POS.mat');
leftIR=zeros(1,512)
rightIR=zeros(1,512)
leftfilter
rightfilter
end
properties (Constant)
PluginInterface = audioPluginInterface(...
audioPluginParameter('Sx',...
'DisplayName','Position Source X',...
'Mapping',{'lin',0,10},...
'Label','meters'),...
audioPluginParameter('Sy',...
'DisplayName','Position Source Y',...
'Mapping',{'lin',0,10},...
'Label','meters'));
end
methods
function plugin=HRTF_test
needtocalculateAzimuth(plugin);
end
function out = process(plugin, in)
out=[step(plugin.leftfilter,in(:,1)),step(plugin.rightfilter,in(:,2))];
end
function set.Sx(plugin, val)
plugin.Sx = val;
needtocalculateAzimuth(plugin);
end
function set.Sy(plugin,val)
plugin.Sy=val;
needtocalculateAzimuth(plugin);
end
function needtocalculateAzimuth(plugin) % Filter Calculation
if plugin.Sy==5
plugin.azimuth=0;
else
plugin.azimuth=rad2deg(atan((plugin.Sx-plugin.Rx)/(plugin.Sy-plugin.Ry)));
end
plugin.elevation=0;
sourcePosition1 = [plugin.Tposition.dposition(:,1),plugin.Tposition.dposition(:,2)];
desiredPosition = [plugin.azimuth plugin.elevation];
interpolatedIR = interpolateHRTF(plugin.Tdata.Tdata,sourcePosition1,desiredPosition);
plugin.leftIR = squeeze(interpolatedIR(:,1,:))';
plugin.rightIR = squeeze(interpolatedIR(:,2,:))';
plugin.leftfilter=dsp.FIRFilter('Numerator',plugin.leftIR);
plugin.rightfilter=dsp.FIRFilter('Numerator',plugin.rightIR);
end
function reset(plugin)
end
end
end
2 Kommentare
Brian Hemmat
am 25 Mai 2020
Bearbeitet: Brian Hemmat
am 25 Mai 2020
Hello Pablo,
I can't reproduce your plugin because I don't have access to those mat files.
In general, don't construct the dsp.FIRFilter objects in the loop. Contruct and assign the left filter and right filter in the plugin constructor:
function plugin = HRTF_test
needtocalculateAzimuth(plugin);
plugin.leftfilter = dsp.FIRFilter;
plugin.rightfilter = dsp.FIRFilter;
end
In needtocalculateAzimuth, just update the filter numerators. The numerators property is tunable for exactly this use case.
function needtocalculateAzimuth(plugin) % Filter Calculation
...
plugin.leftfilter.Numerator = leftIR;
plugin.rightfilter.Numerator = rightIR;
end
For tips on plugin authoring, including implementing composition, see Tips and Tricks for Plugin Authoring.
HTH,
Brian
Akzeptierte Antwort
Brian Hemmat
am 26 Mai 2020
Hi Pablo,
The following code compiles for me (and should for you). Initialize the Numerator's with the correct size at construction, then call needtocalculateAzimuth to set the values.
classdef HRTF_test < audioPlugin
properties
Sx=5;
Sy=8;
Rx=5;
Ry=5;
end
properties (Access = private)
azimuth
elevation
Tdata = coder.load('S005_marl_NYU_DATA.mat');
Tposition = coder.load ('S005_marl_NYU_POS.mat');
leftfilter
rightfilter
end
properties (Constant)
PluginInterface = audioPluginInterface( ...
audioPluginParameter('Sx', ...
'DisplayName','Position Source X', ...
'Mapping',{'lin',0,10}, ...
'Label','meters'), ...
audioPluginParameter('Sy', ...
'DisplayName','Position Source Y', ...
'Mapping',{'lin',0,10}, ...
'Label','meters'));
end
methods
function plugin = HRTF_test
plugin.leftfilter = dsp.FIRFilter('Numerator',zeros(1,512));
plugin.rightfilter = dsp.FIRFilter('Numerator',zeros(1,512));
needtocalculateAzimuth(plugin)
end
function out = process(plugin, in)
out = [step(plugin.leftfilter,in(:,1)),step(plugin.rightfilter,in(:,2))];
end
function set.Sx(plugin, val)
plugin.Sx = val;
needtocalculateAzimuth(plugin);
end
function set.Sy(plugin,val)
plugin.Sy=val;
needtocalculateAzimuth(plugin);
end
function needtocalculateAzimuth(plugin) % Filter Calculation
if plugin.Sx == 5
plugin.azimuth = 0;
else
plugin.azimuth = rad2deg(atan((plugin.Sx-plugin.Rx)/(plugin.Sy-plugin.Ry)));
end
plugin.elevation = 0;
sourcePosition1 = [plugin.Tposition.dposition(:,1),plugin.Tposition.dposition(:,2)];
desiredPosition = [plugin.azimuth plugin.elevation];
interpolatedIR = interpolateHRTF(plugin.Tdata.Tdata,sourcePosition1,desiredPosition);
leftIR = squeeze(interpolatedIR(:,1,:))';
rightIR = squeeze(interpolatedIR(:,2,:))';
plugin.leftfilter.Numerator = leftIR;
plugin.rightfilter.Numerator = rightIR;
end
function reset(plugin)
reset(plugin.leftfilter)
reset(plugin.rightfilter)
end
end
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Audio Plugin Creation and Hosting finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!