%% Determine Loudness Range
% Read in an audio signal. Clip 3 five-second intervals out of the signal.

[x,fs] = audioread('FunkyDrums-44p1-stereo-25secs.mp3');
x1 = x(1:fs*5,:);
x2 = x(5e5:5e5+5*fs,:);
x3 = x(end-5*fs:end,:);

%
% Calculate the loudness and loudness range of the total signal and of each interval.

[L,LRA] = integratedLoudness(x,fs);
[L1,LRA1] = integratedLoudness(x1,fs);
[L2,LRA2] = integratedLoudness(x2,fs);
[L3,LRA3] = integratedLoudness(x3,fs);

fprintf(['Loudness: %0.2f\n', ...
    'Loudness range: %0.2f\n\n', ...
    'Beginning loudness: %0.2f\n', ...
    'Beginning loudness range: %0.2f\n\n', ...
    'Middle loudness: %0.2f\n', ...
    'Middle loudness range: %0.2f\n\n', ...
    'End loudness: %0.2f\n', ...
    'End loudness range: %0.2f\n'], ...
    L,LRA,L1,LRA1,L2,LRA2,L3,LRA3);

% Copyright 2012 The MathWorks, Inc.