MATLAB Answers

HRTF plugin Filter error

2 ビュー (過去 30 日間)
Pablo Panitta
Pablo Panitta 2020 年 5 月 24 日
コメント済み: Pablo Panitta 2020 年 5 月 27 日
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 件のコメント

Brian Hemmat
Brian Hemmat 2020 年 5 月 25 日
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.
For examples of plugins (use they to find coding patterns), see Audio Plugin Example Gallery.
HTH,
Brian
Pablo Panitta
Pablo Panitta 2020 年 5 月 26 日
Hi Brian, thanks a lot for your feedback.
The issue I´m experiencing with this solution is the following :
If I enter to function out with the default position(Sx=5 , Rx=5), the filter is built with default numerator [0.5 0.5]. This is weird because we´re forcing to construct with leftIR & rightIR [1x 512] through "needtocalculateAzimuth" instruction in function plugin. Numerators are correctly calculated [1x512) but for some reason the filter system object doesn´t take them for the initial construction.
Then, when I try to change the position inside the out function loop, off course an error message appears stating the dimension cannot be changed during execution (from [1x2] to [1x512])
If,before enter into function out loop, I change the defalut position to something else, the filter is updated and built with the adequate dimension [1x 512].
I dont´know why this is happening, becuase in both scenarios the same process through needtocalculateAzimuth is follow.
Leave the new lines & .mat files in case you want to try yourself and kindl help me.
Once I solve this issue, I´ll be able to test the .dll compilation.
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');
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);
plugin.leftfilter = dsp.FIRFilter;
plugin.rightfilter = dsp.FIRFilter;
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
Thanks
Pablo

Sign in to comment.

採用された回答

Brian Hemmat
Brian Hemmat 2020 年 5 月 26 日
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

  1 件のコメント

Pablo Panitta
Pablo Panitta 2020 年 5 月 27 日
Perfect! Thanks Brian!

Sign in to comment.

その他の回答 (0 件)

製品


リリース

R2019b

Translated by