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

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.

Implementations

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.

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.

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().

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.