From 9ecac99df40d0b5aa68141df8c0a63e1cc975b18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Mon, 30 Jul 2018 13:31:58 +0200 Subject: [PATCH] Push silence to offline sink if nothing reaches the output --- audio/src/block.rs | 4 ++++ audio/src/offline_sink.rs | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/audio/src/block.rs b/audio/src/block.rs index ee8f9d3e..8ce86970 100644 --- a/audio/src/block.rs +++ b/audio/src/block.rs @@ -425,6 +425,10 @@ impl Block { } vec } + + pub fn is_empty(&self) -> bool { + self.buffer.is_empty() + } } /// An iterator over frames in a block diff --git a/audio/src/offline_sink.rs b/audio/src/offline_sink.rs index 60012047..295c8176 100644 --- a/audio/src/offline_sink.rs +++ b/audio/src/offline_sink.rs @@ -54,13 +54,19 @@ impl AudioSink for OfflineAudioSink { || (self.rendered_blocks.get() >= (self.length / FRAMES_PER_BLOCK_USIZE)) } - fn push_data(&self, chunk: Chunk) -> Result<(), ()> { + fn push_data(&self, mut chunk: Chunk) -> Result<(), ()> { { let offset = self.rendered_blocks.get() * FRAMES_PER_BLOCK_USIZE; let mut buffer = self.buffer.borrow_mut(); if buffer.is_none() { *buffer = Some(vec![0.; self.channel_count * self.length]); } + if chunk.len() == 0 { + chunk.blocks.push(Default::default()); + } + if chunk.blocks[0].is_empty() { + chunk.blocks[0].explicit_silence(); + } if let Some(ref mut buffer) = *buffer { for channel_number in 0..self.channel_count { let channel_offset = offset + (channel_number * self.length);