function y=record(duration,fs) %RECORD Read sound from microphone into vector. % y=RECORD records 1 second of sound at the default frequency (samples % per second). On the SUN SPARC, the default is 8192 samples per second. % Thus RECORD returns a vector of 8192 entries. % % y=RECORD(200) records 200 samples at the default frequency. % y=RECORD(200,500) records 200 samples at the rate of 500 samples % per second. Your hardware may not support arbitrary frequencies. % The SUN SPARC only supports 8192 samples per second. % % See also SOUND, AUREAD, AUWRITE. % Author: % Alexander Perlis % SouthWest Regional Institute in the Mathematical Sciences % c/o Department of Mathematics % The University of Arizona % Tucson, AZ 85721 % (520) 621-2137 % aprl@math.arizona.edu % % Obtain the latest version of this software from: % http://www.math.arizona.edu/~rims/workshops/fourier/softwareMATLAB % % Bugs/problems/ideas: % None. % % Change history: % May 1997 Original version % Dec 1997 Modified to also work with Linux on Pentium with sound card. %---------------------------------------------------------------------------- if nargin<1 %% assume 1 second if not specified duration = 8192; end if strcmp(computer,'LNX86') % !aumix -v 0 -m 50 -i 50 [fp,message] = fopen('/dev/audio','rb'); if fp == -1 disp('Record error: Couldn''t open the audio device.') disp('Suggestion: Try again, or play a sound to reset the device.') disp('The system-generated error message is:') disp(message) else [mu,count] = fread(fp,duration,'uchar'); fclose(fp); % Convert from mu-law to linear y = mu2lin(mu); end % !aumix -v 75 -m 0 -i 0 elseif strcmp(computer,'SUN4') % Is audio device local or remote? host = getenv('HOST'); % dsp = getenv('DISPLAY'); % dsp = dsp(1:find(dsp == ':')-1); %% Strip ":0.0" off end of display name % if strcmp(dsp,host) | strcmp(lower(dsp),'unix') | ... % isempty(dsp) | isempty(host) % Audio device is probably on this machine, so try to read from it. [fp,message] = fopen('/dev/audio','rb'); if fp == -1 disp('Record error: Couldn''t open the audio device.') disp('Suggestion: Try again, or play a sound to reset the device.') disp('The system-generated error message is:') disp(message) else [mu,count] = fread(fp,duration,'uchar'); fclose(fp); % Convert from mu-law to linear y = mu2lin(mu); end % else % disp('Record error: The audio device appears to be on a remote machine.') % end else disp('Record error: Audio recording not supported on this machine.') end % [eof]