In an Audio Plugin process function, what does 'in' represent?

7 views (last 30 days)
I have read many of the tutorials but I may have missed this detail.
By default 'in' is an array doubles of size 1024x2. I think this represents one sample, or one 'snapshot' in time of audio. Using the AudioTestBench with the code below, I am able to see that process is called every .02 seconds, which indicates a sample rate of 50 Hz, but I am expecting a sample rate of 48000 Hz. If 'in' contains more than one frame, how can I access it??
classdef testPlugin < audioPlugin
properties (Constant)
PluginInterface = audioPluginInterface()
end
methods
function out = process(plugin, in)
toc;
tic;
whos in;
out = zeros(size(in));
end
end
end

Accepted Answer

Charlie DeVane
Charlie DeVane on 13 Dec 2018
in contains one frame (buffer) of audio to be processed.
In your example, in contained 1024 samples (rows) with 2 channels (columns).
The frame size is the number of samples per frame, in this case 1024.
process was called once every 1024/48000 = 0.0213 s to handle one frame of data, so the frame rate was 48000/1024 = 46.8750 Hz.
(This is the meaning of frame as used by MathWorks. Some people use a different definition.)
Just use ordinary indexing to access individual samples. For example, in(7,:) will access all channels of the 7th sample (assuming the frame size is at least 7).
The number of channels (columns) of in is determined by the plugin. By default it is 2 channel. You can change that using the InputChannels argument of audioPluginInterface.
The frame size (rows) is determined by the plugin host. In general a plugin must be designed to handle arbitrary frame sizes. Audio Test Bench typically uses 1024, though you can change that in the settings for whichever input you choose. DAW frame sizes can usually be set by the user, although even then the plugin is not guaranteed to always receive exactly that size.
hope this helps,
Charlie
  1 Comment
Tony Lawrence
Tony Lawrence on 17 Dec 2018
Thanks. I've been able to piece this together since asking, but I'm sure someone else will want to know.

Sign in to comment.

More Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!