-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresample.m
26 lines (18 loc) · 968 Bytes
/
resample.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
% Note that matlab arrays start from index 1, not 0.
F1 = 15360; % Sampling rate of Yamaha chip
F2 = 48000;
_gcd = gcd(F1, F2);
M = F1 / gcd(F1, F2); % Necessary Decimation ratio
N = F2 / gcd(F1, F2); % necessary Expansion ratio
Lx = 256; % Length of Audio Input Buffer at F1 rate
Ly = floor(Lx*N/M); % Length of Resampled Output Buffer at F2 rate
x = sin(2*pi*1234*[0:Lx-1]/F1); % Just a test sine wave
y = zeros(1,Ly); % allocate output signal memory
for i=0:Ly-1 % run per each output sample
n = i * (Lx - 1) / Ly % compute exact samapling posiiton inside the long buffer
ind = floor(n); % convert it into largest integer smaller than itself for array indexing
d = n-ind; % take the difference for proportional weighting
y(i+1) = (1-d)*x(ind+1) + d*x(ind+2); % sum the weighted mixture.
end
figure,plot(x); %plot each waveforms...
figure,plot(y);