From 5061cb718824e21e8dc7f17f351f9274053a93b9 Mon Sep 17 00:00:00 2001 From: Niklas Eicker Date: Wed, 6 Sep 2023 21:36:49 +0200 Subject: [PATCH] Multiply instance volume with channel volume --- CHANGELOG.md | 2 ++ examples/multiple_channels.rs | 6 +++--- examples/spacial.rs | 2 +- src/audio.rs | 9 +++++++-- src/audio_output.rs | 10 +++++----- src/channel/typed.rs | 2 +- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ecdb7e..1eacfd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +- Multiply instance volume with channel volume ([#103](https://github.com/NiklasEi/bevy_kira_audio/issues/103)) + ## v0.16.0 - Update to Bevy `0.11` - Spacial audio improvements ([#94](https://github.com/NiklasEi/bevy_kira_audio/pull/94)) diff --git a/examples/multiple_channels.rs b/examples/multiple_channels.rs index ca3a34d..97695ea 100644 --- a/examples/multiple_channels.rs +++ b/examples/multiple_channels.rs @@ -247,7 +247,7 @@ impl Default for ChannelAudioState { stopped: true, loop_started: false, paused: false, - _marker: PhantomData::::default(), + _marker: PhantomData::, } } } @@ -363,7 +363,7 @@ fn build_button_row( NORMAL_BUTTON.into(), ChangeVolumeButton:: { louder: true, - _marker: PhantomData::default(), + _marker: PhantomData, }, font.clone(), ); @@ -373,7 +373,7 @@ fn build_button_row( NORMAL_BUTTON.into(), ChangeVolumeButton:: { louder: false, - _marker: PhantomData::default(), + _marker: PhantomData, }, font.clone(), ); diff --git a/examples/spacial.rs b/examples/spacial.rs index 953046f..4533985 100644 --- a/examples/spacial.rs +++ b/examples/spacial.rs @@ -210,7 +210,7 @@ fn player_look( mut query: Query<&mut Transform, With>, ) { if let Ok(window) = primary_window.get_single() { - let mut delta_state = state.as_mut(); + let delta_state = state.as_mut(); for mut transform in query.iter_mut() { for ev in delta_state.reader_motion.iter(&motion) { match window.cursor.grab_mode { diff --git a/src/audio.rs b/src/audio.rs index 0c8d330..8501e0a 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -114,7 +114,12 @@ impl PartialSoundSettings { } } if let Some(volume) = self.volume { - sound.settings.volume = Value::Fixed(volume); + if let Value::Fixed(channel_volume) = sound.settings.volume { + sound.settings.volume = + Value::Fixed((volume.as_amplitude() * channel_volume.as_amplitude()).into()); + } else { + sound.settings.volume = Value::Fixed(volume); + } } if let Some(playback_rate) = self.playback_rate { sound.settings.playback_rate = playback_rate.into(); @@ -306,7 +311,7 @@ impl<'a, Fade> TweenCommand<'a, Fade> { kind, tween: None, que, - _marker: PhantomData::::default(), + _marker: PhantomData::, } } } diff --git a/src/audio_output.rs b/src/audio_output.rs index 86a2170..6bb3866 100644 --- a/src/audio_output.rs +++ b/src/audio_output.rs @@ -91,7 +91,7 @@ impl AudioOutput { } } } - if let Some(mut channel_state) = self.channels.get_mut(channel) { + if let Some(channel_state) = self.channels.get_mut(channel) { channel_state.paused = true; } else { let channel_state = ChannelState { @@ -123,7 +123,7 @@ impl AudioOutput { } } } - if let Some(mut channel_state) = self.channels.get_mut(channel) { + if let Some(channel_state) = self.channels.get_mut(channel) { channel_state.paused = false; } else { self.channels @@ -148,7 +148,7 @@ impl AudioOutput { } } } - if let Some(mut channel_state) = self.channels.get_mut(channel) { + if let Some(channel_state) = self.channels.get_mut(channel) { channel_state.volume = volume; } else { let channel_state = ChannelState { @@ -176,7 +176,7 @@ impl AudioOutput { } } } - if let Some(mut channel_state) = self.channels.get_mut(channel) { + if let Some(channel_state) = self.channels.get_mut(channel) { channel_state.panning = panning; } else { let channel_state = ChannelState { @@ -204,7 +204,7 @@ impl AudioOutput { } } } - if let Some(mut channel_state) = self.channels.get_mut(channel) { + if let Some(channel_state) = self.channels.get_mut(channel) { channel_state.playback_rate = playback_rate; } else { let channel_state = ChannelState { diff --git a/src/channel/typed.rs b/src/channel/typed.rs index 61daada..be965e5 100644 --- a/src/channel/typed.rs +++ b/src/channel/typed.rs @@ -29,7 +29,7 @@ impl Default for AudioChannel { AudioChannel:: { commands: Default::default(), states: Default::default(), - _marker: PhantomData::default(), + _marker: PhantomData, } } }