-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Support decibels in bevy_audio::Volume #17605
Conversation
Co-authored-by: Zachary Harrold <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I went into the territory of bikeshedding, but I have some comments on this, which maybe warrants a new pass at the PR.
I think the points in the previous review should be addressed. I agree with the problems they pointed out. |
Co-authored-by: Zachary Harrold <[email protected]>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nicely made, and really clear, excellent docs. This is something that I think will be kept around even after swapping backends.
Objective
Volume
type from newtyping anf32
to an enum withLinear
andDecibels
variants.VolumeLevel
to use Decibel and Amplitude Ratio Units #9582.Solution
Compared to #9582, this PR has the following main differences:
ops
for doingVolume
arithmetic. Can add two volumes, e.g. to increase/decrease the current volume. Can multiply two volumes, e.g. to get the “effective” volume of an audio source considering global volume.Testing
cargo run --example soundtrack
.cargo run --example audio_control
.cargo run --example spatial_audio_2d
.cargo run --example spatial_audio_3d
.cargo run --example pitch
.cargo run --example decodable
.cargo run --example audio
.Migration Guide
Audio volume can now be configured using decibel values, as well as using linear scale values. To enable this, some types and functions in
bevy_audio
have changed.Volume
is now an enum withLinear
andDecibels
variants.Before:
After:
Volume::ZERO
has been renamed to the more semantically correctVolume::SILENT
becauseVolume
now supports decibels and "zero volume" in decibels actually means "normal volume".AudioSinkPlayback
trait's volume-related methods now deal withVolume
types rather thanf32
s.AudioSinkPlayback::volume()
now returns aVolume
rather than anf32
.AudioSinkPlayback::set_volume
now receives aVolume
rather than anf32
. This affects theAudioSink
andSpatialAudioSink
implementations of the trait. The previousf32
values are equivalent to the volume converted to linear scale so theVolume:: Linear
variant should be used to migrate betweenf32
s andVolume
.GlobalVolume::new
function now receives aVolume
instead of anf32
.