function [y, Fs, nbits] = getsound()
% flag is create or read, filename, and channels is
%for creation at least.
filename =  input('GetSound. Filename:  ','s');
nbits = 32;

c = input('create (0) or read (1):  ');
   switch c
    case 0
        disp ('Creating Sound File' );
        disp(filename);
        Fs = input('sample Hz (11025,22050,44100): ');
         secs = input('sample seconds: ');
        Nsamps = secs*Fs;
ch =  input('channels: 1 or 2:  ');
if  (ch ~= 2) & (ch ~= 1)
    error('bad channels in getsound');
end
        fprintf('hit any key to start %d sec recording.\n',secs);
        pause;
        y = wavrecord(Nsamps, Fs, ch,'single'); % one channel this time
disp('saving to disk...');
 wavwrite(y,Fs, 32,filename);
        
    case 1
        disp ('WavReading Sound File');
        disp(filename);
    [y, Fs, nbits] = wavread(filename, 'double');
    
    otherwise 
        error('bad case in getsound');
   end
disp('Hit any key to listen:');
pause;
wavplay(y, Fs);
end
