Fix errors with WAVs containing markers (#2617).
[dcpomatic.git] / src / lib / audio_buffers.cc
index 119a499b49e448d75647681dfef88b45c1a62723..0e31793ea2d7634035343fb2245e562af442b9a0 100644 (file)
@@ -81,7 +81,7 @@ void
 AudioBuffers::allocate (int channels, int frames)
 {
        DCPOMATIC_ASSERT (frames >= 0);
-       DCPOMATIC_ASSERT (channels > 0);
+       DCPOMATIC_ASSERT(frames == 0 || channels > 0);
 
        ScopeGuard sg = [this]() { update_data_pointers(); };
 
@@ -335,3 +335,22 @@ AudioBuffers::update_data_pointers ()
         }
 }
 
+
+/** Set a new channel count, either discarding data (if new_channels is less than the current
+ *  channels()), or filling with silence (if new_channels is more than the current channels()
+ */
+void
+AudioBuffers::set_channels(int new_channels)
+{
+       DCPOMATIC_ASSERT(new_channels > 0);
+
+       ScopeGuard sg = [this]() { update_data_pointers(); };
+
+       int const old_channels = channels();
+       _data.resize(new_channels);
+
+       for (int channel = old_channels; channel < new_channels; ++channel) {
+               _data[channel].resize(frames());
+       }
+}
+