function sGt = gainrule_plack2004( sAud, sCfg )
% GAINRULE_PLACK2004 - Gain prescription rule after Plack (2004)
%
% Physiologically motivated compressive gain prescription.
%
% Outer and middle ear filter based on ISO 226:2003 equal-loudness
% contour for 80 phon.
%
% Reference:
%
% Christopher J. Plack, Vit Drga and Enrique A. Lopez-Poveda: Inferred
% basilar-membrane response functions for listeners with mild to
% moderate sensorineural hearing loss.  J. Acoust. Soc. Am. 115 (4),
% April 2004, Pages: 1684-1695
%
% Author: Giso Grimm
% Date: May 2009
  sAud = audprof2aud( sAud );

  max_OHC_gain = 40.0;
  Lmin_comp = 25.0;
  Lmax_comp = 87.0;
  GainLinRatio = 0.0;
  for channel='lr'
    HTL = sAud.(channel).htl;
    HTL = max(0,interp1(log(sAud.frequencies),HTL,...
			log(sCfg.frequencies),'linear','extrap'));
    HTL_OHC = min(max_OHC_gain,HTL);
    HTL_lin = GainLinRatio * (HTL - HTL_OHC);
    vGain = zeros(0,length(sCfg.levels));
    vEqN = equal_loudness_contour80(sCfg.frequencies)-80;
    for k=1:length(HTL)
      param_gt_L = [Lmin_comp-1,Lmin_comp,Lmax_comp - (Lmax_comp-Lmin_comp)*(max_OHC_gain-HTL_OHC(k))/max_OHC_gain,Lmax_comp+1]+vEqN(k);
      param_gt_G = [HTL_OHC(k)+HTL_lin(k),HTL_OHC(k)+HTL_lin(k),HTL_lin(k),HTL_lin(k)];
      [param_gt_L,idx] = unique(param_gt_L);
      param_gt_G = param_gt_G(idx);
      vGain(k,:) = ...
	  interp1(param_gt_L,param_gt_G,sCfg.levels,'linear','extrap');
    end
    sGt.(channel) = vGain';
  end

  
function L = equal_loudness_contour80( vF )
  data = [ ...
      20,118;...
      30,111;...
      40,106;...
      50,102;...
      60,99;...
      80,95;...
      100,92;...
      200,85;...
      300,82;...
      400,81;...
      600,80;...
      900,80;...
      1000,80;...
      1600,82;...
      2000,80;...
      3000,78;...
      4000,79;...
      5000,84;...
      7000,90;...
      9000,93;...
      10000,93;...
      16000,85;...
      18000,84;...
      20000,90;...
	 ];
  L = interp1(log(data(:,1)),data(:,2),log(vF),'linear','extrap');
  