Deprecated: Function create_function() is deprecated in /home/c00p/www/lib/geshi/geshi.php on line 4698
function file_disp( filePath, fileName )
%--------------------------------------------------------------------------
% Waveform and Spectrogram Displays
%
% Cooper Baker - 2014
%--------------------------------------------------------------------------

close all;

% Settings
%--------------------------------------------------------------------------
winSize = 512;
overlap = 4;
win     = chebwin( winSize, 125 );
name    = 'File Display';

% Initializations
%--------------------------------------------------------------------------
if any( exist( 'fileName' ) ~= 1 )
    [ fileName, filePath ] = uigetfile( '*.wav', 'Audio File' );
end

[ buf, sr ] = audioread( [ filePath, fileName ] );
nyqBin      = winSize / 2;
hopSize     = winSize / overlap;
samps       = length( buf );
fwdSamps    = winSize - hopSize;
seconds     = round( ( samps / sr ) * 100 ) / 100;
frames      = ( samps / winSize ) * overlap - ( overlap - 1 );
nyquist     = sr / 2;

% Analysis
%--------------------------------------------------------------------------

% spectrogram
rawGram = spectrogram( buf, win, fwdSamps, winSize, sr );

% intermediate calculations
magGram = abs( rawGram );
ampGram = ( magGram / winSize ) * overlap;

% decibel spectrogram
dbGram = 20 * log10( ampGram );

% Plots
%--------------------------------------------------------------------------
fontName   = 'Times New Roman';
fontSize   = 12;
xSpc       = 1 / 100;
ySpc       = 1 / 25;

fig = figure( 1 );
set( fig, 'Name', fileName );
set( fig, 'Position', [ 0 0 800 500 ] );
set( fig, 'defaultAxesFontName', fontName );
set( fig, 'defaultTextFontName', fontName );

% Samples
% -------------------------------------------------------------------------
set( subplot( 2, 1, 1 ), 'Position', [ 0.1, 0.5, 0.8, 0.37 ] );
plot( buf, 'LineWidth', 1, 'Color', 'Black' );
axis( [ 0 samps -1 1 ] );
set( gca, 'XTick',      [ 0 samps   ] );
set( gca, 'XTickLabel', [] );
set( gca, 'YTickLabel', [] );
ylabel( 'Amplitude' );

% Spectrogram
% -------------------------------------------------------------------------
set( subplot( 2, 1, 2 ), 'Position', [ 0.1, 0.1, 0.8, 0.37 ] );
imagesc( dbGram );
caxis( [ -120 0 ] );
axis xy;
axis( [ 0 frames 0 nyqBin ] );
set( gca, 'XTick',      [ 0 frames  ] );
set( gca, 'XTickLabel', [ 0 seconds ] );
set( gca, 'YTickLabel', [] );
xlabel( 'Seconds' );
ylabel( 'Frequency' );

% tighten up figure borders
tightfig();

xlabel( 'Seconds', 'Position', [ ( frames / 2 ) -( nyqBin * ySpc ) ] );

% Export Graphs
%--------------------------------------------------------------------------
[ a, fileName, b ] = fileparts( fileName );

hgexport( fig, [ fileName, '.eps' ] );

% EOF