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

Optional override for global spatial scale #10419

Merged
merged 4 commits into from
Jan 25, 2024

Conversation

rparrett
Copy link
Contributor

@rparrett rparrett commented Nov 6, 2023

Objective

Fixes #10414.

That issue and its comments do a great job of laying out the case for this.

Solution

Added an optional spatial_scale field to PlaybackSettings, which overrides the default value set on AudioPlugin.

Changelog

  • AudioPlugin::spatial_scale has been renamed to default_spatial_scale.
  • SpatialScale is no longer a resource and is wrapped by DefaultSpatialScale.
  • Added an optional spatial_scale to PlaybackSettings.

Migration Guide

AudioPlugin::spatial_scale has been renamed to default_spatial_scale and the default spatial scale can now be overridden on individual audio sources with PlaybackSettings::spatial_scale.

If you were modifying or reading SpatialScale at run time, use DefaultSpatialScale instead.

// before
app.add_plugins(DefaultPlugins.set(AudioPlugin {
    spatial_scale: SpatialScale::new(AUDIO_SCALE),
    ..default()
}));

// after
app.add_plugins(DefaultPlugins.set(AudioPlugin {
    default_spatial_scale: SpatialScale::new(AUDIO_SCALE),
    ..default()
}));

@alice-i-cecile alice-i-cecile added A-Audio Sounds playback and modification C-Usability A simple quality-of-life change that makes Bevy easier to use labels Nov 7, 2023
@alice-i-cecile alice-i-cecile added this to the 0.13 milestone Nov 7, 2023
Copy link
Contributor

@Ixentus Ixentus left a comment

Choose a reason for hiding this comment

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

Ran the changed example and it worked as expected.

The changes makes sense and the code looks good. LGTM

crates/bevy_audio/src/audio_output.rs Outdated Show resolved Hide resolved
examples/audio/spatial_audio_2d.rs Outdated Show resolved Hide resolved
@rparrett
Copy link
Contributor Author

I will try to rebase this soon.

@rparrett
Copy link
Contributor Author

rparrett commented Jan 14, 2024

Maybe we also want to add a DefaultSpatialScale setting? I felt like doing this would be sort of ugly -- maybe requiring spatial_scale to be an Option, so I didn't do that.

Three months later, I feel like this might be worth the effort. Anyone have an opinion?

@Ixentus
Copy link
Contributor

Ixentus commented Jan 14, 2024

Maybe we also want to add a DefaultSpatialScale setting? I felt like doing this would be sort of ugly -- maybe requiring spatial_scale to be an Option, so I didn't do that.

Three months later, I feel like this might be worth the effort. Anyone have an opinion?

DefaultSpatialScale sounds like a good idea. Setting a ton of entities to the same value would be painful. Would it just be a Resource who's value would be used if .with_spatial(true) is used without .with_spatial_scale()? Where does the Option come in?

@rparrett
Copy link
Contributor Author

rparrett commented Jan 15, 2024

Yeah, I guess things would work more or less like before this PR for configuring the default scale, but PlaybackSettings would need to use an Option<SpatialScale> to make

used if .with_spatial(true) is used without .with_spatial_scale()

doable. But users wouldn't really have to deal with it, I guess. with_spatial_scale could still take a SpatialScale.

@rparrett
Copy link
Contributor Author

It was easier to just re-implement the changes than it was to fix merge conflicts, so I did that and added DefaultSpatialScale. That wasn't a super small change, so I'd appreciate a re-review.

@Ixentus
Copy link
Contributor

Ixentus commented Jan 16, 2024

Much more convenient. Went through it again and it looks great. Let's get this merged!

You might want to update the opening post, especially the changelog and migration guide since they get included in the release info.

@rparrett
Copy link
Contributor Author

Thanks for the reminder. The PR description should be up-to-date now. While updating the migration guide I found an opportunity to make this slightly less breaking by taking a SpatialScale instead of DefaultSpatialScale in AudioPlugin.

I wonder if the From<SpatialScale> impl is still useful?

@rparrett rparrett changed the title Make SpatialScale a property of audio sources instead of a global Resource Optionally override global spatial scale Jan 16, 2024
@rparrett rparrett changed the title Optionally override global spatial scale Optional override for global spatial scale Jan 16, 2024
@Ixentus
Copy link
Contributor

Ixentus commented Jan 17, 2024

Thanks for the reminder. The PR description should be up-to-date now. While updating the migration guide I found an opportunity to make this slightly less breaking by taking a SpatialScale instead of DefaultSpatialScale in AudioPlugin.

Very clean!

I wonder if the From<SpatialScale> impl is still useful?

Since users never need to construct a DefaultSpatialScale it doesn't seem useful anymore.

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jan 25, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jan 25, 2024
Merged via the queue into bevyengine:main with commit 2922476 Jan 25, 2024
23 checks passed
tjamaan pushed a commit to tjamaan/bevy that referenced this pull request Feb 6, 2024
# Objective

Fixes bevyengine#10414.

That issue and its comments do a great job of laying out the case for
this.

## Solution

Added an optional `spatial_scale` field to `PlaybackSettings`, which
overrides the default value set on `AudioPlugin`.

## Changelog

- `AudioPlugin::spatial_scale` has been renamed to
`default_spatial_scale`.
- `SpatialScale` is no longer a resource and is wrapped by
`DefaultSpatialScale`.
- Added an optional `spatial_scale` to `PlaybackSettings`.

## Migration Guide

`AudioPlugin::spatial_scale` has been renamed to `default_spatial_scale`
and the default spatial scale can now be overridden on individual audio
sources with `PlaybackSettings::spatial_scale`.

If you were modifying or reading `SpatialScale` at run time, use
`DefaultSpatialScale` instead.

```rust
// before
app.add_plugins(DefaultPlugins.set(AudioPlugin {
    spatial_scale: SpatialScale::new(AUDIO_SCALE),
    ..default()
}));

// after
app.add_plugins(DefaultPlugins.set(AudioPlugin {
    default_spatial_scale: SpatialScale::new(AUDIO_SCALE),
    ..default()
}));
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Audio Sounds playback and modification C-Usability A simple quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Spatial Audio Functional Regression - different spatial scaling factor for each object
3 participants