annotate util/classes/@audio/plot.m @ 182:f8bc99a5470c danieleb

Added test for audio buffer function
author Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk>
date Mon, 09 Jan 2012 12:58:00 +0000
parents 1495bdfa13e9
children
rev   line source
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@160 19 %% Plot the time domain signal
daniele@160 20 s = obj.s;
daniele@160 21 fs = obj.fs;
daniele@166 22 plot((1:length(s))/fs,s);
daniele@160 23 title('Audio signal')
daniele@160 24 xlabel('time (s)');
daniele@160 25 axis tight
daniele@160 26
daniele@160 27 player = audioplayer(s,fs);
daniele@166 28 set(player,'TimerPeriod',0.1);
daniele@160 29 set(player,'StartFcn',@plotTransportBar);
daniele@160 30 set(player,'TimerFcn',@updateTransportBar);
daniele@160 31 set(player,'StopFcn',@deleteTransportBar);
daniele@160 32
daniele@166 33 %% Add playback controls
daniele@160 34 set(playButtonH,'Callback',@play_callback);
daniele@160 35 set(stopButtonH,'Callback',@stop_callback);
daniele@166 36 set(pauseButtonH,'Callback',@pause_callback);
daniele@166 37 set(rewButtonH,'Callback',@rew_callback);
daniele@166 38 set(ffButtonH,'Callback',@ff_callback);
daniele@160 39
daniele@166 40 function play_callback(~,~)
daniele@166 41 set(player,'SampleRate',fs);
daniele@166 42 play(player,player.CurrentSample);
daniele@166 43 set(pauseButtonH,'Value',0);
daniele@166 44 set(ffButtonH,'Value',0);
daniele@166 45 end
daniele@160 46
daniele@166 47 function pause_callback(~,~)
daniele@166 48 pause(player);
daniele@166 49 set(playButtonH,'Value',0);
daniele@166 50 set(ffButtonH,'Value',0);
daniele@166 51 end
daniele@166 52
daniele@166 53 function stop_callback(~,~)
daniele@166 54 stop(player);
daniele@166 55 set(playButtonH,'Value',0);
daniele@166 56 set(pauseButtonH,'Value',0);
daniele@166 57 set(ffButtonH,'Value',0);
daniele@166 58 end
daniele@166 59
daniele@166 60 function ff_callback(~,~)
daniele@166 61 set(player,'SampleRate',1.5*fs);
daniele@166 62 set(pauseButtonH,'Value',0);
daniele@166 63 set(playButtonH,'Value',0);
daniele@166 64 end
daniele@166 65
daniele@166 66 function rew_callback(~,~)
daniele@166 67 stop(player);
daniele@166 68 play(player);
daniele@166 69 set(pauseButtonH,'Value',0);
daniele@166 70 set(playButtonH,'Value',1);
daniele@166 71 end
daniele@160 72
daniele@160 73 %% Transport Bar functions
daniele@166 74 function plotTransportBar(~,~)
daniele@166 75 global tbH
daniele@166 76 xLim = get(gca,'Xlim');
daniele@166 77 yLim = get(gca,'YLim');
daniele@166 78 tbH = line([xLim(1) xLim(1)],yLim,'Color','k');
daniele@166 79 end
daniele@160 80
daniele@166 81 function updateTransportBar(hObject,~)
daniele@166 82 global tbH
daniele@166 83 currentSample = hObject.CurrentSample;
daniele@166 84 pos = currentSample/fs;
daniele@166 85 set(tbH,'XData',[pos pos]);
daniele@166 86 end
daniele@166 87
daniele@166 88 function deleteTransportBar(~,~)
daniele@166 89 global tbH
daniele@166 90 delete(tbH);
daniele@166 91 end
daniele@160 92 end