Merge branch 'DaforLynx/ambience-loop-fix' into 'master'

Fixing ambience looping issues

See merge request veloren/veloren!3463
This commit is contained in:
Christof Petig 2022-07-08 08:03:02 +00:00
commit 7bd4686187
4 changed files with 12 additions and 20 deletions

View File

@ -2,22 +2,22 @@
tracks: [
(
path: "voxygen.audio.ambience.wind",
length: 14.203,
length: 14.17,
tag: Wind,
),
(
path: "voxygen.audio.ambience.rain",
length: 17.0,
length: 16.97,
tag: Rain,
),
(
path:"voxygen.audio.ambience.thunder",
length: 32.0,
length: 31.97,
tag: Thunder,
),
(
path:"voxygen.audio.ambience.leaves",
length: 26.0,
length: 25.97,
tag: Leaves,
),
]

View File

@ -641,8 +641,8 @@
biomes: [],
site: Some(Dungeon),
segments: [
("voxygen.audio.soundtrack.combat.barred_paths.barred_paths-start", 56.0, Transition(Explore, Combat(High)), Some(Combat(High))),
("voxygen.audio.soundtrack.combat.barred_paths.barred_paths-loop", 54.0, Activity(Combat(High)), None),
("voxygen.audio.soundtrack.combat.barred_paths.barred_paths-start", 55.97, Transition(Explore, Combat(High)), Some(Combat(High))),
("voxygen.audio.soundtrack.combat.barred_paths.barred_paths-loop", 53.97, Activity(Combat(High)), None),
("voxygen.audio.soundtrack.combat.barred_paths.barred_paths-end", 6.0, Transition(Combat(High), Explore), None),
],
),
@ -653,8 +653,8 @@
biomes: [],
site: Some(Dungeon),
segments: [
("voxygen.audio.soundtrack.combat.reversal.reversal-start", 60.0, Transition(Explore, Combat(High)), Some(Combat(High))),
("voxygen.audio.soundtrack.combat.reversal.reversal-loop", 60.0, Activity(Combat(High)), None),
("voxygen.audio.soundtrack.combat.reversal.reversal-start", 59.97, Transition(Explore, Combat(High)), Some(Combat(High))),
("voxygen.audio.soundtrack.combat.reversal.reversal-loop", 59.97, Activity(Combat(High)), None),
("voxygen.audio.soundtrack.combat.reversal.reversal-end", 4.0, Transition(Combat(High), Explore), None),
],
),

View File

@ -79,20 +79,17 @@ impl AmbientMgr {
// Update with sfx volume
channel.set_volume(ambience_volume);
// Set the duration of the loop to whatever the current value is (0.0 by
// default)
// If the sound should loop at this point:
if channel.began_playing.elapsed().as_secs_f32() > channel.next_track_change {
let track = ambience.tracks.iter().find(|track| track.tag == tag);
// Set the channel's start point at this instant
// Set the channel's start point to this instant
channel.began_playing = Instant::now();
if let Some(track) = track {
// Set loop duration to the one specified in the ron
channel.next_track_change = track.length;
// Play the file of the current tag at the current multiplier;
let current_multiplier = channel.multiplier;
audio.play_ambient(tag, &track.path, current_multiplier);
audio.play_ambient(tag, &track.path, current_multiplier * ambience_volume);
}
};

View File

@ -308,15 +308,10 @@ impl AudioFrontend {
}
/// Plays a file at a given volume in the channel with a given tag
fn play_ambient(
&mut self,
channel_tag: AmbientChannelTag,
sound: &str,
volume_multiplier: f32,
) {
fn play_ambient(&mut self, channel_tag: AmbientChannelTag, sound: &str, volume: f32) {
if self.audio_stream.is_some() {
if let Some(channel) = self.get_ambient_channel(channel_tag) {
channel.set_volume(volume_multiplier);
channel.set_volume(volume);
channel.play(load_ogg(sound));
}
}