Re-add missing audio mapping in butler for preview.
[dcpomatic.git] / src / lib / util.cc
index 0ce538cdff2429fbd4f571a57e14e292faddef8e..4ffe3bd12bb8ed4f76092286f8aad08ce4fe0691 100644 (file)
@@ -36,6 +36,7 @@
 #include "digester.h"
 #include "audio_processor.h"
 #include "compose.hpp"
+#include "audio_buffers.h"
 #include <dcp/locale_convert.h>
 #include <dcp/util.h>
 #include <dcp/raw_convert.h>
@@ -735,3 +736,25 @@ audio_channel_types (list<int> mapped, int channels)
 
        return make_pair (non_lfe, lfe);
 }
+
+shared_ptr<AudioBuffers>
+remap (shared_ptr<const AudioBuffers> input, int output_channels, AudioMapping map)
+{
+       shared_ptr<AudioBuffers> mapped (new AudioBuffers (output_channels, input->frames()));
+       mapped->make_silent ();
+
+       for (int i = 0; i < map.input_channels(); ++i) {
+               for (int j = 0; j < mapped->channels(); ++j) {
+                       if (map.get (i, static_cast<dcp::Channel> (j)) > 0) {
+                               mapped->accumulate_channel (
+                                       input.get(),
+                                       i,
+                                       static_cast<dcp::Channel> (j),
+                                       map.get (i, static_cast<dcp::Channel> (j))
+                                       );
+                       }
+               }
+       }
+
+       return mapped;
+}