myplaysnd.m

来自「Mathematical Methods by Moor n Stiling.」· M 代码 · 共 29 行

M
29
字号
function myplaysnd(y,fs)
% 
% Modified and simplified from playsnd, to make the sample rate stuff work

% PLAYSND Implementation 
%   MYPLAYSND(Y,FS)
%
% y = data to play
% fs = sample rate

% Copyright 1999 by Todd K. Moon

if(nargin==1)
  fs = 11025;
end
t = clock;
tmpfile = ['/tmp/au' sprintf('%02.0f%02.0f%02.0f', t(4:6))];
fp = fopen(tmpfile,'wb');
if fp==-1,
  error(['Cannot open ' tmpfile ' with write privilege.'])
end
my = min(y);  My = max(y);

fwrite(fp, floor( 255*(y+my)/(My-my) + .5),'uchar');
fclose(fp);
str = ['!play ' sprintf('%d',fs) ' ' tmpfile];
eval(str)
delete(tmpfile);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?