home *** CD-ROM | disk | FTP | other *** search
- function sound(y,fs)
- %SOUND Convert vector into sound.
- % SOUND(Y) sends the signal in vector Y out the speaker on SPARC, HP,
- % SGI and Macintosh computers. The vector is autoscaled to provide
- % maximum amplitude.
- %
- % The sound is played at the default sample rate. On the SPARC, the
- % sample rate is fixed at 8192 Hz. On the Macintosh, the default
- % sample rate is 22.255K Hz.
- %
- % SOUND(Y,FS), on the Macintosh and on SGI, plays the sound at a sample
- % frequency of FS Hz.
- %
- % Vector Y is automatically scaled so that the maximum and minimum values
- % in Y correspond to the maximum and minimum input ranges allowed by the
- % sound hardware. On the Macintosh and the SGI, the volume control on the
- % Control Panel determines the final sound level.
- %
- % See also SAXIS, AUWRITE, AUREAD.
-
- % Copyright (c) 1984-93 by The MathWorks, Inc.
-
- global SAXIS_SCALE
- global SAXIS_LIM
- v = saxis;
- ymin = min(y(:));
- ymax = max(y(:));
- if ~strcmp(SAXIS_SCALE,'auto')
- smin = v(1);
- smax = v(2);
- else % auto-scale
- smin = ymin;
- smax = ymax;
- if smin == smax
- smax = smax + 1;
- end
- SAXIS_LIM = [smin smax];
- end
- c = computer;
- % Scale y's values between [smin smax] onto [-1 1].
- slope = 2/(smax-smin);
- intercept = (smin+smax)/(smin-smax);
- y(:) = slope*y+intercept;
- if (strcmp(c,'SUN4') | strcmp(c,'HP700') | strcmp(c,'SOL2'))
- auwrite(y);
- elseif length(c) > 2
- if (strcmp(c(1:3),'MAC') | strcmp(c,'NEXT') | strcmp(c,'SGI'))
- if nargin == 1
- playsound(y) % Uses MEX file in the case of NEXT and SGI
- else
- playsound(y,fs)
- end
- end
- if (strcmp(c(1:2),'PC'))
- old_sa = saxis;
- saxis([0 255]);
- x=y+1;
- x=x*(128);
- x=floor(x);
- playwave(x,fs)
- saxis(old_sa);
- end
- else
- error('Sound is not currently supported on this hardware platform.')
- end
-