-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathallpm.m
More file actions
94 lines (83 loc) · 2.61 KB
/
Copy pathallpm.m
File metadata and controls
94 lines (83 loc) · 2.61 KB
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
function [out, rI, wI, buffer, ppi_buffer, ppi_out, x_old, y_old, lp_old] = ...
allpm(in, rI, wI, lfoIndex, excursion, fs, ...
ppi_buffer, ppi_out, x_old, y_old, lp_old, gain, buffer, bufsz)
sine_float = 2*excursion*(sin(2*pi*lfoIndex/fs)+1); % activate excursion
sine_int = ceil(sine_float);
d = sine_int - sine_float;
a = 0.5; % 0 for linear interpolation, 0.5 suggested
wI = mod(wI, bufsz) + 1;
rI = wI + 1+ sine_int;
rI = mod(rI, bufsz) + 1;
% -------------------------------------------------------
% ***** Compute FIR coefficients *****
%
% ***** Välimäki approach
% h(1) = a*d^2 - a*d;
% h(2) = -a*d^2 + (a-1)*d + 1;
% h(3) = -a*d^2 + (a+1)*d;
% h(4) = h(1);
%
% ***** J.O.Smith approach (Lagrange)
% h(1) = -(d-1)*(d-2)*(d-3)/6;
% h(2) = d*(d-2)*(d-3)/2;
% h(3) = -d*(d-1)*(d-3)/2;
% h(4) = d*(d-1)*(d-2)/6;
%
% ***** Cubic spline interpolation
% h(1) = (d^3)/6;
% h(2) = ((1+d)^3-4*d^3)/6;
% h(3) = ((2-d)^3-4*(1-d)^3)/6;
% h(4) = ((1-d)^3)/6;
%
% -------------------------------------------------------
% ***** FIR interpolation *****
%
% buffer(wI) = in + ppi_out * gain;
% ppi_in = buffer(rI);
% ppi_buffer = circshift(ppi_buffer,1);
% ppi_buffer(1) = ppi_in;
% ppi_out = dot(ppi_buffer, h);
% out = ppi_out - buffer(wI) * gain;
% -------------------------------------------------------
% -------------------------------------------------------
% ***** Allpass interpolation *****
%
% x_new = buffer(rI);
%
% % *** Simple allpass interpolator:
% y_new = (1-d)*(x_new - y_old) + x_old;
%
% % *** Warped allpass interpolator:
% % y_new = ((1-d)/(1+d))*(x_new - y_old) + x_old;
%
% tapout = in + (y_new * gain);
% out = y_new - (tapout * gain);
% buffer(wI) = tapout;
%
% x_old = x_new;
% y_old = y_new;
% -------------------------------------------------------
% -------------------------------------------------------
% ***** Linear interpolation *****
%
% lint_out = buffer(rI) * (d) + ppi_out * (1-d);
% buffer(wI) = in + lint_out * gain;
% out = (lint_out - buffer(wI) * gain);
% ppi_out = buffer(rI); % ppi output borrowed: lint_x_old
% -------------------------------------------------------
% -------------------------------------------------------
% ***** No interpolation *****
%
buffer(wI) = in + buffer(rI) * gain;
out = buffer(rI) - buffer(wI) * gain;
% -------------------------------------------------------
% -------------------------------------------------------
% ***** No interpolation + lowpass after buffer
%
% b = 0.5;
% lp_out = b*(buffer(rI)+lp_old);
% buffer(wI) = in + lp_out * gain;
% lp_old = buffer(rI);
% out = lp_out - buffer(wI) * gain;
% -------------------------------------------------------
end