samer@2
|
1 % audio_bench1 - supply audio to given arrow
|
samer@0
|
2 %
|
samer@0
|
3 % audio_bench ::
|
samer@0
|
4 % N:natural ~'audio frame size',
|
samer@0
|
5 % M:natural ~'audio hop size',
|
samer@0
|
6 % list(string) ~'list of audio file names',
|
samer@2
|
7 % arrow({[[N,W]]}, Outputs, S) ~'arrow to process audio buffers',
|
samer@0
|
8 % options {
|
samer@0
|
9 % fs :: nonneg/22050 ~'audio sampling rate';
|
samer@0
|
10 % scope :: natural/0 ~'figure for waveform plot, 0 to disable';
|
samer@0
|
11 % batch :: natural/1 ~'width of buffers';
|
samer@0
|
12 % state :: S/[] ~'initialise with this state';
|
samer@0
|
13 % outbuf :: natural/2 ~'increase audio output buffer by this many frames';
|
samer@0
|
14 % run :: bool/0 ~'if true, run the arrow in arrow_sched';
|
samer@0
|
15 % start :: bool/1 ~'if running and true, start immediately';
|
samer@0
|
16 % period :: nonneg/0.003 ~'if running timer period in seconds';
|
samer@0
|
17 % liveaudio :: bool/0 ~'if true, ignore files and use live audio input';
|
samer@0
|
18 % }
|
samer@2
|
19 % -> arrow( {}, Outputs, T) ~'arrow describing whole system',
|
samer@0
|
20 % [[1,P]->[2]} ~'path to state S in overall state T',
|
samer@0
|
21 % T, ~'final state if returned from repl'.
|
samer@0
|
22 %
|
samer@0
|
23 % This provides an environment for running an audio processing arrow.
|
samer@0
|
24 % Audio is provided in NxW buffers where N is the frame length and W is determined
|
samer@0
|
25 % by the batch options. Hop size is M. Audio is obtained from the given list of files.
|
samer@0
|
26 %
|
samer@0
|
27 % The processing arrow is initially run as fast as possible, but if the value in the
|
samer@0
|
28 % 'output select' is changed from 1 to 2, output is played on audio output device.
|
samer@0
|
29 % If it is set to 3, the original audio input is played unmodified.
|
samer@0
|
30 %
|
samer@0
|
31 % If the 'liveaudio' option is set, then the list of files is ignored and live audio
|
samer@0
|
32 % input used instead.
|
samer@0
|
33 %
|
samer@0
|
34 % If 'run' is false, the arrow describing the system is returned, but if true, the
|
samer@0
|
35 % system is instantiated using arrow_sched and the user dropped into the 'with_sched>>'
|
samer@0
|
36 % interactive interpreter loop. The loop can be exitted by typing 'return' or 'ret(...)'.
|
samer@0
|
37 % If 'ret(..)' is used, then the value supplied is returned as the second return value
|
samer@0
|
38 % from audio_bench.
|
samer@0
|
39
|
samer@0
|
40 function [o,path]=audio_bench(N,M,filelist,a,varargin)
|
samer@37
|
41 opts=options('fs',22050,'batch',1,'liveaudio',0,varargin{:});
|
samer@0
|
42
|
samer@0
|
43 fprintf('Creating audio source with %d files.\n',length(filelist));
|
samer@0
|
44 if opts.liveaudio
|
samer@0
|
45 src=linein(1,opts.fs,'bufsize',4*N);
|
samer@0
|
46 else
|
samer@0
|
47 src=resamplex(opts.fs,map(@monofile,filelist),'bs',2^nextpow2(M*opts.batch));
|
samer@0
|
48 end
|
samer@0
|
49 o= abufsig(src,N,M,opts.batch) * a;
|
samer@0
|
50 path=[2]; % path to state of a in state of o
|
samer@0
|
51 end
|