% sonify_formant - sonify using formant synthesis
function Y=sonify_formant(Controllers,S,varargin)

	opts=options('bpm',240,'fs',11025,'buffer',0.125,'q',0.05,'cfilter',[],varargin{:});

	CC = cellmap(@(f)f/opts.fs,Controllers);
	f0 = window(map(@getf0,S));
	fx = window(map(@getfx,S));

	if ~isempty(opts.cfilter)
		f0 = filter(opts.cfilter{1},opts.cfilter{2},f0);
		fx = filter(opts.cfilter{1},opts.cfilter{2},fx,[],2);
	end
	Y  = formant_synth(256,opts.q,0.2,f0,fx);

	% rebuffer to constant size
	if ~isempty(opts.buffer)
		Y=windowdata(Y,ceil(opts.buffer*opts.fs));
	end

	function z=getf0(s),z=CC{s}(:,1)'; end
	function z=getfx(s),z=CC{s}(:,2:end)'; end
end
