mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-13 11:20:31 +00:00
86 lines
2.1 KiB
C#
86 lines
2.1 KiB
C#
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using osu.Framework.Audio.Mixing;
|
|
using osu.Framework.Statistics;
|
|
using osu.Framework.Audio.Track;
|
|
|
|
namespace osu.Framework.Audio.Sample
|
|
{
|
|
public abstract class SampleChannel : AdjustableAudioComponent, ISampleChannel, IAudioChannel
|
|
{
|
|
internal Action<SampleChannel>? OnPlay;
|
|
|
|
public string Name { get; }
|
|
|
|
protected SampleChannel(string name)
|
|
{
|
|
Name = name;
|
|
}
|
|
|
|
public virtual void Play()
|
|
{
|
|
ObjectDisposedException.ThrowIf(IsDisposed, this);
|
|
|
|
Played = true;
|
|
|
|
try
|
|
{
|
|
// Best-effort: notify global latency manager that a sample playback was requested.
|
|
EzLatency.EzLatencyManager.GLOBAL.RecordPlaybackEvent();
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
|
|
OnPlay?.Invoke(this);
|
|
}
|
|
|
|
public virtual void Stop()
|
|
{
|
|
}
|
|
|
|
protected override void UpdateState()
|
|
{
|
|
FrameStatistics.Increment(StatisticsCounterType.SChannels);
|
|
base.UpdateState();
|
|
}
|
|
|
|
public bool Played { get; private set; }
|
|
|
|
public abstract bool Playing { get; }
|
|
|
|
public virtual bool Looping { get; set; }
|
|
|
|
public override bool IsAlive => ManualFree ? base.IsAlive : base.IsAlive && Playing;
|
|
|
|
public virtual ChannelAmplitudes CurrentAmplitudes { get; } = ChannelAmplitudes.Empty;
|
|
|
|
#region Mixing
|
|
|
|
protected virtual AudioMixer? Mixer { get; set; }
|
|
|
|
AudioMixer? IAudioChannel.Mixer
|
|
{
|
|
get => Mixer;
|
|
set => Mixer = value;
|
|
}
|
|
|
|
Task IAudioChannel.EnqueueAction(Action action) => EnqueueAction(action);
|
|
|
|
#endregion
|
|
|
|
public bool ManualFree { get; set; }
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (!IsDisposed)
|
|
Stop();
|
|
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
}
|