1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-15 23:57:25 +08:00

style: move common audio utils to separate static class

This commit is contained in:
tsrk 2023-08-29 20:10:35 +02:00
parent a7a64b57e9
commit c1a7ad09b4
No known key found for this signature in database
GPG Key ID: EBD46BB3049B56D6
3 changed files with 15 additions and 12 deletions

View File

@ -22,8 +22,6 @@ namespace osu.Game.Rulesets.Edit.Checks
private const int delay_threshold = 5; private const int delay_threshold = 5;
private const int delay_threshold_negligible = 1; private const int delay_threshold_negligible = 1;
private readonly string[] audioExtensions = { "mp3", "ogg", "wav" };
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Audio, "Delayed hit sounds."); public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Audio, "Delayed hit sounds.");
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[] public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
@ -51,9 +49,6 @@ namespace osu.Game.Rulesets.Edit.Checks
if (stream == null) if (stream == null)
continue; continue;
if (!hasAudioExtension(file.Filename))
continue;
if (!isHitSound(file.Filename)) if (!isHitSound(file.Filename))
continue; continue;
@ -111,10 +106,11 @@ namespace osu.Game.Rulesets.Edit.Checks
} }
} }
private bool hasAudioExtension(string filename) => audioExtensions.Any(filename.ToLowerInvariant().EndsWith);
private bool isHitSound(string filename) private bool isHitSound(string filename)
{ {
if (!AudioCheckUtils.HasAudioExtension(filename))
return false;
// <bank>-<sampleset> // <bank>-<sampleset>
string[] parts = filename.ToLowerInvariant().Split('-'); string[] parts = filename.ToLowerInvariant().Split('-');

View File

@ -3,7 +3,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using ManagedBass; using ManagedBass;
using osu.Framework.Audio.Callbacks; using osu.Framework.Audio.Callbacks;
using osu.Game.Extensions; using osu.Game.Extensions;
@ -16,8 +15,6 @@ namespace osu.Game.Rulesets.Edit.Checks
private const int ms_threshold = 25; private const int ms_threshold = 25;
private const int min_bytes_threshold = 100; private const int min_bytes_threshold = 100;
private readonly string[] audioExtensions = { "mp3", "ogg", "wav" };
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Audio, "Too short audio files"); public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Audio, "Too short audio files");
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[] public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
@ -46,7 +43,7 @@ namespace osu.Game.Rulesets.Edit.Checks
{ {
// If the file is not likely to be properly parsed by Bass, we don't produce Error issues about it. // If the file is not likely to be properly parsed by Bass, we don't produce Error issues about it.
// Image files and audio files devoid of audio data both fail, for example, but neither would be issues in this check. // Image files and audio files devoid of audio data both fail, for example, but neither would be issues in this check.
if (hasAudioExtension(file.Filename) && probablyHasAudioData(data)) if (AudioCheckUtils.HasAudioExtension(file.Filename) && probablyHasAudioData(data))
yield return new IssueTemplateBadFormat(this).Create(file.Filename); yield return new IssueTemplateBadFormat(this).Create(file.Filename);
continue; continue;
@ -63,7 +60,6 @@ namespace osu.Game.Rulesets.Edit.Checks
} }
} }
private bool hasAudioExtension(string filename) => audioExtensions.Any(filename.ToLowerInvariant().EndsWith);
private bool probablyHasAudioData(Stream data) => data.Length > min_bytes_threshold; private bool probablyHasAudioData(Stream data) => data.Length > min_bytes_threshold;
public class IssueTemplateTooShort : IssueTemplate public class IssueTemplateTooShort : IssueTemplate

View File

@ -0,0 +1,11 @@
using System.Linq;
namespace osu.Game.Rulesets.Edit.Checks.Components
{
public static class AudioCheckUtils
{
public static readonly string[] AUDIO_EXTENSIONS = { "mp3", "ogg", "wav" };
public static bool HasAudioExtension(string filename) => AUDIO_EXTENSIONS.Any(filename.ToLowerInvariant().EndsWith);
}
}