Read amplitudes from piano reverb source

This commit is contained in:
Dean Herbert 2020-06-23 13:55:44 +09:00
parent 4554a7db33
commit 49d3511063
2 changed files with 49 additions and 16 deletions

View File

@ -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,

View File

@ -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,28 +98,29 @@ 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);
{
float targetAmplitude = (temporalAmplitudes?[(i + indexOffset) % bars_per_visualiser] ?? 0) * (effect?.KiaiMode == true ? 1 : 0.5f);
if (targetAmplitude > frequencyAmplitudes[i]) if (targetAmplitude > frequencyAmplitudes[i])
frequencyAmplitudes[i] = targetAmplitude; 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;