MATLAB Answers

Convolution Reverb audio plugin

31 views (last 30 days)
Lorenzo Lellini
Lorenzo Lellini on 9 Jun 2021
Commented: Lorenzo Lellini on 12 Jun 2021
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

Answers (2)

Brian Hemmat
Brian Hemmat on 9 Jun 2021
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

Lorenzo Lellini
Lorenzo Lellini on 11 Jun 2021
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 Comments
Lorenzo Lellini
Lorenzo Lellini on 12 Jun 2021
Thank you for your answer, it is now clear!

Sign in to comment.

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!