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