samer@0
|
1 function [Sched,GetData]=playaudio_async(Y,Snk,varargin)
|
samer@0
|
2 % playaudio_async - Play stream of audio data asynchronously
|
samer@0
|
3 %
|
samer@0
|
4 % playaudio ::
|
samer@0
|
5 % X:seq [[N]] ~'sequence of arrays',
|
samer@0
|
6 % R:nonneg ~'sampling rate',
|
samer@0
|
7 % options {
|
samer@0
|
8 % maxbuf :: natural/2*max(size(X)) ~'maximum buffer size';
|
samer@0
|
9 % hook :: (iterator(S)->iterator(T)) ~'fn to build iterator';
|
samer@0
|
10 % onstart :: A -> action ~'called BEFORE timer starts';
|
samer@0
|
11 % onstop :: A -> action ~'called AFTER timer stops';
|
samer@0
|
12 % onfinish:: A -> action ~'called when end of signal reached';
|
samer@0
|
13 % defer :: bool / 0 ~'if 1, don't start the timer'
|
samer@0
|
14 % }
|
samer@0
|
15 % -> sched(S) ~'scheduler api functions',
|
samer@0
|
16 % (S -> [[N]]) ~'function to recover audio from iterator state'.
|
samer@0
|
17 %
|
samer@0
|
18 % iterator(S) ::= cell {(S->action S)~'state transformer', S~'initial state'}.
|
samer@0
|
19 %
|
samer@0
|
20 % sched(S) ::= struct {
|
samer@0
|
21 % dispose :: unit -> action unit;
|
samer@0
|
22 % isrunning :: unit -> action bool;
|
samer@0
|
23 % startat :: real -> action unit;
|
samer@0
|
24 % start :: unit -> action unit;
|
samer@0
|
25 % stop :: unit -> action unit;
|
samer@0
|
26 % rewind :: unit -> action unit;
|
samer@0
|
27 % getstate :: unit -> action S;
|
samer@0
|
28 % setstate :: S -> action unit
|
samer@0
|
29 % }.
|
samer@0
|
30 %
|
samer@0
|
31 % The 'hook' option gives the caller an opportunity to elaborate on the
|
samer@0
|
32 % 'iterator' used to drive the audio playback. The 'iterator' is a cell
|
samer@0
|
33 % array contain a state transformer function and initial state. The caller
|
samer@0
|
34 % can use this to build a more complex iterator the does other things
|
samer@0
|
35 % for each buffer of samples.
|
samer@0
|
36 %
|
samer@0
|
37 % The third return value is a function which can be used in a state
|
samer@0
|
38 % transformer function to recover a buffer of audio samples from the
|
samer@0
|
39 % current state.
|
samer@0
|
40 %
|
samer@0
|
41 % NB: all the audio buffers must be the same size for this to work.
|
samer@0
|
42 % NB: the rewind function should only be called when the timer is stopped.
|
samer@0
|
43 [Sched,GetData]=playaudio_unfold(size(Y,2),@decons,Y,Snk),varargin{:});
|
samer@0
|
44 end
|