% FUNCTION MY_SOUND(Y, [FS], [NBITS])
%
% Y values in [-1 +1] or 'filename' to WAVREAD
% default FS = 16000, NBITS = 16

function my_sound(y, fs, nbits)

if nargin < 1
  error('my_sound() need at least one parameter');
end

if nargin < 2
  fs = 16000;
end

if nargin < 3
  nbits = 16;
end

if ischar(y)
  [y, y_fs, y_b_bits] = wavread(y);
  if y_fs ~= fs
    y = resample( y, fs, y_fs );
  end
end

filename = ...
    fullfile(getenv('HOME'), ['.my_sound.' num2str(now*1e10) '.wav']);

wavwrite(y, fs, nbits, filename);
system(['play ' filename]);
delete(fullfile(getenv('HOME'), '.my_sound.*.wav'));
