Use dcp::file_to_string().
[dcpomatic.git] / src / lib / audio_merger.h
index c9026b93eb99aedf131f0e68db54b148c839ee9f..07e730ce2048164fe658d8e1fa155462b9457d25 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 */
 
+
+/** @file  src/audio_merger.h
+ *  @brief AudioMerger class.
+ */
+
+
 #include "audio_buffers.h"
 #include "dcpomatic_time.h"
 #include "util.h"
 
+
+/** @class AudioMerger.
+ *  @brief A class that can merge audio data from many sources.
+ */
 class AudioMerger
 {
 public:
-       AudioMerger (int channels, int frame_rate);
+       explicit AudioMerger (int frame_rate);
 
-       /** Pull audio up to a given time; after this call, no more data can be pushed
-        *  before the specified time.
-        */
-       std::pair<boost::shared_ptr<AudioBuffers>, DCPTime> pull (DCPTime time);
-       void push (boost::shared_ptr<const AudioBuffers> audio, DCPTime time);
+       std::list<std::pair<std::shared_ptr<AudioBuffers>, dcpomatic::DCPTime>> pull (dcpomatic::DCPTime time);
+       void push (std::shared_ptr<const AudioBuffers> audio, dcpomatic::DCPTime time);
+       void clear ();
 
 private:
-       boost::shared_ptr<AudioBuffers> _buffers;
-       DCPTime _last_pull;
+       Frame frames (dcpomatic::DCPTime t) const;
+
+       class Buffer
+       {
+       public:
+               /** @param c Channels
+                *  @param f Frames
+                *  @param t Time
+                *  @param r Frame rate.
+                */
+               Buffer (int c, int32_t f, dcpomatic::DCPTime t, int r)
+                       : audio (new AudioBuffers (c, f))
+                       , time (t)
+                       , frame_rate (r)
+               {}
+
+               Buffer (std::shared_ptr<AudioBuffers> a, dcpomatic::DCPTime t, int r)
+                       : audio (a)
+                       , time (t)
+                       , frame_rate (r)
+               {}
+
+               std::shared_ptr<AudioBuffers> audio;
+               dcpomatic::DCPTime time;
+               int frame_rate;
+
+               dcpomatic::DCPTimePeriod period () const {
+                       return dcpomatic::DCPTimePeriod (time, time + dcpomatic::DCPTime::from_frames (audio->frames(), frame_rate));
+               }
+       };
+
+       std::list<Buffer> _buffers;
        int _frame_rate;
 };