Code covered by the BSD License

# Acoustic Tracker (Updated)

### MathWorks Data Acquisition Toolbox Team (view profile)

06 Mar 2003 (Updated )

Demonstrate using the Data Acquisition Toolbox to build an application.

makeasound(varargin)
```function makeasound(varargin)
%MAKEASOUND Make a sound.
% MAKEASOUND will create an analogoutput object and continuously play a
% 1000 Hz sine wave through the object. MAKASOUND STOP will stop
% the object from playing the sound.
%
% MAKASOUND(fo) will play a sine wave at fo Hz
% MAKEASOUND(wavefile) will use the data stored in wavefile.
%

% Copyright 1998 - 2001 The MathWorks, Inc

if nargin,
% Check to see if called as MAKEASOUND STOP
if strcmp(lower(varargin{1}),'stop'),
% If being told to stop, find the object playing the sound and stop it.
Objects=daqfind('Name','Produce Sound');
for lp=1:length(Objects),
stop(Objects{lp});
delete(Objects{lp});
end
return;
fo=1000;      %Default frequency
elseif findstr(lower(varargin{1}),'.wav')
%Specify a .wav file for source of sound
filename = varargin{1};

else,     %Specify frequency
fo = varargin{1};
end % if strcmp
else
fo=1000;      %Default frequency

end % if nargin

% Create the analogoutput with two channels
%(If use one channel, will create mono signal)
AO=analogoutput('winsound');

AO.SampleRate=44100; % Hz
AO.RepeatOutput=inf; % Run forever
AO.Name='Produce Sound'; % Name the object

if exist('filename','var') & exist(filename,'file')
y=y(:,1);           %Require mono signal
AO.SampleRate=fs; % Hz
else
% Create the sine wave
t=(0:1/AO.Samplerate:1-1/AO.SampleRate)';
y=2*sin(2*pi*fo*t);
end;

% Put the data into the object and start the object.
putdata(AO,[zeros(size(y)) y]);     %Send data to right speaker only
start(AO);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
```