Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce minimum gameplay sample volume of 5% #25185

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ private void load()
RelativeSizeAxes = Axes.X
},
tailContainer = new Container<DrawableHoldNoteTail> { RelativeSizeAxes = Axes.Both },
slidingSample = new PausableSkinnableSound { Looping = true }
slidingSample = new PausableSkinnableSound
{
Looping = true,
MinimumSampleVolume = MINIMUM_SAMPLE_VOLUME,
}
});

maskedContents.AddRange(new[]
Expand Down
6 changes: 5 additions & 1 deletion osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ private void load()
headContainer = new Container<DrawableSliderHead> { RelativeSizeAxes = Axes.Both },
OverlayElementContainer = new Container { RelativeSizeAxes = Axes.Both, },
Ball,
slidingSample = new PausableSkinnableSound { Looping = true }
slidingSample = new PausableSkinnableSound
{
Looping = true,
MinimumSampleVolume = MINIMUM_SAMPLE_VOLUME,
}
});

PositionBindable.BindValueChanged(_ => Position = HitObject.StackedPosition);
Expand Down
1 change: 1 addition & 0 deletions osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private void load()
spinningSample = new PausableSkinnableSound
{
Volume = { Value = 0 },
MinimumSampleVolume = MINIMUM_SAMPLE_VOLUME,
Looping = true,
Frequency = { Value = spinning_sample_initial_frequency }
}
Expand Down
25 changes: 24 additions & 1 deletion osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ public abstract partial class DrawableHitObject : PoolableDrawableWithLifetime<H
/// </summary>
internal bool IsInitialized;

/// <summary>
/// The minimum allowable volume for sample playback.
/// <see cref="Samples"/> quieter than that will be forcibly played at this volume instead.
/// </summary>
/// <remarks>
/// <para>
/// Drawable hitobjects adding their own custom samples, or other sample playback sources
/// (i.e. <see cref="GameplaySampleTriggerSource"/>) must enforce this themselves.
/// </para>
/// <para>
/// This sample volume floor is present in stable, although it is set at 8% rather than 5%.
/// See: https://github.com/peppy/osu-stable-reference/blob/3ea48705eb67172c430371dcfc8a16a002ed0d3d/osu!/Audio/AudioEngine.cs#L1070,
/// https://github.com/peppy/osu-stable-reference/blob/3ea48705eb67172c430371dcfc8a16a002ed0d3d/osu!/Audio/AudioEngine.cs#L1404-L1405.
/// The reason why it is 5% here is that the 8% cap was enforced in a silent manner
/// (i.e. the minimum selectable volume in the editor was 5%, but it would be played at 8% anyways),
/// which is confusing and arbitrary, so we're just doing 5% here at the cost of sacrificing strict parity.
/// </para>
/// </remarks>
public const int MINIMUM_SAMPLE_VOLUME = 5;

/// <summary>
/// Creates a new <see cref="DrawableHitObject"/>.
/// </summary>
Expand All @@ -181,7 +201,10 @@ private void load(IGameplaySettings gameplaySettings, ISkinSource skinSource)
comboColourBrightness.BindTo(gameplaySettings.ComboColourNormalisationAmount);

// Explicit non-virtual function call in case a DrawableHitObject overrides AddInternal.
base.AddInternal(Samples = new PausableSkinnableSound());
base.AddInternal(Samples = new PausableSkinnableSound
{
MinimumSampleVolume = MINIMUM_SAMPLE_VOLUME
});

CurrentSkin = skinSource;
CurrentSkin.SourceChanged += skinSourceChanged;
Expand Down
6 changes: 5 additions & 1 deletion osu.Game/Rulesets/UI/GameplaySampleTriggerSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using osu.Framework.Graphics.Containers;
using osu.Game.Audio;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Skinning;
Expand Down Expand Up @@ -45,7 +46,10 @@ public GameplaySampleTriggerSource(HitObjectContainer hitObjectContainer)
Child = hitSounds = new Container<SkinnableSound>
{
Name = "concurrent sample pool",
ChildrenEnumerable = Enumerable.Range(0, max_concurrent_hitsounds).Select(_ => new PausableSkinnableSound())
ChildrenEnumerable = Enumerable.Range(0, max_concurrent_hitsounds).Select(_ => new PausableSkinnableSound
{
MinimumSampleVolume = DrawableHitObject.MINIMUM_SAMPLE_VOLUME
})
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Screens.Edit.Timing;
using osuTK;
using osuTK.Graphics;
Expand Down Expand Up @@ -101,7 +102,7 @@ private void load()
},
volume = new IndeterminateSliderWithTextBoxInput<int>("Volume", new BindableInt(100)
{
MinValue = 0,
MinValue = DrawableHitObject.MINIMUM_SAMPLE_VOLUME,
MaxValue = 100,
})
}
Expand Down
8 changes: 7 additions & 1 deletion osu.Game/Skinning/SkinnableSound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ namespace osu.Game.Skinning
/// </summary>
public partial class SkinnableSound : SkinReloadableDrawable, IAdjustableAudioComponent
{
/// <summary>
/// The minimum allowable volume for <see cref="Samples"/>.
/// <see cref="Samples"/> that specify a lower <see cref="ISampleInfo.Volume"/> will be forcibly pulled up to this volume.
/// </summary>
public int MinimumSampleVolume { get; set; }

public override bool RemoveWhenNotAlive => false;
public override bool RemoveCompletedTransforms => false;

Expand Down Expand Up @@ -156,7 +162,7 @@ private void updateSamples()
{
var sample = samplePool?.GetPooledSample(s) ?? new PoolableSkinnableSample(s);
sample.Looping = Looping;
sample.Volume.Value = s.Volume / 100.0;
sample.Volume.Value = Math.Max(s.Volume, MinimumSampleVolume) / 100.0;

samplesContainer.Add(sample);
}
Expand Down