How can I create a multi-channel audio plugin in Matlab?
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
jibrahim
2024-4-4
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
0 个评论
更多回答(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!