-
Notifications
You must be signed in to change notification settings - Fork 2
/
PhasorRT.m
157 lines (122 loc) · 5.06 KB
/
PhasorRT.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
classdef PhasorRT < audioPlugin
properties
Freq1 = 1
Freq2 = 1
Freq3 = 1
Freq4 = 1
R1 = .1
R2 = .1
R3 = .1
R4 = .1
Mix = 0.5
end
properties (Dependent)
end
properties
end
properties (Constant)
% audioPluginInterface manages the number of input/output channels
% and uses audioPluginParameter to generate plugin UI parameters.
PluginInterface = audioPluginInterface(...
audioPluginParameter('Freq1','DisplayName','Freq1','Label','','Mapping',{'lin',0.1 10}),...
audioPluginParameter('Freq2','DisplayName','Freq2','Label','','Mapping',{'lin',0.1 10}),...
audioPluginParameter('Freq3','DisplayName','Freq3','Label','','Mapping',{'lin',0.1 10}),...
audioPluginParameter('Freq4','DisplayName','Freq4','Label','','Mapping',{'lin',0.1 10}),...
audioPluginParameter('R1','DisplayName','R1','Label','','Mapping',{'lin',0 1}),...
audioPluginParameter('R2','DisplayName','R2','Label','','Mapping',{'lin',0 1}),...
audioPluginParameter('R3','DisplayName','R3','Label','','Mapping',{'lin',0 1}),...
audioPluginParameter('R4','DisplayName','R4','Label','','Mapping',{'lin',0 1}),...
audioPluginParameter('Mix','DisplayName','Dry/Wet','Label','%','Mapping',{'lin',0 1}));
end
properties (Access = private)
pSR
AP1 = [0, 0, 0];
AP2 = [0, 0, 0];
AP3 = [0, 0, 0];
AP4 = [0, 0, 0];
xn1 = 0;
xn2 = 0;
theta1
theta2
theta3
theta4
end
methods
function obj = PhasorRT()
obj.pSR = getSampleRate(obj);
obj.theta1 = 0;
obj.theta2 = 0;
obj.theta3 = 0;
obj.theta4 = 0;
% obj.theta1 = obj.Freq1*2*pi/obj.pSR;
% obj.theta2 = obj.Freq2*2*pi/obj.pSR;
%
% obj.theta3 = obj.Freq3*2*pi/obj.pSR;
%
% obj.theta4 = obj.Freq4*2*pi/obj.pSR;
end
function reset(obj)
obj.pSR = getSampleRate(obj);
end
function out = process(obj, x)
[m,n]=size(x);
y = zeros(size(x));
delta1 = (obj.Freq1*2*pi/obj.pSR);
delta2 = (obj.Freq2*2*pi/obj.pSR);
delta3 = (obj.Freq3*2*pi/obj.pSR);
delta4 = (obj.Freq4*2*pi/obj.pSR);
a21 = obj.R1^2;
a22 = obj.R2^2;
a23 = obj.R3^2;
a24 = obj.R4^2;
for i=1:m
obj.theta1 = obj.theta1 + delta1;
if obj.theta1 > 2*pi
obj.theta1 = obj.theta1 - 2*pi;
end
obj.theta2 = obj.theta2 + delta2;
if obj.theta2 > 2*pi
obj.theta2 = obj.theta2 - 2*pi;
end
obj.theta3 = obj.theta3 + delta3;
if obj.theta3 > 2*pi
obj.theta3 = obj.theta3 - 2*pi;
end
obj.theta4 = obj.theta4 + delta4;
if obj.theta4 > 2*pi
obj.theta4 = obj.theta4 - 2*pi;
end
a11 = -2*obj.R1*cos(obj.theta1);
a12 = -2*obj.R2*cos(obj.theta2);
a13 = -2*obj.R3*cos(obj.theta3);
a14 = -2*obj.R4*cos(obj.theta4);
% first allpas
obj.AP1(1) = a21 * x(i,1) + a11 * obj.xn1 + obj.xn2 - a11 * obj.AP1(2) - a21 * obj.AP1(3);
% second allpas
obj.AP2(1) = a22 * obj.AP1(1)+ a12 * obj.AP1(2) + obj.AP1(3) - a12 * obj.AP2(2) - a22 * obj.AP2(3);
% third allpass
obj.AP3(1) = a23 * obj.AP2(1)+ a13 * obj.AP2(2) + obj.AP2(3) - a13 * obj.AP3(2) - a23 * obj.AP3(3);
% fourth allpass
obj.AP4(1) = a24 * obj.AP3(1)+ a14 * obj.AP3(2) + obj.AP3(3) - a14 * obj.AP4(2) - a24 * obj.AP4(3);
% signal
obj.xn2 = obj.xn1;
obj.xn1 = x(i,1);
% first allpass
obj.AP1(3) = obj.AP1(2);
obj.AP1(2) = obj.AP1(1);
% second allpass
obj.AP2(3) = obj.AP2(2);
obj.AP2(2) = obj.AP2(1);
% third allpass
obj.AP3(3) = obj.AP3(2);
obj.AP3(2) = obj.AP3(1);
% fourth allpass
obj.AP4(3) = obj.AP4(2);
obj.AP4(2) = obj.AP4(1);
y(i,:) = obj.AP4(1);
end
wet = obj.Mix;
out = (1-wet)*x + wet*y;
end
end
end