1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/// A built-in synthesized instrument.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum Instrument {
/// A sinusoidal oscillator.
Sine,
/// A pulse oscillator with equal high and low periods.
Square,
/// A symmetric triangle oscillator.
Triangle,
/// A low, harmonically soft melodic preset.
Bass,
/// A slowly attacking, detuned melodic preset.
Pad,
/// A prominent, harmonically bright melodic preset.
Lead,
/// A short low tone with a downward pitch sweep.
BassDrum,
/// A short pitched drum with a smaller downward sweep.
Tom,
/// A short mixture of tone and deterministic noise.
Snare,
/// A short bright metallic/noise preset.
HiHat,
/// A quickly decaying, harmonically bright plucked-string preset.
Pluck,
}
impl Instrument {
/// Return the recommended linear gain for this instrument.
///
/// The values compensate for waveform, spectrum, envelope, and one-shot
/// duration so the built-in instruments have similar integrated perceived
/// loudness at their typical pitches. They are calibrated from the EBU R128
/// loudness of the one-second sections in the `render_wav` example. Multiply
/// this value by note velocity when constructing custom MIDI mappings or
/// direct [`crate::Event`]s.
#[must_use]
pub const fn default_gain(self) -> f32 {
match self {
Self::Sine => 0.25,
Self::Square => 0.165,
Self::Triangle => 0.31,
Self::Pluck => 0.63,
Self::Bass => 0.55,
Self::Pad | Self::Tom => 0.65,
Self::Lead => 0.325,
Self::BassDrum => 1.0,
Self::Snare => 0.81,
Self::HiHat => 0.86,
}
}
}