function gplay(x,sr,dur)
% gplay(x,sr,dur)
% graphical playback:
% Play a segment of sound dur seconds long starting at time pointed by the mouse.
% Clicking starts playing.
% Exit the program by typing a return key.
% input parameters:
% x - sound that corresponds to the graphical display. 
% The x axis of the display must be in seconds.
% sr - sampling rate
% dur - duration of the playback segment
% Example: graph could be a spectrogram of a sound file in the active graphics window.

if nargin < 2,
    error('you must provide sampling rate
end
if nargin == 2,
    dur = 2;
end

while 1,
    [i,j,button] = ginput(1)
    
    if isempty(i), %on pc:  ~= 1,
        return
    else
        soundsc(x(round(i*sr):round((i+dur)*sr)),sr);
    end
end