Merge master.
[dcpomatic.git] / src / lib / audio_decoder.cc
index 8d3b0e1288ea5b53627a9cfb82619b0ccc125c7e..32453cc13c974d58218cf5dae9eb4eb6da5047d2 100644 (file)
@@ -23,7 +23,6 @@
 #include "log.h"
 #include "resampler.h"
 #include "util.h"
-#include "film.h"
 
 #include "i18n.h"
 
@@ -34,9 +33,8 @@ using std::cout;
 using boost::optional;
 using boost::shared_ptr;
 
-AudioDecoder::AudioDecoder (shared_ptr<const Film> film, shared_ptr<const AudioContent> content)
-       : Decoder (film)
-       , _audio_content (content)
+AudioDecoder::AudioDecoder (shared_ptr<const AudioContent> content)
+       : _audio_content (content)
 {
        if (content->output_audio_frame_rate() != content->content_audio_frame_rate() && content->audio_channels ()) {
                _resampler.reset (new Resampler (content->content_audio_frame_rate(), content->output_audio_frame_rate(), content->audio_channels ()));
@@ -58,14 +56,11 @@ AudioDecoder::audio (shared_ptr<const AudioBuffers> data, ContentTime time)
        }
 
        if (!_audio_position) {
-               shared_ptr<const Film> film = _film.lock ();
-               assert (film);
-               FrameRateChange frc = film->active_frame_rate_change (_audio_content->position ());
-               _audio_position = (double (time) / frc.speed_up) * film->audio_frame_rate() / TIME_HZ;
+               _audio_position = time;
        }
 
-       _pending.push_back (shared_ptr<DecodedAudio> (new DecodedAudio (data, _audio_position.get ())));
-       _audio_position = _audio_position.get() + data->frames ();
+       _pending.push_back (shared_ptr<DecodedAudio> (new DecodedAudio (_audio_position.get (), data)));
+       _audio_position = _audio_position.get() + ContentTime (data->frames (), _audio_content->output_audio_frame_rate ());
 }
 
 void
@@ -77,8 +72,8 @@ AudioDecoder::flush ()
 
        shared_ptr<const AudioBuffers> b = _resampler->flush ();
        if (b) {
-               _pending.push_back (shared_ptr<DecodedAudio> (new DecodedAudio (b, _audio_position.get ())));
-               _audio_position = _audio_position.get() + b->frames ();
+               _pending.push_back (shared_ptr<DecodedAudio> (new DecodedAudio (_audio_position.get (), b)));
+               _audio_position = _audio_position.get() + ContentTime (b->frames (), _audio_content->output_audio_frame_rate ());
        }
 }