Skip to content

Commit

Permalink
samedec: flush on EOF in main app
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cbs228 committed Feb 2, 2024
1 parent 59ececa commit 799b352
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
3 changes: 2 additions & 1 deletion crates/samedec/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ impl State<Waiting> {
return Some(msg.into());
}

None
// end of file; flush any remaining messages out of the decoder
Some(receiver.flush()?.into())
}
}

Expand Down
10 changes: 0 additions & 10 deletions crates/samedec/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ fn samedec() -> Result<(), CliError> {
std::iter::from_fn(|| Some(inbuf.read_i16::<NativeEndian>().ok()?)),
);

// flush all data samples out of the decoder
match rx.flush() {
Some(lastmsg) => {
if !args.quiet {
println!("{}", lastmsg)
}
}
None => {}
}

Ok(())
}

Expand Down

0 comments on commit 799b352

Please sign in to comment.