Ability to set a Global Volume
Objective
Adds a new resource to control a global volume. Fixes #7690
Solution
Added a new resource to control global volume, this is then multiplied with an audio sources volume to get the output volume, individual audio sources can opt out of this my enabling the absolute_volume field in PlaybackSettings.
Changelog
Added
-
GlobalVolumea resource to control global volume (in prelude). -
global_volumefield toAudioPluginor setting the initial value ofGlobalVolume. -
Volumeenum that can beRelativeorAbsolute. -
VolumeLevelstruct for defining a volume level.
This also opens the opportunity to fix the issue in the decodable audio example being very loud by adding .insert_resource(GlobalVolume::new(0.2)) to it. Tested it and it works.
Changing the global volume should change the sounds already playing that have been set relative to it.
Agreed, but this may not be trivial. Docs would be fine for me as a start.
I think I would prefer an enum for the volume instead of having two fields, but I'm not completely sure on that.
This is nice :)
Enum for volume makes a lot of sense, I'll have a go at changing the volume of already playing sounds. Would something like this work
pub enum Volume {
Absolute(f32),
Relative(f32),
}
That looks perfect. Ideally we could document what the f32 means, or use a more sensible numeric type too. Negative volumes don't exactly make sense to me.
Is there a way in rust to have positive only floats?
Is there a way in rust to have positive only floats?
I would newtype here and use a constructor method.
I've added the volume enum but using the newtype for the volume level feels too verbose imo, some thoughts on this would be great. I also added the global volume as a field in the audio struct so you can set it using the .set() method on the plugin group.
Changing the global volume should change the sounds already playing that have been set relative to it.
Updating the volume for AudioSinks that have not been detached is easy, but I am unsure of how to update ones which have been detached (have no strong handle) so for now I will add message mentioning that only new sounds will be impacted.
I'm glad to see this added. Merging now, we can refine later as needed.