Convolution Reverb audio plugin

조회 수: 25 (최근 30일)
Lorenzo Lellini
Lorenzo Lellini 2021년 6월 9일
댓글: Lorenzo Lellini 2021년 6월 12일
Hello.
My idea is to create a simple convolution reverb audio plugin. I have chosen a nice Impulse response and I wrote a function script. It works and I would convert the function script in an audio plugin. For the moment I'm working with mono audio, but I will convert to stereo.
My only problem is that I have to specify also the Impulse Response as input in the function. I would find a way to "store" the IR (or more than one IR) inside the function in order to give only the audio and the parameters as input.
The IR is a too long vector and I can't explicitly write in the function code, I actually have it as a variable.
Have you any idea?
function y = ConvReverb(IR, Audio_Input, Input_Gain, Output_Gain, DryWet)
% Input and Output gain between 0 and 1. If you put 1 the volume is not
% affected
%
% Dry/Wet percentage between 0 and 1
%
% "length(IR)+length(Audio_Input)-1" is the conv length between x and h
x = Input_Gain*Audio_Input;
d = DryWet;
wet = d*x;
dry = (1-d)*x;
H = fft(IR, length(IR)+length(Audio_Input)-1);
DRY = fft(dry, length(IR)+length(Audio_Input)-1);
WET = fft(wet, length(IR)+length(Audio_Input)-1);
Y=H.*WET+DRY;
y_time = ifft(Y);
y = Output_Gain*y_time;
end

채택된 답변

Brian Hemmat
Brian Hemmat 2021년 6월 9일
Hi Lorenzo,
My understanding is that you are developing a function but eventually want to convert it to an audioPlugin object. In that case:
Take a look at the pattern in audiopluginexample.FastConvolver. It defines a property to hold the impulse response. In general, the plugins in the plugin gallery cover a number of common patterns:
Best,
Brian

추가 답변 (1개)

Lorenzo Lellini
Lorenzo Lellini 2021년 6월 11일
Hi Brian and thank you for your answer.
I have seen the FastConvolver and dsp.FrequencyDomainFIRFilter is what I need.
I made some tests with this object in a normal script and it works: I obtain a reverbered signals using an known impulse response.
When I convert the script into a simple plugin (I create a really simply plugin structure) it doesn't work. I had some tests on audioTestBench and I can't hear the reverbered sound when I change the dry/wet level. It is like the filter doesn't work. What is wrong?
Moreover, I have seen that dsp.FrequencyDomainFIRFilter requires a ROW VECTOR as input. In this way I have to load a mono Impulse Response and I have to transpose it because it is a column vector. Is there a way to fix it and use stereo IRs?
I'm sorry if they are quite silly questions but It is my first experience with MATLAB plugins and filter objects.
Thank you.
classdef ConvReverbPlugin < audioPlugin
properties
% PROPERTIES THAT CAN BE MODIFIED FROM THE USER.
DryWet = 0.5;
Output_Gain = 1;
end
properties (Access = private)
% PROPERTIES NOT VISIBLE TO THE USER.
% MONO IR (it is a column vector)
IR = audioread('IR_Dataset/IR_Reverb.wav'); % MONO IR
end
properties (Constant)
% USER INTERFACE SECTION.
PluginInterface = audioPluginInterface(...
audioPluginParameter('DryWet', ...
'DisplayName','Dry/Wet', ...
'Mapping', {'lin',0,1}), ...
audioPluginParameter('Output_Gain', ...
'DisplayName','Output Volume','Mapping', {'lin',0,1}))
end
methods
function out = process(plugin, in)
% PLUGIN PROCESSING
d = plugin.DryWet;
wet = d*in;
dry = (1-d)*in;
% I have to use the transposition ' on plugin.IR because dsp.FrequencyDomainFIRFilter
% takes ONLY row vectors as input.
filter = dsp.FrequencyDomainFIRFilter('Numerator', plugin.IR', ...
'PartitionForReducedLatency', true, 'PartitionLength', 10240);
y=filter(wet);
out = (dry + y) * plugin.Output_Gain;
end
end
end
  댓글 수: 2
Brian Hemmat
Brian Hemmat 2021년 6월 11일
Hi Lorenzo,
Regarding why you're not hearing anything: You are creating the filter and using it in the process method. This means every time its called, the filter has no prior state. Instead, you need to create the filter during construction. Here is your code updated:
classdef ConvReverbPlugin < audioPlugin
properties
% PROPERTIES THAT CAN BE MODIFIED FROM THE USER.
DryWet = 0.5;
Output_Gain = 1;
end
properties (Access = private)
% PROPERTIES NOT VISIBLE TO THE USER.
% MONO IR (it is a column vector)
IR = audioread('ChurchImpulseResponse-16-44p1-mono-5secs.wav').'; % <<<< TRANSPOSE TO ROW VECTOR
Filter % <<<< CREATE PROPERTY TO HOLD FILTER.
end
properties (Constant)
% USER INTERFACE SECTION.
PluginInterface = audioPluginInterface(...
audioPluginParameter('DryWet', ...
'DisplayName','Dry/Wet', ...
'Mapping', {'lin',0,1}), ...
audioPluginParameter('Output_Gain', ...
'DisplayName','Output Volume','Mapping', {'lin',0,1}))
end
methods
function plugin = ConvReverbPlugin()
% CONSTRUCTOR - Create the filter once.
plugin.Filter = dsp.FrequencyDomainFIRFilter('Numerator', plugin.IR, ... %<<<
'PartitionForReducedLatency', true, 'PartitionLength', 10240); %<<<
end
function out = process(plugin, in)
% PLUGIN PROCESSING
d = plugin.DryWet;
wet = d*in;
dry = (1-d)*in;
y = plugin.Filter(wet); % <<< USE THE FILTER
out = (dry + y) * plugin.Output_Gain;
end
end
end
Regarding row vector impulse response: Just convert the impulse response to a row vector when its defined in the property. The example code above does this.
Regarding stereo convolution: Do you mean you want two separate impulse responses for the two channels? If so, create two filters and filter each channel separately. If both channels use the same impulse response, then the example code works for that. It will filter the channels independently.
Best,
Brian
Lorenzo Lellini
Lorenzo Lellini 2021년 6월 12일
Thank you for your answer, it is now clear!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Audio Plugin Creation and Hosting에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by