Skip to content

Bulk sample writing #84

Description

@kleinesfilmroellchen

In the old wav library, writing all of a file's samples in bulk was as easy as wav::write(header, i16_sample_buffer, write_impl). Even though this is not a flexible API (and hound even has the i16 specializations), in hound it's much more awkward:

let writer = WavWriter::new(&mut output_file, header)?;
let mut writer = writer.get_i16_writer(samples.len() as u32);
for s in samples {
	writer.write_sample(s);
}
writer.flush()?;

This also feels very inefficient to me. It's not easy for the compiler to see that on little-endian systems, the data can just be memcpy'd into WavWriter's buffer, or even directly into the output stream (i.e. this entire for loop should literally just be one system call on Linux).

I'd therefore like there to be a write_samples API for the WavWriter (and the 16-bit specialization) that takes &[Sample]. Straightforward enough, I hope.

A streaming design is less straightforward for many libraries, and they will always benefit from a bulk writing function since they already have all of the sample data available.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions