-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.m
72 lines (62 loc) · 2.19 KB
/
driver.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
clear; close all;
%Initialize sound files
gts_init;
%Get the filename from the user
filename = input('Guitar tab image name: ', 's');
%filename = 'Test Images/test_image8.JPG';
%Find the order of the notes on the image
ordered_notes = image_read(filename);
%*****SOUND SYNTHESIS*****
notes_to_play = synthesize(ordered_notes);
%*****PLAY AUDIO*****
Fsloc = Fs(1);
% need to fix - needs to be played much faster.
horizontal_loc = diff(cell2mat(ordered_notes{1}(:, 1)));
for i = 2:length(ordered_notes)
horizontal_loc = [horizontal_loc; horizontal_loc(length(horizontal_loc)); diff(cell2mat(ordered_notes{i}(:, 1)))];
end
temp = sort(horizontal_loc, 'descend');
max_diff = mean(temp(1:3));
count = 0;
note_num = 1;
for i = 1:length(horizontal_loc)
if(horizontal_loc(i) ~= 0 || i == length(horizontal_loc))
if(i == length(horizontal_loc) && horizontal_loc(i) == 0)
yA = notes_to_play{note_num};
sound(yA(1:40000), Fsloc);
pause_time = 1 * horizontal_loc(i) / max_diff;
pause(pause_time);
% note_num = note_num + 1;
%
% yA = notes_to_play{note_num};
% sound(yA(1:40000), Fsloc);
elseif(i == length(horizontal_loc) && horizontal_loc(i) ~= 0)
yA = notes_to_play{note_num};
sound(yA(1:40000), Fsloc);
pause_time = 1 * horizontal_loc(i) / max_diff;
if(pause_time > 1)
pause_time = 1;
end
pause(pause_time);
note_num = note_num + 1;
yA = notes_to_play{note_num};
sound(yA(1:40000), Fsloc);
else
yA = notes_to_play{note_num};
sound(yA(1:40000), Fsloc);
pause_time = 1 * horizontal_loc(i) / max_diff;
if(pause_time > 1)
pause_time = 1;
end
pause(pause_time);
note_num = note_num + 1;
end
elseif(horizontal_loc(i) == 0)
continue;
end
end
% for(j=1:1:length(notes_to_play))
% yA = notes_to_play{j};
% sound(yA(1:40000),Fsloc);
% pause(0.75);
% end