Audio Toolbox : Illegal use of reserved keyword "classdef"
34 次查看(过去 30 天)
显示 更早的评论
% Ping Ping Delay Audio Plugin Class
%
% Author: Nathanael Channings
%
% Date: 14/11/20
classdef PingPongDelayPlugin < audioPlugin
% Declare user Controlled Parameters
properties
% Output User Variables
Wet = 0.7;
Dry = 0.5;
GainL = 0.8;
GainR = 0.8;
% Delay User Variables
delayType = 2; % 1(Straight)
% 2(pingPong)
leftDelay = 0.3; % Delay Value of the Right Channel
rightDelay = 0.5; % Delay Value of the Right Channel
feedback = 0.7; % Feedback Value for Both Channels
% Distortion User Variable
% Modulation User Variables
% Reverb User Variables
end
% Declare Private Plugin Parameters
properties (Access = private)
% Delay Variables
sDelayL = round(leftDelay*getSampleRate(plugin));
sDelayR = round(rightDelay*getSampleRate(plugin));
delayLineLeft = zeros(sDelayL,1);
delayLineRight = zeros(sDelayR,1);
dIdxL = 1;
dIdxR = 1;
% Filter Variables
% Distortion Variables
% Modulation Variables
end
% Design Plugin GUI
properties (Constant)
PluginInterface = audioPluginInterface(...
audioPluginParameter('delayType','DisplayName','Delay Type','Style','rotaryknob','Mapping',{'int',1,3}),...
audioPluginParameter('leftDelay','DisplayName','Left Delay','Style','rotaryKnob','Mapping',{'lin',0,2}),...
audioPluginParameter('rightDelay','DisplayName','Right Delay','Style','rotaryKnob','Mapping',{'lin',0,2})...
);
end
% This is Where Your DSP Lives
methods
function out = process(plugin,in)
% Define the I/O Buffer Length
L = max(size(in));
out = zeros(L,2); % Output Array
d = zeros(N,2); % Distortion Array
m = zeros(N,2); % Modulated Array
% Create a Main Time Loop with the length of the buffer
for n = 1:L
% Define the Output
out(n,1) = plugin.Dry*in(n,1) + plugin.Wet*plugin.delayLineLeft(plugin.dIdxL);
out(n,2) = plugin.Dry*in(n,2) + plugin.Wet*plugin.delayLineRight(plugin.dIdxR);
% Write Samples to the Delay Lines
if plugin.delayType == 1
tempL = plugin.feedback*plugin.delayLineLeft(plugin.dIdxL);
tempR = plugin.feedback*plugin.delayLineRight(plugin.dIdxR);
plugin.delayLineLeft(plugin.dIdxL) = tempL;
plugin.delayLineRight(plugin.dIdxR) = tempR;
else if plugin.delayType == 2
tempL = plugin.feedback*plugin.delayLineLeft(plugin.dIdxL);
tempR = plugin.feedback*plugin.delayLineRight(plugin.dIdxR);
plugin.delayLineLeft(plugin.dIdxL) = tempR;
plugin.delayLineRight(plugin.dIdxR) = tempL;
end
end
% Iterate Through Each Delay Line Index
plugin.dIdxL = plugin.dIdxL + 1;
if plugin.dIdxL > plugin.sDelayL
plugin.dIdxL = 1;
end
plugin.dIdxR = plugin.dIdxR + 1;
if plugin.dIdxR > plugin.sDelayR
plugin.dIdxR = 1;
end
end % End of for Loop
end % End of Function
end % End of Methods
end % End of Class
4 个评论
回答(2 个)
Steven Lord
2020-11-15
To use a class file you don't run the classdef file directly. You construct the object by calling the constructor (the function with the same name as the file) with the appropriate inputs. Because this classdef file does not contain an explicit constructor function, you'd call the default constructor that accepts no inputs.
myobj = PingPongDelayPlugin
Now you can call various functions on myobj.
Walter Roberson
2020-11-15
编辑:Walter Roberson
2020-11-15
If you define a constant property then when you use the property to initialize other properties you must qualify with the class name.
https://www.mathworks.com/help/matlab/matlab_oop/expressions-in-class-definitions.html
Properties not declared as Constant or enumeration are considered variables and cannot be referenced directly in constructing default values. Instead you need to define a method that will be executed when the object is constructed. constants and enumerations are assigned when the class is constructed.
Remember that when you do not declare leftDelay constant then you are declaring that the user can change the value, and when you do that then which of the values should be used to construct new objects?
It is valid to construct a constant property to initialize with, and also to declare a variable property as the current value for any given object.
https://www.mathworks.com/help/matlab/matlab_oop/specifying-properties.html#brqy3km-10
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!