function Lsb = soundpr(X, scf)
%X = Sound_pressure_level(X, scf)
%
%   The sound pressure level Lsb is computed for every subband.
%   X is the normalised power density spectrum and scf are the 32 scale
%   factors (one per band).
%
%   See also  Scale_factors
   

%-------------------------------------------------------------------------------
common;

% Check input parameters
if (length(X) ~= FFT_SIZE)
   error('Unexpected power density spectrum size.');
end

if (length(scf) ~= N_SUBBAND)
   error('Unexpected number of scalefactors');
end

% Pick the 32 sound pressure level of the spectral line with maximum amplitude
% in the frequency range corresponding to subband i and compute the
% sound pressure level Lsb.
Xmin = min(X);
n = FFT_SIZE / 2 / N_SUBBAND; % Size of each subband

for i = 1:N_SUBBAND,
   local_max = Xmin;
   for j = 1:n,
      local_max = max(X((i - 1) * n + j), local_max);
   end
   Lsb(i) = max(local_max, 20 * log10(scf(i) * 32768) - 10);
end
