Stop trying to read from audio file if no data is available
As soon as libsndfile has finished reading a file it no longer returns any data. This can send the `render` method for `FileRenderer` into an infinite loop. This way if not enough data is available a partial buffer is returned.
This commit is contained in:
parent
289d7a56cd
commit
0cd33b8289
1 changed files with 6 additions and 3 deletions
|
@ -153,10 +153,13 @@ FilePlayer(path::String) = FilePlayer(af_open(path))
|
|||
function render(node::FileRenderer, device_input::AudioBuf, info::DeviceInfo)
|
||||
@assert node.file.sfinfo.samplerate == info.sample_rate
|
||||
|
||||
# Keep reading data from the file until the output buffer is full
|
||||
# Keep reading data from the file until the output buffer is full, but stop
|
||||
# as soon as no more data can be read from the file
|
||||
audio = Array(AudioSample, node.file.sfinfo.channels, 0)
|
||||
while size(audio, 2) < info.buf_size
|
||||
audio = hcat(audio, read(node.file, info.buf_size-size(audio, 2), AudioSample))
|
||||
read_audio = zeros(AudioSample, node.file.sfinfo.channels, 1)
|
||||
while size(audio, 2) < info.buf_size && size(read_audio, 2) > 0
|
||||
read_audio = read(node.file, info.buf_size-size(audio, 2), AudioSample)
|
||||
audio = hcat(audio, read_audio)
|
||||
end
|
||||
|
||||
if audio == Nothing
|
||||
|
|
Loading…
Reference in a new issue