diff options
| author | Carl Hetherington <cth@carlh.net> | 2017-02-26 01:40:30 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2017-04-19 23:04:32 +0100 |
| commit | 58dce923b9d438a27ce1cd7e3125370f74d46e3a (patch) | |
| tree | 5a332a967aa3fb9bcb923f62b4832d8bb4d2bb17 /src/lib/audio_merger.h | |
| parent | e7e06b4c9a6bf4459ff27a30cf347121c0e40e07 (diff) | |
Fix merging of audio in various circumstances.
Diffstat (limited to 'src/lib/audio_merger.h')
| -rw-r--r-- | src/lib/audio_merger.h | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/src/lib/audio_merger.h b/src/lib/audio_merger.h index 6db28b6c3..87bda7f8b 100644 --- a/src/lib/audio_merger.h +++ b/src/lib/audio_merger.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2017 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 @@ -24,19 +24,54 @@ class AudioMerger { public: - AudioMerger (int channels, int frame_rate); + 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); + std::list<std::pair<boost::shared_ptr<AudioBuffers>, DCPTime> > pull (DCPTime time); void push (boost::shared_ptr<const AudioBuffers> audio, DCPTime time); - DCPTime last_pull () const { - return _last_pull; - } private: - boost::shared_ptr<AudioBuffers> _buffers; + class Buffer + { + public: + /** @param c Channels + * @param f Frames + * @param t Time + * @param r Frame rate. + */ + Buffer (int c, int32_t f, DCPTime t, int r) + : audio (new AudioBuffers (c, f)) + , time (t) + , frame_rate (r) + {} + + Buffer (boost::shared_ptr<AudioBuffers> a, DCPTime t, int r) + : audio (a) + , time (t) + , frame_rate (r) + {} + + boost::shared_ptr<AudioBuffers> audio; + DCPTime time; + int frame_rate; + + DCPTimePeriod period () const { + return DCPTimePeriod (time, time + DCPTime::from_frames (audio->frames(), frame_rate)); + } + }; + + class BufferComparator + { + public: + bool operator() (AudioMerger::Buffer const & a, AudioMerger::Buffer const & b) + { + return a.time < b.time; + } + }; + + std::list<Buffer> _buffers; DCPTime _last_pull; int _frame_rate; }; |
