home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / SOUNDS.DI$ / SOUND.M < prev    next >
Encoding:
Text File  |  1993-04-27  |  1.8 KB  |  66 lines

  1. function sound(y,fs)
  2. %SOUND    Convert vector into sound.
  3. %    SOUND(Y) sends the signal in vector Y out the speaker on SPARC, HP,
  4. %       SGI and Macintosh computers. The vector is autoscaled to provide
  5. %       maximum amplitude.
  6. %
  7. %    The sound is played at the default sample rate. On the SPARC, the 
  8. %    sample rate is fixed at 8192 Hz. On the Macintosh, the default 
  9. %    sample rate is 22.255K Hz.
  10. %
  11. %    SOUND(Y,FS), on the Macintosh and on SGI, plays the sound at a sample
  12. %    frequency of FS Hz.
  13. %
  14. %    Vector Y is automatically scaled so that the maximum and minimum values 
  15. %    in Y correspond to the maximum and minimum input ranges allowed by the
  16. %    sound hardware. On the Macintosh and the SGI, the volume control on the
  17. %       Control Panel determines the final sound level.
  18. %
  19. %    See also SAXIS, AUWRITE, AUREAD.
  20.  
  21. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  22.  
  23. global SAXIS_SCALE
  24. global SAXIS_LIM
  25. v = saxis;
  26. ymin = min(y(:));
  27. ymax = max(y(:));
  28. if ~strcmp(SAXIS_SCALE,'auto')
  29.     smin = v(1);
  30.     smax = v(2);
  31. else % auto-scale
  32.     smin = ymin;
  33.     smax = ymax;
  34.     if smin == smax
  35.        smax = smax + 1;
  36.     end
  37.     SAXIS_LIM = [smin smax];
  38. end
  39. c = computer;
  40. % Scale y's values between [smin smax] onto [-1 1].
  41. slope = 2/(smax-smin);
  42. intercept = (smin+smax)/(smin-smax);
  43. y(:) = slope*y+intercept;
  44. if (strcmp(c,'SUN4') | strcmp(c,'HP700') | strcmp(c,'SOL2')) 
  45.     auwrite(y);
  46. elseif length(c) > 2
  47.     if (strcmp(c(1:3),'MAC') | strcmp(c,'NEXT') | strcmp(c,'SGI'))
  48.         if nargin == 1
  49.                 playsound(y)  % Uses MEX file in the case of NEXT and SGI
  50.         else
  51.             playsound(y,fs)
  52.         end
  53.     end
  54.     if (strcmp(c(1:2),'PC'))
  55.         old_sa = saxis;
  56.         saxis([0 255]);
  57.         x=y+1;
  58.         x=x*(128);
  59.         x=floor(x);
  60.         playwave(x,fs)
  61.         saxis(old_sa);
  62.     end
  63. else
  64.     error('Sound is not currently supported on this hardware platform.')
  65. end
  66.