%Simple analog output

clear waveform;

%define the output
adaptor = 'winsound';
id = 0;
chan = 1;

% Analog output object Configuration.
% Create an analog input object with one channel.
ao = analogoutput(adaptor, id);
ch = addchannel(ao, chan);

% Configure the analog output rate.
set(ao, 'SampleRate', 8000);
%and trigger mode
set(ao, 'TriggerType', 'manual');
%delete the ao object when done
%not documented, but seems to work
set(ao,'stopaction','delete');

% Object Execution.
% Start the analog input object.

%2000 points/output
x=linspace(0,2*pi,1000)';

for i=1:30
   %make an increasing frequency sin wave
   %The exponential puts the notes on a log scale
   %and the final modulation eliminates end-effects
   waveform(:,i)=0.25*sin(2^((i+14)*.125)*x).*sin(x*0.5);
end

%Make the 30 waveforms into one long column
waveform = reshape(waveform, length(x)*30,1);

% Put it in the ouput buffer
putdata(ao, waveform);

%start output and trigger it
start(ao);
trigger(ao);

%generic scheme for deleting all AO
%existingAO=daqfind('name','winsound0-AO');
%for i=1:length(existingAO)
%  delete(existingAO{i});
%end