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 rain_ambience_enabled: bool,
48    pub num_sfx_channels: usize,
49    pub num_ui_channels: usize,
50    pub music_spacing: f32,
51    pub subtitles: bool,
52    pub combat_music_enabled: bool,
53    /// The size of the sample buffer Kira uses. Increasing this may improve
54    /// audio performance at the cost of audio latency.
55    pub buffer_size: usize,
56    /// Set to None to use the default samplerate determined by the game;
57    /// otherwise, use Some(samplerate); the game will attempt to force
58    /// samplerate to this.
59    pub sample_rate: Option<u32>,
60
61    /// Audio Device that Voxygen will use to play audio.
62    pub output: AudioOutput,
63}
64
65impl Default for AudioSettings {
66    fn default() -> Self {
67        Self {
68            master_volume: AudioVolume::new(0.8, false),
69            inactive_master_volume_perc: AudioVolume::new(0.5, false),
70            music_volume: AudioVolume::new(0.5, false),
71            sfx_volume: AudioVolume::new(0.8, false),
72            ambience_volume: AudioVolume::new(0.8, false),
73            num_sfx_channels: 64,
74            rain_ambience_enabled: true,
75            num_ui_channels: 16,
76            music_spacing: 1.0,
77            subtitles: false,
78            output: AudioOutput::Automatic,
79            combat_music_enabled: false,
80            buffer_size: 512,
81            sample_rate: None,
82        }
83    }
84}