Struct hound::SampleWriter16 [] [src]

pub struct SampleWriter16<'parent, W> where
    W: Write + Seek + 'parent, 
{ /* fields omitted */ }

A writer that specifically only writes integer samples of 16 bits per sample.

The writer buffers written samples internally so they can be written in a single batch later on. This has two advantages when performance is important:

  • There is no need for error handling during writing, only on flush. This eliminates a lot of branches.
  • The buffer can be written once, which reduces the overhead of the write call. Because writing to an io::BufWriter is implemented with a memcpy (even for single bytes), there is a large overhead to writing small amounts of data such as a 16-bit sample. By writing large blocks (or by not using BufWriter) this overhead can be avoided.

A SampleWriter16 can be obtained by calling WavWriter::get_i16_writer.

Methods

impl<'parent, W: Write + Seek> SampleWriter16<'parent, W>
[src]

[src]

Writes a single sample for one channel.

WAVE interleaves channel data, so the channel that this writes the sample to depends on previous writes.

Unlike WavWriter::write_sample(), no range check is performed. Only the least significant 16 bits are considered, everything else is discarded. Apart from that check, this method is more efficient than WavWriter::write_sample(), because it can avoid dispatching on the number of bits. That was done already when the SampleWriter16 was constructed.

Note that nothing is actually written until flush() is called.

[src]

Like write_sample(), but does not perform a bounds check when writing to the internal buffer.

It is the responsibility of the programmer to ensure that no more samples are written than allocated when the writer was created.

[src]

Flush the internal buffer to the underlying writer.

Panics

Panics if insufficient samples (less than specified when the writer was constructed) have been written with write_sample().

Trait Implementations

Auto Trait Implementations

impl<'parent, W> Send for SampleWriter16<'parent, W> where
    W: Send

impl<'parent, W> Sync for SampleWriter16<'parent, W> where
    W: Sync