- AudioMerger (int channels, boost::function<F (T)> t_to_f, boost::function<T (F)> f_to_t)
- : _buffers (new AudioBuffers (channels, 0))
- , _last_pull (0)
- , _t_to_f (t_to_f)
- , _f_to_t (f_to_t)
- {}
-
- /** Pull audio up to a given time; after this call, no more data can be pushed
- * before the specified time.
- */
- TimedAudioBuffers<T>
- pull (T time)
- {
- assert (time >= _last_pull);
-
- TimedAudioBuffers<T> out;
-
- F const to_return = _t_to_f (time - _last_pull);
- out.audio.reset (new AudioBuffers (_buffers->channels(), to_return));
- /* And this is how many we will get from our buffer */
- F const to_return_from_buffers = min (to_return, _buffers->frames ());
-
- /* Copy the data that we have to the back end of the return buffer */
- out.audio->copy_from (_buffers.get(), to_return_from_buffers, 0, to_return - to_return_from_buffers);
- /* Silence any gap at the start */
- out.audio->make_silent (0, to_return - to_return_from_buffers);
-
- out.time = _last_pull;
- _last_pull = time;
-
- /* And remove the data we're returning from our buffers */
- if (_buffers->frames() > to_return_from_buffers) {
- _buffers->move (to_return_from_buffers, 0, _buffers->frames() - to_return_from_buffers);
- }
- _buffers->set_frames (_buffers->frames() - to_return_from_buffers);
-
- return out;
- }
-
- void
- push (boost::shared_ptr<const AudioBuffers> audio, T time)
- {
- assert (time >= _last_pull);