forked from torstenmolitor/fourier-piano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
75 lines (59 loc) · 2.38 KB
/
main.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
%% recording
timeSpan = 5;
fs = 8192;
x = record(timeSpan, fs); % record voice
timeWindow = 0.2;
windowOverlap = 0.3; % overlap between consecutive windows (0 = no overlap, etc.)
low_c = 3; % lowest c shown on the piano
high_c = 5; % highest c shown on the piano
%% train
A = 440;
load('train.mat');
fs = Fs; % the sampling frequency of the sound
x = y; % the signal
timeWindow = 0.2;
windowOverlap = 0.3; % overlap between consecutive windows (0 = no overlap, etc.)
low_c = 5; % lowest c shown on the piano
high_c = 7; % highest c shown on the piano
frameTime = timeWindow*(1-windowOverlap);
%% intel
[x,fs] = audioread('sounds/intel-sound-logo.mp3');
x = mean(x,2); % naive stereo -> mono
timeWindow = 0.12; % seconds per window
windowOverlap = 0.3; % overlap between consecutive windows (0 = no overlap, etc.)
low_c = 4; % lowest c shown on the piano
high_c = 5; % highest c shown on the piano
%% twin peaks
% set tuning convention, e.g. 435, 440, 442
A = 440;
% [x,fs] = audioread('sounds/twin-peaks-theme.mp3',44100.*[1.0, 7.15]);
[x,fs] = audioread('sounds/twin-peaks-theme.mp3',[46100, 331900]); % wamp
x = mean(x,2); % naive stereo -> mono
timeWindow = 0.24; % seconds per window
windowOverlap = 0.1; % overlap between consecutive windows (0 = no overlap, etc.)
low_c = 2; % lowest c shown on the piano
high_c = 6; % highest c shown on the piano
frameTime = timeWindow*(1-0.1);
%% Simon Åkesson's Gbmaj7#9#11no3
A = 442;
% [x,fs] = audioread('sounds/Gbmaj7#9#11no3.mp3'); %
[x,fs] = audioread('sounds/Gbmaj7#9#11no3.mp3', [4.15e5, 5.8e5]); %
x = mean(x,2); % naive stereo -> mono
% timeWindow = 0.2; % seconds per window
timeWindow = 0.3*length(x)/fs; % seconds per window
windowOverlap = 0.9; % overlap between consecutive windows (0 = no overlap, etc.)
low_c = 2; % lowest c shown on the piano
high_c = 5; % highest c shown on the piano
frameTime = 5; %timeWindow*(1-windowOverlap);
%%
sound(x,fs)
%%
[F, allFFTWindows,nWindows] = split2windows(x, fs, timeWindow,windowOverlap); % divide signal into windows and perform FFT on each window
maxFFT = max_in_range(allFFTWindows,F,low_c,high_c); % used for scaling the piano background
%%
plot_sequence(F,allFFTWindows,maxFFT,low_c,high_c,A,frameTime)
%%
make_gif(F,allFFTWindows,maxFFT,low_c,high_c,A,'gifs/train.gif')
%%
plot_sequence(F,allFFTWindows,maxFFT,low_c,high_c,A,1)
saveas(gcf,'pngs/chord.png')