Add test for audio delay, and do it in the player rather than the decoder.
[dcpomatic.git] / src / lib / audio_buffers.cc
index c3e89f1302e5315e01495c374a994975b19b806b..6d4eb85147545fab2a3610f86d285e944dd275b3 100644 (file)
@@ -144,6 +144,18 @@ AudioBuffers::make_silent (int c)
        }
 }
 
+void
+AudioBuffers::make_silent (int from, int frames)
+{
+       assert ((from + frames) <= _allocated_frames);
+
+       for (int c = 0; c < _channels; ++c) {
+               for (int i = from; i < (from + frames); ++i) {
+                       _data[c][i] = 0;
+               }
+       }
+}
+
 /** Copy data from another AudioBuffers to this one.  All channels are copied.
  *  @param from AudioBuffers to copy from; must have the same number of channels as this.
  *  @param frames_to_copy Number of frames to copy.
@@ -206,6 +218,9 @@ AudioBuffers::accumulate_channel (AudioBuffers const * from, int from_channel, i
        }
 }
 
+/** Ensure we have space for at least a certain number of frames.  If we extend
+ *  the buffers, fill the new space with silence.
+ */
 void
 AudioBuffers::ensure_size (int frames)
 {
@@ -218,6 +233,9 @@ AudioBuffers::ensure_size (int frames)
                if (!_data[i]) {
                        throw bad_alloc ();
                }
+               for (int j = _allocated_frames; j < frames; ++j) {
+                       _data[i][j] = 0;
+               }
        }
 
        _allocated_frames = frames;