Skip to content

Conversation

roderickvd
Copy link
Member

We already had Sample::sample_size() which returns the size in bytes of a format. This does not always correspond with the number of bits. For example, I24 is stored in 4 bytes but with 24 bits storing audio, not 32. This PR introduces a new function Sample::bits_per_sample() to do that.

For F32 or F64 we could argue what it should return. This method returns 32/64 bits of bit depth (storage) instead of 24/58 bits of precision (effective resolution).

@roderickvd roderickvd requested a review from Copilot September 4, 2025 19:47
@roderickvd roderickvd self-assigned this Sep 4, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new method bits_per_sample() to the SampleFormat enum to distinguish between storage size and actual bit depth. The key motivation is that some formats like I24 use 4 bytes for storage but only 24 bits for audio data.

  • Adds SampleFormat::bits_per_sample() method that returns the actual audio bit depth
  • Refactors sample_size() method to use explicit type-specific mem::size_of calls instead of grouped patterns
  • Updates documentation to clarify the distinction between quantized sampling depth and storage formats

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/samples_formats.rs Adds new bits_per_sample() method and refactors sample_size() for clarity
CHANGELOG.md Documents the new Sample::bits_per_sample method

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@roderickvd roderickvd merged commit f7206e9 into master Sep 7, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant