bbx_dsp/
writer.rs

1//! Audio file writer trait.
2//!
3//! This module defines the [`Writer`] trait for writing audio file data.
4//! Implementations are provided by the `bbx_file` crate (e.g., WAV writer).
5
6use crate::sample::Sample;
7
8/// Trait for writing audio data to files.
9///
10/// Implementations handle encoding and file format specifics. Call
11/// [`finalize`](Self::finalize) when done to ensure proper file closure.
12pub trait Writer<S: Sample>: Send + Sync {
13    /// Get the sample rate of the writer.
14    fn sample_rate(&self) -> f64;
15
16    /// Get the number of channels of the writer.
17    fn num_channels(&self) -> usize;
18
19    /// Check whether the writer can write to audio an audio file. This
20    /// is useful for particular audio files that use closing byte signatures,
21    /// unlike WAV files which can usually be appended with more audio data
22    /// at any time.
23    fn can_write(&self) -> bool;
24
25    /// Write samples to a specified channel.
26    fn write_channel(&mut self, channel_index: usize, samples: &[S]) -> Result<(), Box<dyn std::error::Error>>;
27
28    /// Finalize the writing of an audio file.
29    fn finalize(&mut self) -> Result<(), Box<dyn std::error::Error>>;
30}