Skip to content

Commit

Permalink
Multiply instance volume with channel volume
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasEi committed Sep 6, 2023
1 parent 92b1a97 commit 5061cb7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
6 changes: 3 additions & 3 deletions examples/multiple_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl<T> Default for ChannelAudioState<T> {
stopped: true,
loop_started: false,
paused: false,
_marker: PhantomData::<T>::default(),
_marker: PhantomData::<T>,
}
}
}
Expand Down Expand Up @@ -363,7 +363,7 @@ fn build_button_row<T: Component + Default + Clone>(
NORMAL_BUTTON.into(),
ChangeVolumeButton::<T> {
louder: true,
_marker: PhantomData::default(),
_marker: PhantomData,
},
font.clone(),
);
Expand All @@ -373,7 +373,7 @@ fn build_button_row<T: Component + Default + Clone>(
NORMAL_BUTTON.into(),
ChangeVolumeButton::<T> {
louder: false,
_marker: PhantomData::default(),
_marker: PhantomData,
},
font.clone(),
);
Expand Down
2 changes: 1 addition & 1 deletion examples/spacial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ fn player_look(
mut query: Query<&mut Transform, With<FlyCam>>,
) {
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 {
Expand Down
9 changes: 7 additions & 2 deletions src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -306,7 +311,7 @@ impl<'a, Fade> TweenCommand<'a, Fade> {
kind,
tween: None,
que,
_marker: PhantomData::<Fade>::default(),
_marker: PhantomData::<Fade>,
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/audio_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<B: Backend> AudioOutput<B> {
}
}
}
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 {
Expand Down Expand Up @@ -123,7 +123,7 @@ impl<B: Backend> AudioOutput<B> {
}
}
}
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
Expand All @@ -148,7 +148,7 @@ impl<B: Backend> AudioOutput<B> {
}
}
}
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 {
Expand Down Expand Up @@ -176,7 +176,7 @@ impl<B: Backend> AudioOutput<B> {
}
}
}
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 {
Expand Down Expand Up @@ -204,7 +204,7 @@ impl<B: Backend> AudioOutput<B> {
}
}
}
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/channel/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<T> Default for AudioChannel<T> {
AudioChannel::<T> {
commands: Default::default(),
states: Default::default(),
_marker: PhantomData::default(),
_marker: PhantomData,
}
}
}
Expand Down

0 comments on commit 5061cb7

Please sign in to comment.