view arrows/audio_bench1.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents beb8a3f4a345
children
line wrap: on
line source
% audio_bench1 - supply audio to given arrow 
%
% audio_bench :: 
%    N:natural  ~'audio frame size',
%    M:natural  ~'audio hop size',
%    list(string) ~'list of audio file names',
%    arrow({[[N,W]]}, Outputs, S) ~'arrow to process audio buffers',
%    options {
%       fs      :: nonneg/22050 ~'audio sampling rate';
%       scope   :: natural/0    ~'figure for waveform plot, 0 to disable';
%       batch   :: natural/1 ~'width of buffers';
%       state   :: S/[]      ~'initialise with this state';
%       outbuf  :: natural/2 ~'increase audio output buffer by this many frames';
%       run     :: bool/0    ~'if true, run the arrow in arrow_sched';
%       start   :: bool/1    ~'if running and true, start immediately';
%       period  :: nonneg/0.003 ~'if running timer period in seconds';
%       liveaudio :: bool/0 ~'if true, ignore files and use live audio input';
%    }
% -> arrow( {}, Outputs, T) ~'arrow describing whole system',
%    [[1,P]->[2]}      ~'path to state S in overall state T',
%    T,                ~'final state if returned from repl'.
%
% This provides an environment for running an audio processing arrow.
% Audio is provided in NxW buffers where N is the frame length and W is determined
% by the batch options. Hop size is M. Audio is obtained from the given list of files.
%
% The processing arrow is initially run as fast as possible, but if the value in the
% 'output select' is changed from 1 to 2, output is played on audio output device.
% If it is set to 3, the original audio input is played unmodified.
%
% If the 'liveaudio' option is set, then the list of files is ignored and live audio
% input used instead.
%
% If 'run' is false, the arrow describing the system is returned, but if true, the
% system is instantiated using arrow_sched and the user dropped into the 'with_sched>>'
% interactive interpreter loop. The loop can be exitted by typing 'return' or 'ret(...)'.
% If 'ret(..)' is used, then the value supplied is returned as the second return value
% from audio_bench.

function [o,path]=audio_bench(N,M,filelist,a,varargin)
	opts=options('fs',22050,'batch',1,'liveaudio',0,varargin{:});

	fprintf('Creating audio source with %d files.\n',length(filelist));
	if opts.liveaudio
		src=linein(1,opts.fs,'bufsize',4*N);
	else
		src=resamplex(opts.fs,map(@monofile,filelist),'bs',2^nextpow2(M*opts.batch));
	end
	o= abufsig(src,N,M,opts.batch) * a; 
	path=[2]; % path to state of a in state of o 
end