mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Voxygen: Update ambient channels volume
This commit is contained in:
parent
05279872ce
commit
1d605c2dc8
voxygen/src/audio
@ -165,18 +165,24 @@ pub enum AmbientChannelTag {
|
|||||||
/// which are always heard at the camera's position.
|
/// which are always heard at the camera's position.
|
||||||
pub struct AmbientChannel {
|
pub struct AmbientChannel {
|
||||||
tag: AmbientChannelTag,
|
tag: AmbientChannelTag,
|
||||||
|
multiplier: f32,
|
||||||
sink: Sink,
|
sink: Sink,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AmbientChannel {
|
impl AmbientChannel {
|
||||||
pub fn new(stream: &OutputStreamHandle, tag: AmbientChannelTag) -> Self {
|
pub fn new(stream: &OutputStreamHandle, tag: AmbientChannelTag, multiplier: f32) -> Self {
|
||||||
let new_sink = Sink::try_new(stream);
|
let new_sink = Sink::try_new(stream);
|
||||||
match new_sink {
|
match new_sink {
|
||||||
Ok(sink) => Self { tag, sink },
|
Ok(sink) => Self {
|
||||||
|
tag,
|
||||||
|
multiplier,
|
||||||
|
sink,
|
||||||
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
warn!("Failed to create rodio sink. May not play wind sounds.");
|
warn!("Failed to create rodio sink. May not play wind sounds.");
|
||||||
Self {
|
Self {
|
||||||
tag,
|
tag,
|
||||||
|
multiplier,
|
||||||
sink: Sink::new_idle().0,
|
sink: Sink::new_idle().0,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -195,7 +201,9 @@ impl AmbientChannel {
|
|||||||
|
|
||||||
pub fn stop(&mut self) { self.sink.stop(); }
|
pub fn stop(&mut self) { self.sink.stop(); }
|
||||||
|
|
||||||
pub fn set_volume(&mut self, volume: f32) { self.sink.set_volume(volume); }
|
pub fn set_volume(&mut self, volume: f32) { self.sink.set_volume(volume * self.multiplier); }
|
||||||
|
|
||||||
|
pub fn set_multiplier(&mut self, multiplier: f32) { self.multiplier = multiplier; }
|
||||||
|
|
||||||
pub fn get_volume(&mut self) -> f32 { self.sink.volume() }
|
pub fn get_volume(&mut self) -> f32 { self.sink.volume() }
|
||||||
|
|
||||||
|
@ -308,14 +308,16 @@ impl AudioFrontend {
|
|||||||
) -> Option<&mut AmbientChannel> {
|
) -> Option<&mut AmbientChannel> {
|
||||||
if let Some(audio_stream) = &self.audio_stream {
|
if let Some(audio_stream) = &self.audio_stream {
|
||||||
if self.ambient_channels.is_empty() {
|
if self.ambient_channels.is_empty() {
|
||||||
let mut ambient_channel = AmbientChannel::new(audio_stream, channel_tag);
|
let mut ambient_channel =
|
||||||
ambient_channel.set_volume(self.get_sfx_volume() * volume_multiplier);
|
AmbientChannel::new(audio_stream, channel_tag, volume_multiplier);
|
||||||
|
ambient_channel.set_volume(self.get_sfx_volume());
|
||||||
self.ambient_channels.push(ambient_channel);
|
self.ambient_channels.push(ambient_channel);
|
||||||
} else {
|
} else {
|
||||||
let sfx_volume = self.get_sfx_volume();
|
let sfx_volume = self.get_sfx_volume();
|
||||||
for channel in self.ambient_channels.iter_mut() {
|
for channel in self.ambient_channels.iter_mut() {
|
||||||
if channel.get_tag() == channel_tag {
|
if channel.get_tag() == channel_tag {
|
||||||
channel.set_volume(sfx_volume * volume_multiplier);
|
channel.set_multiplier(volume_multiplier);
|
||||||
|
channel.set_volume(sfx_volume);
|
||||||
return Some(channel);
|
return Some(channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -329,7 +331,8 @@ impl AudioFrontend {
|
|||||||
if self.audio_stream.is_some() {
|
if self.audio_stream.is_some() {
|
||||||
let sfx_volume = self.get_sfx_volume();
|
let sfx_volume = self.get_sfx_volume();
|
||||||
if let Some(channel) = self.ambient_channels.iter_mut().last() {
|
if let Some(channel) = self.ambient_channels.iter_mut().last() {
|
||||||
channel.set_volume(sfx_volume * volume_multiplier);
|
channel.set_multiplier(volume_multiplier);
|
||||||
|
channel.set_volume(sfx_volume);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -416,10 +419,7 @@ impl AudioFrontend {
|
|||||||
pub fn set_sfx_volume(&mut self, sfx_volume: f32) {
|
pub fn set_sfx_volume(&mut self, sfx_volume: f32) {
|
||||||
self.sfx_volume = sfx_volume;
|
self.sfx_volume = sfx_volume;
|
||||||
|
|
||||||
let sfx_volume = self.get_sfx_volume();
|
self.update_sfx_volumes();
|
||||||
for channel in self.sfx_channels.iter_mut() {
|
|
||||||
channel.set_volume(sfx_volume);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_music_volume(&mut self, music_volume: f32) {
|
pub fn set_music_volume(&mut self, music_volume: f32) {
|
||||||
@ -439,10 +439,18 @@ impl AudioFrontend {
|
|||||||
channel.set_volume(music_volume);
|
channel.set_volume(music_volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.update_sfx_volumes();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_sfx_volumes(&mut self) {
|
||||||
let sfx_volume = self.get_sfx_volume();
|
let sfx_volume = self.get_sfx_volume();
|
||||||
for channel in self.sfx_channels.iter_mut() {
|
for channel in self.sfx_channels.iter_mut() {
|
||||||
channel.set_volume(sfx_volume);
|
channel.set_volume(sfx_volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for channel in self.ambient_channels.iter_mut() {
|
||||||
|
channel.set_volume(sfx_volume);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop_ambient_sounds(&mut self) {
|
pub fn stop_ambient_sounds(&mut self) {
|
||||||
|
Loading…
Reference in New Issue
Block a user