12
12
% valid : Input data valid flag.
14
% f=BLOCKREAD(L) reads next L audio samples according to source
15
% specified in BLOCK. f is a LxW matrix, where columns are
16
% channels in the stream.
18
% [f,valid]=blockrad(...) does the same and in addition it returns valid*
19
% flag, which is set to 1, except for the last block of the stream (e.g.
20
% at the end of a file).
14
22
% Function also control the playback, so it does not have to rely on
15
23
% whether the user called BLOCKPLAY.
17
25
% Block streaming uses several buffers to compensate for the processing
20
%@strong{Url}: @url{http://ltfat.sourceforge.net/doc/blockproc/blockread.php}
30
%@strong{Url}: @url{http://ltfat.github.io/doc/blockproc/blockread.html}
31
%@seealso{block, blockplay}
23
% Copyright (C) 2005-2014 Peter L. Soendergaard <soender@users.sourceforge.net>.
24
% This file is part of LTFAT version 2.0.1
34
% Copyright (C) 2005-2015 Peter L. Soendergaard <peter@sonderport.dk>.
35
% This file is part of LTFAT version 2.1.0
26
37
% This program is free software: you can redistribute it and/or modify
27
38
% it under the terms of the GNU General Public License as published by
199
212
elseif isa(source,'function_handle')
200
213
% Number of wav samples (is chached, since it is a disk read operation)
201
214
Lwav = block_interface('getLs');
215
% Internal data pointer for audio data
216
pos = block_interface('getDatapos') +1;
217
block_interface('setDatapos',pos+L-1);
203
219
% Determine valid samples
204
220
endSample = min(pos + L - 1, Lwav(1));
205
221
%f = cast(wavread(source,[pos, endSample]),block_interface('getClassId'));
206
f = source(pos,endSample);
222
f = cast(source(pos,endSample),classid);
207
223
% Pad with zeros if some samples are missing
208
224
if (pos + L - 1) >= Lwav(1)
209
225
ftmp = zeros(L,Lwav(2),classid);
212
228
% Rewind if loop option was set.
213
229
if block_interface('getIsLoop')
214
block_interface('setPos',0);
230
block_interface('setDatapos',0);
215
231
% Throw away stored overlaps.
216
232
if ~isempty(block_interface('getAnaOverlap'))
217
233
block_interface('setAnaOverlap',[]);
259
275
while(playrec('isFinished', pageId) == 0), end;
279
%% {'rec',...} Recording while playing
281
elseif iscell(source)
282
recChanList = block_interface('getRecChanList');
283
playChanList = block_interface('getPlayChanList');
284
if do_updateBAR || do_updateGUI
289
Lwav = block_interface('getLs');
291
% Issue reading buffers up to max
292
while block_interface('getEnqBufCount') <= block_interface('getBufCount')
293
% Internal data pointer for audio data
294
pos = block_interface('getDatapos') +1;
295
block_interface('setDatapos',pos+L-1);
297
% Determine valid samples
298
endSample = min(pos + L - 1, Lwav(1));
299
%f = cast(wavread(source,[pos, endSample]),block_interface('getClassId'));
300
fin = source(pos,endSample);
301
% Pad with zeros if some samples are missing
302
if (pos + L - 1) >= Lwav(1)
303
ftmp = zeros(L,Lwav(2),classid);
304
ftmp(1:size(fin,1),:) = fin;
306
% Rewind if loop option was set.
307
if block_interface('getIsLoop')
308
block_interface('setDatapos',0);
309
% Throw away stored overlaps.
310
if ~isempty(block_interface('getAnaOverlap'))
311
block_interface('setAnaOverlap',[]);
313
if ~isempty(block_interface('getSynOverlap'))
314
block_interface('setSynOverlap',[]);
321
% Broadcast single input channel to all output chanels.
323
fin = repmat(fin,1,numel(playChanList));
326
block_interface('pushPage',playrec('playrec', fin, playChanList, -1,...
331
pageList = block_interface('getPageList');
332
% Block until the first page is loaded
333
while(playrec('isFinished', pageList(1)) == 0)
335
% Read the data. Cast to the specified type
336
f = cast(playrec('getPlayrec',pageList(1)),classid);
338
playrec('delPage', pageList(1));
339
% Throw away the page id
340
block_interface('popPage');