Skip to content

Instantly share code, notes, and snippets.

@zaman
Created June 16, 2011 23:06
Show Gist options
  • Save zaman/1030525 to your computer and use it in GitHub Desktop.
Save zaman/1030525 to your computer and use it in GitHub Desktop.
%Simple analog output
%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.
for i=15:40
%2000 points/output
x=linspace(0,2*pi,2000);
%make an increasing frequency sin wave
%The exponential puts the notes on a log scale
%and the final modulation eliminates end-effects
waveform=0.25*sin(2^(i*.125)*x).*sin(x*0.5);
plot(x,waveform)
axis([0 6.28 -.3 .3])
drawnow
% Put it in the ouput buffer
%transpose waveform to make a column vector
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)
end
delete(ao);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment