Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Comment Inconsistency #540

Open
YichiZhang0613 opened this issue Dec 6, 2024 · 1 comment
Open

Code Comment Inconsistency #540

YichiZhang0613 opened this issue Dec 6, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@YichiZhang0613
Copy link

In web-audio-api-rs-main/src/node/channel_merger.rs, the comment indicates code will panic when count <= 2, while the code will panic when count != 1.

/// # Panics
///
/// This function panics if given count is greater than 2
///
#[track_caller]
#[inline(always)]
fn assert_valid_channel_count(count: usize) {
    assert!(
        count == 1,
        "InvalidStateError - channel count of ChannelMergerNode must be equal to 1"
    );
}

In web-audio-api-rs-main/src/lib.rs

/// # Panics
///
/// This function will panic if:
/// - the given sample rate is lower than 4000 or greater than 192000
///
#[track_caller]
#[inline(always)]
pub(crate) fn assert_valid_sample_rate(sample_rate: f32) {
    // Arbitrary cutoffs defined as:
    // min_sample_rate = min_required_in_spec / 4
    // max_sample_rate = max_required_in_spec * 4
    let min_sample_rate = 2_000.;
    let max_sample_rate = 384_000.;

    assert!(
        sample_rate >= min_sample_rate && sample_rate <= max_sample_rate,
        "NotSupportedError - Invalid sample rate: {:?}, should be in the range [{:?}, {:?}]",
        sample_rate,
        min_sample_rate,
        max_sample_rate,
    );
}

In web-audio-api-rs-new-main/src/node/panner.rs, the comment indicates code will panic when value < 0.0, while the code will panic when value <= 0.0 .

/// # Panics
///
/// Panics if the provided value is negative.
pub fn set_max_distance(&mut self, value: f64) {
    assert!(value > 0., "RangeError - maxDistance must be positive");
    self.max_distance = value;
    self.registration
        .post_message(ControlMessage::MaxDistance(value));
}
@orottier
Copy link
Owner

Hi @YichiZhang0613, thanks for flagging this. We will need to update the comments to reflect the actual code

@orottier orottier added documentation Improvements or additions to documentation good first issue Good for newcomers labels Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants