% audio_norm - Arrow to do audio loudness normalisation using arbitrary estimator
function o= audio_norm(src,fs,N,M,W,Lag,dynorm,varargin)
	opts=options('spectra',1,'lim',[-6,-1],'play',0,varargin{:});

	if opts.spectra, 
		spectra=@(f,clim)obs_with(aspectrum(N)*arr(@log10)*imager('clim',clim,'fig',f));
	else 
		spectra=@(f,clim)aid;
	end

	if opts.play
		player = arr(@(x)flatten(x(1:M,:))) * audioout(linesink(1,fs));
	else 
		player = aid;
	end

	o = audioin(src,N,M,W) ...
	  * spectra(13,[-11,1]) ...
	  * dup * ( ...
		    arr(@flatten)*dup*( ...
				arr(@(t)log(mean(abs(t))))*delay(Lag-1,nan) ...    % instantaneous log scale
				+ dynorm(Lag) ...     % estimated log scale
			 ) ...
		    * arr(@(a,b)[a;b]) ...      % combine
			 * obs_with(scope(128,'fig',11,'ylim',opts.lim)) ... % plot both on top of each other
			 * arr(@(t)t(2)) ...         % pick out dynorm_lap value
		  + delay(Lag-1,0) ...            % delay audio same amount as scale signal
		  ) ...
	  * arr(@(ls,x)0.03*x*exp(-ls)) ...     % divide audio buffer by scale
	  * spectra(15,[-6,6]) ...
	  * player;
