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

% clean up
close all;
clear;

% Initializations
%--------------------------------------------------------------------------
sampRate  = 44100;
freq      = 1000;
zeroSec   = 1;
toneSec   = 2;
outFile   = 'sine_ideal.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
