X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fsndfile_decoder.cc;h=432f73f0d66f5b30e6c8068a13266719cf9c197b;hb=ff1ab29c3ea270061a54bde529270953e14b9adc;hp=80a6afd2baf79eae384164a310119a127e21c5bf;hpb=89115db77729a2c99f1a09ff6a461720e16f889e;p=dcpomatic.git diff --git a/src/lib/sndfile_decoder.cc b/src/lib/sndfile_decoder.cc index 80a6afd2b..432f73f0d 100644 --- a/src/lib/sndfile_decoder.cc +++ b/src/lib/sndfile_decoder.cc @@ -35,11 +35,12 @@ using boost::shared_ptr; SndfileDecoder::SndfileDecoder (shared_ptr f, shared_ptr c) : Decoder (f) - , AudioDecoder (f) + , AudioDecoder (f, c) , _sndfile_content (c) , _deinterleave_buffer (0) { - _sndfile = sf_open (_sndfile_content->file().string().c_str(), SFM_READ, &_info); + _info.format = 0; + _sndfile = sf_open (_sndfile_content->path(0).string().c_str(), SFM_READ, &_info); if (!_sndfile) { throw DecodeError (_("could not open audio file for reading")); } @@ -54,9 +55,13 @@ SndfileDecoder::~SndfileDecoder () delete[] _deinterleave_buffer; } -void +bool SndfileDecoder::pass () { + if (_remaining == 0) { + return true; + } + /* Do things in half second blocks as I think there may be limits to what FFmpeg (and in particular the resampler) can cope with. */ @@ -89,9 +94,11 @@ SndfileDecoder::pass () } data->set_frames (this_time); - audio (data, double(_done) / audio_frame_rate()); + audio (data, _done * TIME_HZ / audio_frame_rate ()); _done += this_time; _remaining -= this_time; + + return true; } int @@ -112,8 +119,11 @@ SndfileDecoder::audio_frame_rate () const return _info.samplerate; } -bool -SndfileDecoder::done () const +void +SndfileDecoder::seek (ContentTime t, bool accurate) { - return _audio_position >= _sndfile_content->audio_length (); + Decoder::seek (t, accurate); + + _done = t * audio_frame_rate() / TIME_HZ; + _remaining = _info.frames - _done; }