Struct hound::WavWriter
[−]
[src]
pub struct WavWriter<W> where W: Write + Seek {
// some fields omitted
}
A writer that accepts samples and writes the WAVE format.
The writer needs a WavSpec
that describes the audio properties. Then
samples can be written with write_sample
. Channel data is interleaved.
The number of samples written must be a multiple of the number of channels.
After all samples have been written, the file must be finalized. This can
be done by calling finalize
. If finalize
is not called, the file will
be finalized upon drop. However, finalization may fail, and without calling
finalize
, such a failure cannot be observed.
Methods
impl<W> WavWriter<W> where W: Write + Seek
fn new(writer: W, spec: WavSpec) -> WavWriter<W>
Creates a writer that writes the WAVE format to the underlying writer.
The underlying writer is assumed to be at offset 0. WavWriter
employs
buffering internally to avoid too many write
calls to the underlying
writer.
fn write_sample<S: Sample>(&mut self, sample: S) -> Result<()>
Writes a single sample for one channel.
WAVE interleaves channel data, so the channel that this writes the
sample to depends on previous writes. This will return an error if the
sample does not fit in the number of bits specified in the WavSpec
.
fn finalize(self) -> Result<()>
Writes the parts of the WAVE format that require knowing all samples.
This method must be called after all samples have been written. If it is not called, the destructor will finalize the file, but any errors that occur in the process cannot be observed in that manner.
impl WavWriter<BufWriter<File>>
fn create<P: AsRef<Path>>(filename: P, spec: WavSpec) -> Result<WavWriter<BufWriter<File>>>
Creates a writer that writes the WAVE format to a file.
This is a convenience constructor that creates the file, wraps it in a
BufWriter
, and then constructs a WavWriter
from it. The file will
be overwritten if it exists.