How can I create a multi-channel audio plugin in Matlab?

11 views (last 30 days)
I have created a simple VST3 Dither plugin in Matlab (generateAudioPlugin). it creates noise and adds it to the input signal.
But, this plugin only works in stereo. i want it to be channel agnostic, so it adapts to my DAW. mono, stereo, 6-ch and so on...
classdef DitherPlugin < audioPlugin
properties
ditherOn = true;
bitDepth = '24-bit';
ditherType = 'Triangular';
end
properties (Constant)
lsbValue16bit = 1/2^15
lsbValue24bit = 1/2^23
PluginInterface = audioPluginInterface( ...
audioPluginParameter('ditherOn', ...
'DisplayName', 'TPDF Dither On/Off', ...
'Mapping', {'enum', 'Off', 'On'}), ...
audioPluginParameter('bitDepth', ...
'DisplayName', 'Bit Depth', ...
'Mapping', {'enum', '16-bit', '24-bit'}, ...
'Style', 'dropdown'), ...
audioPluginParameter('ditherType', ...
'DisplayName', 'Dither Type', ...
'Mapping', {'enum', 'Triangular', 'Noise Shaped Dither'}, ...
'Style', 'dropdown'))
end
methods
function set.bitDepth(plugin, depth)
validDepths = {'16-bit', '24-bit'};
if any(strcmp(depth, validDepths))
plugin.bitDepth = depth;
else
error('Invalid Bit Depth. Valid options are: %s.', strjoin(validDepths, ', '));
end
end
function set.ditherType(plugin, type)
validTypes = {'Triangular', 'Noise Shaped Dither'};
if any(strcmp(type, validTypes))
plugin.ditherType = type;
else
error('Invalid type. Valid options are: %s.', strjoin(validTypes, ', '));
end
end
function set.ditherOn(plugin, value)
if islogical(value)
plugin.ditherOn = value;
else
error('Invalid value for ditherOn. Value must be true or false.');
end
end
function out = process(plugin, in)
if plugin.ditherOn
switch plugin.bitDepth
case '16-bit'
lsbValue = DitherPlugin.lsbValue16bit;
case '24-bit'
lsbValue = DitherPlugin.lsbValue24bit;
otherwise
error('Unknown bit depth setting: %s', plugin.bitDepth);
end
% Create and apply dither based on the selected dither type
switch plugin.ditherType
case 'Triangular'
% Create flat dither noise
%implementation...
case 'Noise Shaped Dither'
% implementation
%ditherNoise = ...
otherwise
error('Unknown dither type setting: %s', plugin.ditherType);
end
%quantize
out = round((in + ditherNoise) / lsbValue) * lsbValue;
else
% If dither is not enabled, pass the signal through unaffected
out = in;
end
end
end
end

Accepted Answer

jibrahim
jibrahim on 4 Apr 2024
Hi Hasan,
The audio plugin interface allows you to specify the desired numbers of input and output channels. I beleive the default is stereo.
For example, for a plugin with 6 input and output channels:
classdef myPlugin < audioPlugin
properties (Constant)
PluginInterface = audioPluginInterface( ...
'InputChannels',6, ...
'OutputChannels',6);
end
methods
function y= process(~,x)
y = x;
end
end
end
Note that the number of channels is not dynamic, so you would have to specify the maximum number of channels you need.
generateAudioPlugin myPlugin % generate the plugin
p = loadAudioPlugin('myPlugin.dll');
out = process(p,randn(256,6)); % Six input channels. You can just use zeros for channels you are not interested in

More Answers (0)

Categories

Find more on Audio Plugin Creation and Hosting in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!