Stereo VST Prototype in Matlab

Introduction

The stereo is general techniques in audio field today with the distribution of a sound signal into two channel or multi-channel by a pan control setting.  So I prototype the panning in frequency domain with filters in Matlab platform and convert it to VST plugin. All the code consists of three portions: filtering the corresponding frequency out of original spectrum and panning the left and right channel to generate the stereo effect. 

Object-Oriented Programming in Matlab

The audio plugin need be programmed with the Object-Oriented in Matlab, if you need more details, you can check the reference:https://www.mathworks.com/help/audio/audio-plugin-creation-and-hosting.html
I design my plugin structure as the below.

classdef Name < matlab.System & audioPlugin
properties

end
methods
constructor

end
function

end
end
methods (Access=protected)
function Out=stepImpl(obj,in)

end
function resetImpl(obj)

end
function processTunedPropertiesImpl(obj)

end
end
methods (Access = private)
function 

end
end

Design Filter

I need take out the corresponding frequency from my spectrum to the next panning control, for which I need design my filter. Here I choose a high pass filter and a low pass filter to split the spectrum to two parts, such that I can increase the gain in two portion separately. If necessary, it can replace it with more complex filter design like equalizer and band pass filter for more critical manipulation in frequency domain. I program the desired filter in the method (Access=private) position.  

methods (Access = private)
function lowPassCoeffs(p)
w0 = 2*pi*p.Cutoff/getSampleRate(p); % Angular Freq. (Radians/sample)
alpha = sin(w0)/(2*10^(p.Q1/20)); % Filter Width
norm=1/(1 + alpha);
p.Num1 = (1 – cos(w0))*norm * [.5;1;.5];
p.Den1 = [-2*cos(w0)*norm; (1 – alpha)*norm];
end

function highPassCoeffs(p)
% Function to compute filter coefficients
w0 = 2*pi*p.Cutoff/getSampleRate(p);
alpha = sin(w0)/(2*10^(p.Q2/20));
norm = 1/(1+alpha);
p.Num2 = (1 +cos(w0))*norm * [.5;-1;.5];
p.Den2 = [-2*cos(w0)*norm; (1 – alpha)*norm];
end

Q is the gain of the filter.

I use freqz command to check my filter, and it suits for my plan. Like the below figure.

low pass filter and high pass filter

Panning Control in two Channel

Panning distribute the variant sound in two channels to construct the psychological stereo. Generally, it can be applied by sound volume and different shape of spectrum. Here I directly use the vector, containing sin and cos, to create different gains for left and right channels. If needed, it can apply the above filters repeatedly to different channels to manufacture multifarious combination of spectrum in left and right.

\(\left[ \begin{matrix} left \\ right \end{matrix} \right] =\left[ \begin{matrix} \cos { \theta } *left \\ \sin { \theta *right } \end{matrix} \right] \)

Full Matlab code link and  VST code link

Extension

There is still a lot of space to extend the code in different aspects. You can use equalizer command (designParamEQ ) to cause it more flexibility. Here I only add stochastic  angular for sinusoid function to make it more sense to ordinary people. So it rises up the interesting topic that it can become more friendly in the future by introducing the machine learning to adjust the sound volume in left and right channels.