How can I create a multi-channel audio plugin in Matlab?
Show older comments
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
More Answers (0)
Categories
Find more on Audio Plugin Creation and Hosting in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!