Is it posible to set 2 inputs in audio plugin?
2 次查看(过去 30 天)
显示 更早的评论
I am designing a spectral subtracter to evaluate losses in perceptual audio coding, which consists in a plugin that compares the audio spectrum of two signals, the original and the compressed one. The thing is that i want to develop this code as an audio plugin but i am having some troubles to set two different inputs in my plugin, as the process function only has one in, right? Is there any way of adding another extra input? Or any idea to avoid having this problem?
Thank you.
0 个评论
采纳的回答
jibrahim
2023-5-5
编辑:jibrahim
2023-5-5
Hi David,
It is possible to design plugins with more than one input. Here is a simple example:
classdef myPlugin < audioPlugin
properties (Constant)
PluginInterface = audioPluginInterface( ...
audioPluginParameter('scale','DisplayName','Scale','Label','','Mapping',{'lin',0,1}),...
'InputChannels',[2 2], ...
'PluginName','myPlugin' ...
)
end
properties
scale = .1
end
methods
function y = process(obj,x1,x2)
y = obj.scale*x1+x2;
end
end
end
Validation and generation of the plugin should work:
validateAudioPlugin myPlugin
generateAudioPlugin myPlugin
If you were to use the generated plugin in MATLAB, you would have to concatenate the two inputs. For example:
hostedPlugin = loadAudioPlugin("myPlugin.dll")
y = process(hostedPlugin,randn(1024,4));
4 个评论
Gabriele Bunkheila
2023-5-11
编辑:Gabriele Bunkheila
2023-5-11
Hi David,
I wasn't sure what you meant with your latest question but I'll try a couple of ideas to help us identify exactly what you are after.
From your MATLAB code (e.g. an edited version of the code generated byAudio Test Bench), you could use a file-selection utility such as uigetfile with 'MultiSelect','on'. Then read both separately with two different dsp.AudioDeviceReader objects. In the loop, read the samples from both objects separately in the loop and feed the frames of samples read by each as inputs to your plugin within the streaming loop.
dir = fullfile(matlabroot,'toolbox','audio','samples');
filenames = uigetfile({'*.mp3;*.wav'}, [], dir,'MultiSelect','on');
% Create test bench input and output
fileReader1 = dsp.AudioFileReader('Filename',filenames{1}, 'PlayCount',10);
fileReader2 = dsp.AudioFileReader('Filename',filenames{2}, 'PlayCount',10);
assert(isequal(fileReader1.SampleRate,fileReader2.SampleRate))
player = audioDeviceWriter(fileReader1.SampleRate);
% Create the objects under test
sut1 = myPlugin;
setSampleRate(sut1,fileReader1.SampleRate);
% Open parameter tuners for interactive tuning during simulation
tuner1 = parameterTuner(sut1);
drawnow
% Stream processing loop
while ~isDone(fileReader1) && ~isDone(fileReader2)
% Read from input, process, and write to output
in1 = fileReader1();
in2 = fileReader2();
out1 = process(sut1,in1,in2);
player(sum(out1,2))
% Process parameterTuner callbacks
drawnow limitrate
end
% Clean up
release(fileReader1)
release(fileReader2)
Note that file reading always takes place outside the boundaries. The code outside the plugin here needs to care cared of some of the tasks normally taken care of by a DAW, e.g. ensuring the two sample rates match, and that samples are always availability from both files.
If you prefer a workflow fully based on interactive Apps, you could also turn your MATLAB plugin into a binary VST or AU plugin (from Audio Test Bench or via generateAudioPlugin), then use it from your DAW of choice, and handle file selection and signal routing directly from the DAW.
I hope this helps.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio Plugin Creation and Hosting 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!