%--------------------------------------------------------------------------
% 2 sec 1000Hz zero-padded sine tone
% .5 sec silence + 1 sec tone + .5 sec silence
%
% Cooper Baker - 2014
%--------------------------------------------------------------------------

% clean up
close all;
clear;

% Initializations
%--------------------------------------------------------------------------
sampRate  = 44100;
freq      = 1000;
zeroSec   = 0.5;
toneSec   = 1;
outFile   = 'sine.wav';
toneSamps = toneSec * sampRate;
zeroSamps = zeroSec * sampRate;

% Synthesis
%--------------------------------------------------------------------------

% generate a vector to synthesize the waveform
toneVec  = [ 0 : 1 : toneSamps - 1 ];

% generate waveform and silence
tone = sin( 2 * pi * ( freq / sampRate ) * toneVec );
zero = zeros( 1, zeroSamps );

% concatenate waveform and silence into output vector
output = [ zero( 1, 1 : zeroSamps ), tone( 1, 1 : toneSamps ), zero( 1, 1 : zeroSamps ) ];

% Output
%--------------------------------------------------------------------------

% create comment string
commentString = sprintf( 'Frequency: %.0f\nWaveform: %s', freq, 'sine' );

% write file to disk
audiowrite( outFile, output, sampRate, 'BitsPerSample', 32, 'Artist', 'NormCoeff', 'Title', num2str( 1 ), 'Comment', commentString );

% EOF