function maketones
% Generate synthetic sources
%
%  Usage:
%    maketones
%
%  Just run it and it'll work ...

% -------------------
%  Continuous sounds
% -------------------
%
% Obvious cases here
% For pitched tones frequency is variable
% just to make adaptation harder (he, he ...)

% Overall length
l = 191258;
t = linspace( 0, 2*pi, l);


% The omnipresent sinusoid
fprintf( 'Sine ...')
sn = sin( (1+ .4*sin( 8*t).^2) * 440 .* t);
wavwrite( sn, 22050, 16, '../sources/sine.wav');
fprintf( 'done\n')


% Sawtooth
fprintf( 'Sawtooth ...')
saw = sawtooth( (440 + 100*sin( 8*t)).* t);
wavwrite( saw, 22050, 16, '../sources/sawtooth.wav');
fprintf( 'done\n')


% Square
fprintf( 'Square ...')
sq = square( (440 + 100*sawtooth( 8*t)).* t);
wavwrite( sq, 22050, 16, '../sources/square.wav');
fprintf( 'done\n')


% Gaussian noisef
% Clipped to accomodate soundfile format
fprintf( 'Gaussian noise ...')
gn = randn( 1, l);
i = find( abs( gn) > 4);
gn(i) = gn(i)/max( abs( gn(i)));
gn = gn/4;
wavwrite( gn, 22050, 16, '../sources/gaussn.wav');
fprintf( 'done\n')

% Caychy noise
% Clipped to accomodate soundfile format
fprintf( 'Cauchy noise ...')
cn = cauchrand( l);
i = find( abs( cn) > 1);
cn(i) = cn(i)/max( abs( cn(i)));
wavwrite( cn, 22050, 16, '../sources/cauchyn.wav');
fprintf( 'done\n')


% --------------------
%  Interrupted sounds
% --------------------
%
% This is to test how fast an algorithm will 
% lose it if a sound fades out for a while.

% Define gating functions and apply on previous signals

% Sinusoid
fprintf( 'Gated sinusoid ...')
gt = interp1( 1:9, [1 1 1 0 0 0 1 1 1], linspace( 0, 9, l));
wavwrite( gt.*sn,  22050, '../sources/gsine.wav')
fprintf( 'done\n')

% Sawtooth
fprintf( 'Gated sawtooth ...')
gt = interp1( 1:9, [0 0 0 1 1 1 1 1 1], linspace( 0, 9, l));
wavwrite( gt.*saw, 22050, '../sources/gsawtooth.wav')
fprintf( 'done\n')

% Square
fprintf( 'Gated square ...')
gt = interp1( 1:9, [0 0 1 1 1 1 1 0 0], linspace( 0, 9, l));
wavwrite( gt.*sq,  22050, '../sources/gsquare.wav')
fprintf( 'done\n')

% Gaussian noise
fprintf( 'Gated Gaussian noise ...')
gt = interp1( 1:9, [1 1 1 1 0 0 0 0 0], linspace( 0, 9, l));
wavwrite( gt.*gn,  22050, '../sources/ggaussn.wav')
fprintf( 'done\n')

% Cauchy noise
fprintf( 'Gated Cauchy noise ...')
gt = interp1( 1:9, [1 1 1 0 1 1 0 0 1], linspace( 0, 9, l));
wavwrite( gt.*cn,  22050, '../sources/gcauchyn.wav')
fprintf( 'done\n')


% Auxiliary function for Cauchy noise
function out = cauchrand( l, r)

if nargin == 1
        r = 1;
end
r = r/318.3;

x1 = rand( 1, l);
i = find( x1 == .5);
x1(i) = x1(i) + eps;
x1 = x1 * pi;

out = r * tan( x1);
