Skip to content

Remove nbr_frames in AudioRenderClient::write_to_device() #84

Closed

Description

@LastExceed

Since the slice already stores its length, the nbr_frames parameter seems superfluous.

wasapi-rs/src/api.rs

Lines 2127 to 2153 in 9b3564e

pub fn write_to_device(
&self,
nbr_frames: usize,
data: &[u8],
buffer_flags: Option<BufferFlags>,
) -> WasapiRes<()> {
if nbr_frames == 0 {
return Ok(());
}
let nbr_bytes = nbr_frames * self.bytes_per_frame;
if nbr_bytes != data.len() {
return Err(WasapiError::DataLengthMismatch {
received: data.len(),
expected: nbr_bytes,
});
}
let bufferptr = unsafe { self.client.GetBuffer(nbr_frames as u32)? };
let bufferslice = unsafe { slice::from_raw_parts_mut(bufferptr, nbr_bytes) };
bufferslice.copy_from_slice(data);
let flags = match buffer_flags {
Some(bflags) => bflags.to_u32(),
None => 0,
};
unsafe { self.client.ReleaseBuffer(nbr_frames as u32, flags)? };
trace!("wrote {nbr_frames} frames");
Ok(())
}

Activity

  1. HEnquist commented on Oct 27, 2026

    @HEnquist
    Owner

    Thanks, yes you are right, that argument can be removed. It's been there since the first version of the library (where I probably just copied it over from the dequeue write method) and it was never needed. I'll just remove it. While looking at that I found some other minor inconsistencies that would be nice to fix as well. PR incoming!

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions