daniele@160
|
1 function plot(obj)
|
daniele@160
|
2
|
daniele@166
|
3 figure,
|
daniele@166
|
4 playbackPanelH = uipanel(gcf,'Units','Normalized','Position',[.3 0 .4 .1]);
|
daniele@166
|
5
|
daniele@166
|
6 buttWidth = 1/6;
|
daniele@166
|
7 centers = linspace(0,1,7)-buttWidth/2;
|
daniele@166
|
8 rewButtonH = uicontrol(playbackPanelH,'Style','pushbutton','String','<<','Units',...
|
daniele@166
|
9 'Normalized','Position',[centers(2) 0.2 buttWidth 0.6]);
|
daniele@166
|
10 ffButtonH = uicontrol(playbackPanelH,'Style','togglebutton','String','>>','Units',...
|
daniele@166
|
11 'Normalized','Position',[centers(3) 0.2 buttWidth 0.6]);
|
daniele@166
|
12 stopButtonH = uicontrol(playbackPanelH,'Style','pushbutton','String','stop','Units',...
|
daniele@166
|
13 'Normalized','Position',[centers(4) 0.2 buttWidth 0.6]);
|
daniele@166
|
14 playButtonH = uicontrol(playbackPanelH,'Style','togglebutton','String','play','Units',...
|
daniele@166
|
15 'Normalized','Position',[centers(5) 0.2 buttWidth 0.6]);
|
daniele@166
|
16 pauseButtonH = uicontrol(playbackPanelH,'Style','togglebutton','String','||','Units',...
|
daniele@166
|
17 'Normalized','Position',[centers(6) 0.2 buttWidth 0.6]);
|
daniele@166
|
18
|
daniele@166
|
19 waveformPanelH = uipanel(gcf,'Units','Normalized','Position',[.02 .12 .96 .86]);
|
daniele@166
|
20 waveformAxesH = axes('Parent',waveformPanelH);
|
daniele@166
|
21
|
daniele@160
|
22 %% Plot the time domain signal
|
daniele@160
|
23 s = obj.s;
|
daniele@160
|
24 fs = obj.fs;
|
daniele@166
|
25 plot((1:length(s))/fs,s);
|
daniele@160
|
26 title('Audio signal')
|
daniele@160
|
27 xlabel('time (s)');
|
daniele@160
|
28 axis tight
|
daniele@160
|
29
|
daniele@160
|
30 player = audioplayer(s,fs);
|
daniele@166
|
31 set(player,'TimerPeriod',0.1);
|
daniele@160
|
32 set(player,'StartFcn',@plotTransportBar);
|
daniele@160
|
33 set(player,'TimerFcn',@updateTransportBar);
|
daniele@160
|
34 set(player,'StopFcn',@deleteTransportBar);
|
daniele@160
|
35
|
daniele@166
|
36 %% Add playback controls
|
daniele@160
|
37 set(playButtonH,'Callback',@play_callback);
|
daniele@160
|
38 set(stopButtonH,'Callback',@stop_callback);
|
daniele@166
|
39 set(pauseButtonH,'Callback',@pause_callback);
|
daniele@166
|
40 set(rewButtonH,'Callback',@rew_callback);
|
daniele@166
|
41 set(ffButtonH,'Callback',@ff_callback);
|
daniele@160
|
42
|
daniele@166
|
43 function play_callback(~,~)
|
daniele@166
|
44 set(player,'SampleRate',fs);
|
daniele@166
|
45 play(player,player.CurrentSample);
|
daniele@166
|
46 set(pauseButtonH,'Value',0);
|
daniele@166
|
47 set(ffButtonH,'Value',0);
|
daniele@166
|
48 end
|
daniele@160
|
49
|
daniele@166
|
50 function pause_callback(~,~)
|
daniele@166
|
51 pause(player);
|
daniele@166
|
52 set(playButtonH,'Value',0);
|
daniele@166
|
53 set(ffButtonH,'Value',0);
|
daniele@166
|
54 end
|
daniele@166
|
55
|
daniele@166
|
56 function stop_callback(~,~)
|
daniele@166
|
57 stop(player);
|
daniele@166
|
58 set(playButtonH,'Value',0);
|
daniele@166
|
59 set(pauseButtonH,'Value',0);
|
daniele@166
|
60 set(ffButtonH,'Value',0);
|
daniele@166
|
61 end
|
daniele@166
|
62
|
daniele@166
|
63 function ff_callback(~,~)
|
daniele@166
|
64 set(player,'SampleRate',1.5*fs);
|
daniele@166
|
65 set(pauseButtonH,'Value',0);
|
daniele@166
|
66 set(playButtonH,'Value',0);
|
daniele@166
|
67 end
|
daniele@166
|
68
|
daniele@166
|
69 function rew_callback(~,~)
|
daniele@166
|
70 stop(player);
|
daniele@166
|
71 play(player);
|
daniele@166
|
72 set(pauseButtonH,'Value',0);
|
daniele@166
|
73 set(playButtonH,'Value',1);
|
daniele@166
|
74 end
|
daniele@160
|
75
|
daniele@160
|
76 %% Transport Bar functions
|
daniele@166
|
77 function plotTransportBar(~,~)
|
daniele@166
|
78 global tbH
|
daniele@166
|
79 xLim = get(gca,'Xlim');
|
daniele@166
|
80 yLim = get(gca,'YLim');
|
daniele@166
|
81 tbH = line([xLim(1) xLim(1)],yLim,'Color','k');
|
daniele@166
|
82 end
|
daniele@160
|
83
|
daniele@166
|
84 function updateTransportBar(hObject,~)
|
daniele@166
|
85 global tbH
|
daniele@166
|
86 currentSample = hObject.CurrentSample;
|
daniele@166
|
87 pos = currentSample/fs;
|
daniele@166
|
88 set(tbH,'XData',[pos pos]);
|
daniele@166
|
89 end
|
daniele@166
|
90
|
daniele@166
|
91 function deleteTransportBar(~,~)
|
daniele@166
|
92 global tbH
|
daniele@166
|
93 delete(tbH);
|
daniele@166
|
94 end
|
daniele@160
|
95 end
|