mirror of
https://github.com/osukey/osukey.git
synced 2025-05-09 23:57:18 +09:00
Read amplitudes from piano reverb source
This commit is contained in:
parent
4554a7db33
commit
49d3511063
@ -44,6 +44,8 @@ namespace osu.Game.Screens.Menu
|
|||||||
RelativeSizeAxes = Axes.Both
|
RelativeSizeAxes = Axes.Both
|
||||||
}, intro =>
|
}, intro =>
|
||||||
{
|
{
|
||||||
|
intro.LogoVisualisation.AddAmplitudeSource(pianoReverb);
|
||||||
|
|
||||||
AddInternal(intro);
|
AddInternal(intro);
|
||||||
|
|
||||||
welcome?.Play();
|
welcome?.Play();
|
||||||
@ -74,6 +76,8 @@ namespace osu.Game.Screens.Menu
|
|||||||
private Sprite welcomeText;
|
private Sprite welcomeText;
|
||||||
private Container scaleContainer;
|
private Container scaleContainer;
|
||||||
|
|
||||||
|
public LogoVisualisation LogoVisualisation { get; private set; }
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(TextureStore textures)
|
private void load(TextureStore textures)
|
||||||
{
|
{
|
||||||
@ -89,7 +93,7 @@ namespace osu.Game.Screens.Menu
|
|||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new LogoVisualisation
|
LogoVisualisation = new LogoVisualisation
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
|
@ -13,7 +13,10 @@ using osu.Framework.Graphics.Textures;
|
|||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
|
|
||||||
@ -65,6 +68,11 @@ namespace osu.Game.Screens.Menu
|
|||||||
|
|
||||||
public Color4 AccentColour { get; set; }
|
public Color4 AccentColour { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The relative movement of bars based on input amplification. Defaults to 1.
|
||||||
|
/// </summary>
|
||||||
|
public float Magnitude { get; set; } = 1;
|
||||||
|
|
||||||
private readonly float[] frequencyAmplitudes = new float[256];
|
private readonly float[] frequencyAmplitudes = new float[256];
|
||||||
|
|
||||||
private IShader shader;
|
private IShader shader;
|
||||||
@ -76,6 +84,13 @@ namespace osu.Game.Screens.Menu
|
|||||||
Blending = BlendingParameters.Additive;
|
Blending = BlendingParameters.Additive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly List<IHasAmplitudes> amplitudeSources = new List<IHasAmplitudes>();
|
||||||
|
|
||||||
|
public void AddAmplitudeSource(IHasAmplitudes amplitudeSource)
|
||||||
|
{
|
||||||
|
amplitudeSources.Add(amplitudeSource);
|
||||||
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(ShaderManager shaders, IBindable<WorkingBeatmap> beatmap)
|
private void load(ShaderManager shaders, IBindable<WorkingBeatmap> beatmap)
|
||||||
{
|
{
|
||||||
@ -83,27 +98,28 @@ namespace osu.Game.Screens.Menu
|
|||||||
shader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE_ROUNDED);
|
shader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE_ROUNDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly float[] temporalAmplitudes = new float[256];
|
||||||
|
|
||||||
private void updateAmplitudes()
|
private void updateAmplitudes()
|
||||||
{
|
{
|
||||||
var track = beatmap.Value.TrackLoaded ? beatmap.Value.Track : null;
|
var effect = beatmap.Value.BeatmapLoaded && beatmap.Value.TrackLoaded
|
||||||
var effect = beatmap.Value.BeatmapLoaded ? beatmap.Value.Beatmap?.ControlPointInfo.EffectPointAt(track?.CurrentTime ?? Time.Current) : null;
|
? beatmap.Value.Beatmap?.ControlPointInfo.EffectPointAt(beatmap.Value.Track.CurrentTime)
|
||||||
|
: null;
|
||||||
|
|
||||||
float[] temporalAmplitudes = track?.CurrentAmplitudes.FrequencyAmplitudes;
|
for (int i = 0; i < temporalAmplitudes.Length; i++)
|
||||||
|
temporalAmplitudes[i] = 0;
|
||||||
|
|
||||||
|
if (beatmap.Value.TrackLoaded)
|
||||||
|
addAmplitudesFromSource(beatmap.Value.Track);
|
||||||
|
|
||||||
|
foreach (var source in amplitudeSources)
|
||||||
|
addAmplitudesFromSource(source);
|
||||||
|
|
||||||
for (int i = 0; i < bars_per_visualiser; i++)
|
for (int i = 0; i < bars_per_visualiser; i++)
|
||||||
{
|
{
|
||||||
if (track?.IsRunning ?? false)
|
float targetAmplitude = Magnitude * (temporalAmplitudes[(i + indexOffset) % bars_per_visualiser]) * (effect?.KiaiMode == true ? 1 : 0.5f);
|
||||||
{
|
if (targetAmplitude > frequencyAmplitudes[i])
|
||||||
float targetAmplitude = (temporalAmplitudes?[(i + indexOffset) % bars_per_visualiser] ?? 0) * (effect?.KiaiMode == true ? 1 : 0.5f);
|
frequencyAmplitudes[i] = targetAmplitude;
|
||||||
if (targetAmplitude > frequencyAmplitudes[i])
|
|
||||||
frequencyAmplitudes[i] = targetAmplitude;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int index = (i + index_change) % bars_per_visualiser;
|
|
||||||
if (frequencyAmplitudes[index] > frequencyAmplitudes[i])
|
|
||||||
frequencyAmplitudes[i] = frequencyAmplitudes[index];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
indexOffset = (indexOffset + index_change) % bars_per_visualiser;
|
indexOffset = (indexOffset + index_change) % bars_per_visualiser;
|
||||||
@ -136,6 +152,19 @@ namespace osu.Game.Screens.Menu
|
|||||||
|
|
||||||
protected override DrawNode CreateDrawNode() => new VisualisationDrawNode(this);
|
protected override DrawNode CreateDrawNode() => new VisualisationDrawNode(this);
|
||||||
|
|
||||||
|
private void addAmplitudesFromSource([NotNull] IHasAmplitudes source)
|
||||||
|
{
|
||||||
|
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||||
|
|
||||||
|
var amplitudes = source.CurrentAmplitudes.FrequencyAmplitudes;
|
||||||
|
|
||||||
|
for (int i = 0; i < amplitudes.Length; i++)
|
||||||
|
{
|
||||||
|
if (i < temporalAmplitudes.Length)
|
||||||
|
temporalAmplitudes[i] += amplitudes[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class VisualisationDrawNode : DrawNode
|
private class VisualisationDrawNode : DrawNode
|
||||||
{
|
{
|
||||||
protected new LogoVisualisation Source => (LogoVisualisation)base.Source;
|
protected new LogoVisualisation Source => (LogoVisualisation)base.Source;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user