Index exceeds the number of array elements (480)
Show older comments
Error occurs when attemping to validate the plugin
classdef modDelay < audioPlugin
properties
Depth = 0.004; % Range(0.001,0.007)
Rate = 0.6; % Range(0.1,20)
feedback = 0.5;
end
properties (Access = private)
modDelayLineL = zeros(round(0.01*48000),1);
modDelayLineR = zeros(round(0.01*48000),1);
modIdxL = 1;
modIdxR = 1;
phase = 0;
end
properties (Constant)
end
methods
function out = process(plugin,in)
L = length(in);
out = zeros(L,2);
Fs = getSampleRate(plugin);
T = 1/Fs;
for n = 1:L
modReadIdxL = plugin.modIdxL + round(abs(round(plugin.Depth*Fs)*...
sin(plugin.phase)));
modReadIdxR = plugin.modIdxR + round(abs(round(plugin.Depth*Fs)*...
sin(plugin.phase)));
% Left Channel Read Index
if modReadIdxL > round(0.01*Fs)
modReadIdxL = modReadIdxL - round(0.01*Fs);
end
% Right Channel Read Index
if modReadIdxR > round(0.01*Fs)
modReadIdxR = modReadIdxR - round(0.01*Fs);
end
% Increment the phase of control sinusoid
plugin.phase = plugin.phase + 2*pi*plugin.Rate*T;
% Wrap phase around 2*pi
if(plugin.phase > 2*pi)
plugin.phase = plugin.phase - 2*pi;
end
% Write to Output
out(n,1) = plugin.modDelayLineL(modReadIdxL);
out(n,2) = plugin.modDelayLineR(modReadIdxR);
% Write to Delay Lines
% Left Channel Delay
plugin.modDelayLineL(plugin.modIdxL) = in(n,1) +...
plugin.feedback*plugin.modDelayLineL(modReadIdxL);
% Right Channel Delay
plugin.modDelayLineR(plugin.modIdxR) = in(n,2) +...
plugin.modDelayLineR(modReadIdxR);
% Increment Modulation Index Values
plugin.modIdxL = plugin.modIdxL + 1; % Left Channel
plugin.modIdxR = plugin.modIdxL + 1; % Right Channel
% Wrap Index Values Around to Create a Circular Buffer
% Left Channel
if plugin.modIdxL > round(0.01*Fs)
plugin.modIdxL = 1;
end
% Right Channel
if plugin.modIdxR > round(0.01*Fs)
plugin.modIdxR = 1;
end
end
function reset(plugin)
plugin.modDelayLineL = zeros(round(0.01*48000),1);
plugin.modDelayLineR = zeros(round(0.01*48000),1);
plugin.modIdxL = 1;
plugin.modIdxR = 1;
plugin.phase = 0;
end
end
end
end
4 Comments
KALYAN ACHARJYA
on 1 Dec 2020
Please refer: There are so many common threads with the same issue
https://www.mathworks.com/matlabcentral/answers/441852-index-exceeds-the-number-of-array-elements
Nathanael Channings
on 1 Dec 2020
jibrahim
on 1 Dec 2020
Hi Nathanael,
validateAudioPlugin will run a testbench against your plugin. You can use the keeptestbench option to preserve the testbench m file:
validateAudioPlugin -keeptestbench modDelay
To reproduce the error, just run testbench_modDelay. You can put breakpoints in that file to hopefully give you insight into what is going wrong.
Nathanael Channings
on 1 Dec 2020
Accepted Answer
More Answers (0)
Categories
Find more on Entering Commands 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!