From 799b352dd81b711e96d8627f2022e50a5e5f037f Mon Sep 17 00:00:00 2001 From: Colin S <3526918+cbs228@users.noreply.github.com> Date: Thu, 1 Feb 2024 22:24:46 -0600 Subject: [PATCH] samedec: flush on EOF in main app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, `samedec::app::run()` would unceremoniously exit on EOF. Since an EOF results in samples being "stranded" in filter buffers and other parts of the system, it is necessary to push zeros through the system to make it output any remaining Messages. This "flush" operation was performed by isolated code that ran after the app terminated. This would print the Message(s), but it would not take any other actions like spawning child processes. We should spawn the child even if there's no audio data that follows. The state machine will simply `wait()` for it to terminate and then exit. This change permits us to run child processes on short snippets of SAME data—i.e., our `sample/*.bin` data files. This is CLI-expanding behavior. --- crates/samedec/src/app.rs | 3 ++- crates/samedec/src/main.rs | 10 ---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/crates/samedec/src/app.rs b/crates/samedec/src/app.rs index bf6bfc1..93bcbdc 100644 --- a/crates/samedec/src/app.rs +++ b/crates/samedec/src/app.rs @@ -114,7 +114,8 @@ impl State { return Some(msg.into()); } - None + // end of file; flush any remaining messages out of the decoder + Some(receiver.flush()?.into()) } } diff --git a/crates/samedec/src/main.rs b/crates/samedec/src/main.rs index 1c5bffd..591e31f 100644 --- a/crates/samedec/src/main.rs +++ b/crates/samedec/src/main.rs @@ -48,16 +48,6 @@ fn samedec() -> Result<(), CliError> { std::iter::from_fn(|| Some(inbuf.read_i16::().ok()?)), ); - // flush all data samples out of the decoder - match rx.flush() { - Some(lastmsg) => { - if !args.quiet { - println!("{}", lastmsg) - } - } - None => {} - } - Ok(()) }