Stop SndfileDecoder with no audio emitting lots of silence.
authorCarl Hetherington <cth@carlh.net>
Tue, 7 May 2013 20:02:13 +0000 (21:02 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 7 May 2013 20:02:13 +0000 (21:02 +0100)
src/lib/sndfile_decoder.cc

index fdaf2eeaaf4397ad5d1cb1430ebc6d006607a5b7..d70478a1bb7c0c698ef3484ebad4694a0add6055 100644 (file)
@@ -102,14 +102,20 @@ SndfileDecoder::pass ()
        sf_count_t const block = _audio_stream->sample_rate() / 2;
        shared_ptr<AudioBuffers> audio (new AudioBuffers (_audio_stream->channels(), block));
        sf_count_t const this_time = min (block, _frames - _done);
+       bool have_sound = false;
        for (size_t i = 0; i < _sndfiles.size(); ++i) {
                if (!_sndfiles[i]) {
                        audio->make_silent (i);
                } else {
                        sf_read_float (_sndfiles[i], audio->data(i), this_time);
+                       have_sound = true;
                }
        }
 
+       if (!have_sound) {
+               return true;
+       }
+
        audio->set_frames (this_time);
        Audio (audio, double(_done) / _audio_stream->sample_rate());
        _done += this_time;