Skip to content

Spatial sound calculates diff incorrectly (swaps left and right) #884

@strowk

Description

@strowk

In these formulas there is I think mistake that reverses lift/right:

https://github.com/RustAudio/rodio/blame/a352fb53846b47523d828b276b6d625f251aabb2/src/source/spatial.rs#L60-L62

        let left_diff_modifier = (((left_dist - right_dist) / max_diff + 1.0) / 4.0 + 0.5).min(1.0);
        let right_diff_modifier =
            (((right_dist - left_dist) / max_diff + 1.0) / 4.0 + 0.5).min(1.0);

It basically says that if "left_dist" (distance from emitter to "left" listener) is bigger - then modifier to left is bigger (farther - louder, which should be the other way around, i.e closer - louder).
And same for the right.

Essentially at close distances this results in swap in sound - left feels like right and vice versa..

I think it should be

        let left_diff_modifier = (((right_dist - left_dist) / max_diff + 1.0) / 4.0 + 0.5).min(1.0);
        let right_diff_modifier =
            (((left_dist - right_dist) / max_diff + 1.0) / 4.0 + 0.5).min(1.0);

It sort of appears to be obvious mistake in that code, am I missing something here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions