Skip to content
Draft
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
47 changes: 44 additions & 3 deletions YARG.Core/Audio/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public abstract class AudioManager
mixer.Dispose();
return null;
}
MixerAudioHandler.SetMixer(mixer);
YargLogger.LogDebug("Custom audio file loaded");
return mixer;
}
Expand Down Expand Up @@ -128,6 +127,50 @@ internal void SetBufferLength(int length)
}
}

internal void SetSfxVolume(double volume)
{
lock (SfxSamples)
{
foreach (var sample in SfxSamples)
{
sample?.SetVolume(volume);
}
}
}

internal void SetDrumSfxVolume(double volume)
{
lock (DrumSfxSamples)
{
foreach (var sample in DrumSfxSamples)
{
sample?.SetVolume(volume);
}
}
}

internal void SetVoxSampleVolume(double volume)
{
lock (VoxSamples)
{
foreach (var sample in VoxSamples)
{
sample?.SetVolume(volume);
}
}
}

internal void SetMetronomeVolume(double volume)
{
lock (MetronomeSamples)
{
foreach (var sample in MetronomeSamples)
{
sample?.SetVolume(volume);
}
}
}

protected abstract void ToggleBuffer_Internal(bool enable);

protected abstract void SetBufferLength_Internal(int length);
Expand Down Expand Up @@ -188,8 +231,6 @@ internal void RemoveMixer(StemMixer mixer)
YargLogger.LogFormat(level, "Mixer \"{0}\" disposed", mixer.Name);
_activeMixers.Remove(mixer);
}

MixerAudioHandler.RemoveMixer(mixer);
}

protected virtual void DisposeManagedResources() { }
Expand Down
11 changes: 4 additions & 7 deletions YARG.Core/Audio/DrumSampleChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ public abstract class DrumSampleChannel : IDisposable
protected readonly string _path;
protected readonly int _playbackCount;
protected double _volume;
private double _settingVolume = 1;

public readonly DrumSfxSample Sample;
protected DrumSampleChannel(DrumSfxSample sample, string path, int playbackCount)
{
Sample = sample;
_path = path;
_playbackCount = playbackCount;

GlobalAudioHandler.SampleStemSettings[SongStem.DrumSfx].OnVolumeChange += SetVolume;
}

public void Play(double volume)
Expand All @@ -30,8 +29,7 @@ public void Play(double volume)
if (!_disposed)
{
_volume = volume;
volume *= GlobalAudioHandler.GetSampleVolumeSetting(SongStem.DrumSfx);
SetVolume_Internal(volume);
SetVolume_Internal(volume * _settingVolume);
Play_Internal();
}
}
Expand All @@ -43,8 +41,8 @@ internal void SetVolume(double volume)
{
if (!_disposed)
{
volume *= _volume;
SetVolume_Internal(volume);
_settingVolume = volume;
SetVolume_Internal(volume * _volume);
}
}
}
Expand Down Expand Up @@ -73,7 +71,6 @@ private void Dispose(bool disposing)
{
if (!_disposed)
{
GlobalAudioHandler.SampleStemSettings[SongStem.DrumSfx].OnVolumeChange -= SetVolume;
if (disposing)
{
DisposeManagedResources();
Expand Down
43 changes: 19 additions & 24 deletions YARG.Core/Audio/GlobalAudioHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,6 @@ public static class GlobalAudioHandler
_ => 2
};

internal static readonly Dictionary<SongStem, StemSettings> SampleStemSettings;

static GlobalAudioHandler()
{
SampleStemSettings = new()
{
{ SongStem.Sfx, new StemSettings() },
{ SongStem.DrumSfx, new StemSettings() },
{ SongStem.VoxSample, new StemSettings() },
{ SongStem.Metronome, new StemSettings() },
};
}

public static bool LogMixerStatus { get; internal set; }

public static bool UseWhammyFx;
Expand Down Expand Up @@ -69,19 +56,27 @@ static GlobalAudioHandler()
/// </remarks>
public static int WhammyOversampleFactor = WHAMMY_OVERSAMPLE_DEFAULT;

public static double GetSampleTrueVolume(SongStem stem)
{
return SampleStemSettings[stem].TrueVolume;
}

public static double GetSampleVolumeSetting(SongStem stem)
{
return SampleStemSettings[stem].VolumeSetting;
}

public static void SetSampleVolumeSetting(SongStem stem, double volume)
{
SampleStemSettings[stem].VolumeSetting = volume;
volume = Math.Clamp(volume, 0, 1);
lock (_instanceLock)
{
switch (stem)
{
case SongStem.Sfx:
_instance?.SetSfxVolume(volume);
break;
case SongStem.DrumSfx:
_instance?.SetDrumSfxVolume(volume);
break;
case SongStem.VoxSample:
_instance?.SetVoxSampleVolume(volume);
break;
case SongStem.Metronome:
_instance?.SetMetronomeVolume(volume);
break;
}
}
}

private static readonly object _instanceLock = new();
Expand Down
2 changes: 0 additions & 2 deletions YARG.Core/Audio/MetronomeSampleChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ protected MetronomeSampleChannel(MetronomeSample sample, string hiPath, string l
Sample = sample;
_hiPath = hiPath;
_loPath = loPath;
GlobalAudioHandler.SampleStemSettings[SongStem.Metronome].OnVolumeChange += SetVolume;
}

public void PlayHi()
Expand Down Expand Up @@ -86,7 +85,6 @@ private void Dispose(bool disposing)
{
if (!_disposed)
{
GlobalAudioHandler.SampleStemSettings[SongStem.Metronome].OnVolumeChange -= SetVolume;
if (disposing)
{
DisposeManagedResources();
Expand Down
113 changes: 0 additions & 113 deletions YARG.Core/Audio/MixerAudioHandler.cs

This file was deleted.

4 changes: 3 additions & 1 deletion YARG.Core/Audio/PreviewContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks;
using System.Threading;
using YARG.Core.Logging;
Expand Down Expand Up @@ -108,6 +108,8 @@ public class PreviewContext : IDisposable
private readonly CancellationTokenSource _token;
private bool _disposed;

public StemMixer Mixer => _mixer;

private PreviewContext(StemMixer mixer, double previewStartTime, double previewLength, double fadeDuration, float volume, CancellationTokenSource token)
{
_mixer = mixer;
Expand Down
3 changes: 0 additions & 3 deletions YARG.Core/Audio/SampleChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ protected SampleChannel(SfxSample sample, string path, int playbackCount)
Sample = sample;
_path = path;
_playbackCount = playbackCount;

GlobalAudioHandler.SampleStemSettings[SongStem.Sfx].OnVolumeChange += SetVolume;
}

public void Play(double duration = 0)
Expand Down Expand Up @@ -134,7 +132,6 @@ private void Dispose(bool disposing)
{
if (!_disposed)
{
GlobalAudioHandler.SampleStemSettings[SongStem.Sfx].OnVolumeChange -= SetVolume;
if (disposing)
{
DisposeManagedResources();
Expand Down
11 changes: 1 addition & 10 deletions YARG.Core/Audio/StemChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,9 @@ protected StemChannel(AudioManager manager, SongStem stem, bool clampVolume)
_clampVolume = clampVolume;
_manager = manager;
Stem = stem;

var settings = MixerAudioHandler.StemSettings[Stem];
settings.OnVolumeChange += OnVolumeChanged;
}

private void OnVolumeChanged(double volume)
{
SetVolume(volume);
}

public void SetWhammyPitch(float percent)
internal void SetWhammyPitch(float percent)
{
lock (this)
{
Expand Down Expand Up @@ -103,7 +95,6 @@ private void Dispose(bool disposing)
{
if (!_disposed)
{
MixerAudioHandler.StemSettings[Stem].OnVolumeChange -= OnVolumeChanged;
if (disposing)
{
DisposeManagedResources();
Expand Down
Loading