home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / SOUNDS.DI$ / AUWRITE.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1.3 KB  |  44 lines

  1. function auwrite(y,filename)
  2. %AUWRITE Write mu-law encoded audio file.
  3. %    AUWRITE(Y,'filename') converts Y to mu-law encoded bytes
  4. %    and writes it to the specified audio file.
  5. %    /dev/audio is used if the file name is not given.
  6.  
  7. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  8.  
  9. localsound = 0;
  10. if nargin < 2
  11.    filename = '/dev/audio';
  12.    machinename = getenv('HOST');
  13.    dspname = getenv('DISPLAY');
  14.    ii = find(dspname == ':');
  15.    dspname  = dspname(1:ii-1);
  16. % if host isn't same as display, not local, unless the display is :0.0
  17.    if strcmp(dspname,machinename) | isempty(dspname)
  18.       localsound  = 1;
  19.    end
  20. end
  21. mu = lin2mu(y);
  22. if ~localsound % make temporary filename and place in current directory.
  23.    t = clock;
  24.    hm = pwd;
  25.    filename = [hm, '/', sprintf('tp%02.0f%02.0f%02.0f', t(4), t(5), t(6))];
  26. end
  27. fp = fopen(filename,'wb');
  28. if fp == -1
  29.    disp('Audio capabilities are not available on this machine or you')
  30.    disp('do not have write privileges for this file.')
  31. else
  32.    fwrite(fp,mu,'uchar');
  33.    fclose(fp);
  34. end
  35. if ~localsound
  36.    cp = computer;
  37.    commandsh = 'rsh';
  38.    if cp(1) == 'H'
  39.       commandsh = 'remsh';
  40.    end
  41.    eval(['!', commandsh, ' ', dspname, ' "cat ', filename,' > /dev/audio"']);
  42.    delete(filename);
  43. end
  44.