function [ audioPower ] = detect_AudioPower( sampleWavFileName, OVERWRITE )
% find the audio power

% open original power calculation
sampleFileName = sampleWavFileName( 1 : length( sampleWavFileName ) - 4 );
fileName = [ sampleFileName '_AP.txt'];
fileID = fopen( fileName );

if( (fileID <= 0) || (OVERWRITE) ) %does the file exist?
    % no
    disp('WARNING: MISSING AUDIO POWER FILE');
    %calculate it
    [x, fs, frameLength, noOfFrames] = openFile(  [ sampleFileName '.wav' ] );       
    
    audioPower = calculate_audioPower(x, fs, frameLength, noOfFrames);
%     frameIndex = 1:1:length(AP);
    fileID = fopen( fileName, 'w');
    for i = 1 : noOfFrames
         fprintf( fileID, '%d %s \n' , i, num2str( audioPower(i,1)) );
    end
    
    fclose( fileID );
    fileID = fopen( fileName );
end

audioPower = fscanf( fileID, '%f', inf );
audioPower = audioPower(2:2:end);
fclose( fileID );