%Simple analog output
clear all;

%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', 44100);
%and trigger mode
set(ao, 'TriggerType', 'manual');

% Object Execution.
% Start the analog input object.

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

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);

%Wait until output is done
while strcmp(ao.Running, 'On')
end

%kill analog out
stop(ao)
delete(ao);
