Add simple stereo-5.1 upmixer.
[dcpomatic.git] / src / lib / audio_decoder.cc
index 97a088791ad9bbe2c4b5e84cec227d016ce23175..e4f98c678ad3a150987431f7f587428a07603b10 100644 (file)
@@ -24,6 +24,7 @@
 #include "resampler.h"
 #include "util.h"
 #include "film.h"
+#include "audio_processor.h"
 
 #include "i18n.h"
 
@@ -43,13 +44,17 @@ AudioDecoder::AudioDecoder (shared_ptr<const AudioContent> content)
                _resampler.reset (new Resampler (content->audio_frame_rate(), content->resampled_audio_frame_rate(), content->audio_channels ()));
        }
 
+       if (content->audio_processor ()) {
+               _processor = content->audio_processor()->clone (content->resampled_audio_frame_rate ());
+       }
+
        reset_decoded_audio ();
 }
 
 void
 AudioDecoder::reset_decoded_audio ()
 {
-       _decoded_audio = ContentAudio (shared_ptr<AudioBuffers> (new AudioBuffers (_audio_content->audio_channels(), 0)), 0);
+       _decoded_audio = ContentAudio (shared_ptr<AudioBuffers> (new AudioBuffers (_audio_content->processed_audio_channels(), 0)), 0);
 }
 
 shared_ptr<ContentAudio>
@@ -125,6 +130,10 @@ AudioDecoder::audio (shared_ptr<const AudioBuffers> data, ContentTime time)
                data = _resampler->run (data);
        }
 
+       if (_processor) {
+               data = _processor->run (data);
+       }
+
        AudioFrame const frame_rate = _audio_content->resampled_audio_frame_rate ();
 
        if (_seek_reference) {
@@ -206,4 +215,7 @@ AudioDecoder::seek (ContentTime t, bool accurate)
        if (accurate) {
                _seek_reference = t;
        }
+       if (_processor) {
+               _processor->flush ();
+       }
 }