veloren_voxygen/settings/
audio.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Debug, Serialize, Deserialize)]
4pub enum AudioOutput {
5    /// Veloren's audio system wont work on some systems,
6    /// so you can use this to disable it, and allow the
7    /// game to function
8    // If this option is disabled, functions in the rodio
9    // library MUST NOT be called.
10    Off,
11    #[serde(other)]
12    Automatic,
13}
14
15impl AudioOutput {
16    pub fn is_enabled(&self) -> bool { !matches!(self, Self::Off) }
17}
18
19#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
20pub struct AudioVolume {
21    pub volume: f32,
22    pub muted: bool,
23}
24
25impl AudioVolume {
26    pub fn new(volume: f32, muted: bool) -> Self { Self { volume, muted } }
27
28    pub fn get_checked(&self) -> f32 {
29        match self.muted {
30            true => 0.0,
31            false => self.volume,
32        }
33    }
34}
35
36/// `AudioSettings` controls the volume of different audio subsystems and which
37/// device is used.
38#[derive(Clone, Debug, Serialize, Deserialize)]
39#[serde(default)]
40pub struct AudioSettings {
41    pub master_volume: AudioVolume,
42    #[serde(rename = "inactive_master_volume")]
43    pub inactive_master_volume_perc: AudioVolume,
44    pub music_volume: AudioVolume,
45    pub sfx_volume: AudioVolume,
46    pub ambience_volume: AudioVolume,
47    pub num_sfx_channels: usize,
48    pub num_ui_channels: usize,
49    pub music_spacing: f32,
50    pub subtitles: bool,
51    pub combat_music_enabled: bool,
52    /// The size of the sample buffer Kira uses. Increasing this may improve
53    /// audio performance at the cost of audio latency.
54    pub buffer_size: usize,
55
56    /// Audio Device that Voxygen will use to play audio.
57    pub output: AudioOutput,
58}
59
60impl Default for AudioSettings {
61    fn default() -> Self {
62        Self {
63            master_volume: AudioVolume::new(0.8, false),
64            inactive_master_volume_perc: AudioVolume::new(0.5, false),
65            music_volume: AudioVolume::new(0.5, false),
66            sfx_volume: AudioVolume::new(0.8, false),
67            ambience_volume: AudioVolume::new(0.8, false),
68            num_sfx_channels: 48,
69            num_ui_channels: 16,
70            music_spacing: 1.0,
71            subtitles: false,
72            output: AudioOutput::Automatic,
73            combat_music_enabled: false,
74            buffer_size: 256,
75        }
76    }
77}