1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 09:02:58 +08:00

fix: use using statement for waveform auto-disposal

This commit is contained in:
tsrk 2023-08-29 19:45:11 +02:00
parent a04333c17b
commit a7a64b57e9
No known key found for this signature in database
GPG Key ID: EBD46BB3049B56D6

View File

@ -57,54 +57,55 @@ namespace osu.Game.Rulesets.Edit.Checks
if (!isHitSound(file.Filename)) if (!isHitSound(file.Filename))
continue; continue;
Waveform waveform = new Waveform(stream); using (Waveform waveform = new Waveform(stream))
var points = waveform.GetPoints();
// Skip muted samples
if (points.Length == 0 || points.Sum(getAverageAmplitude) <= silence_threshold)
continue;
float maxAmplitude = points.Select(getAverageAmplitude).Max();
int consequentDelay = 0;
int delay = 0;
float amplitude = 0;
while (delay + consequentDelay < points.Length)
{ {
amplitude += getAverageAmplitude(points[delay]); var points = waveform.GetPoints();
// Reached peak amplitude/transient // Skip muted samples
if (amplitude >= maxAmplitude) if (points.Length == 0 || points.Sum(getAverageAmplitude) <= silence_threshold)
break; continue;
amplitude *= falloff_factor; float maxAmplitude = points.Select(getAverageAmplitude).Max();
if (amplitude < silence_threshold) int consequentDelay = 0;
int delay = 0;
float amplitude = 0;
while (delay + consequentDelay < points.Length)
{ {
amplitude = 0; amplitude += getAverageAmplitude(points[delay]);
consequentDelay++;
// Reached peak amplitude/transient
if (amplitude >= maxAmplitude)
break;
amplitude *= falloff_factor;
if (amplitude < silence_threshold)
{
amplitude = 0;
consequentDelay++;
}
delay++;
} }
delay++; if (consequentDelay >= delay_threshold)
} yield return new IssueTemplateConsequentDelay(this).Create(file.Filename, consequentDelay);
else if (consequentDelay + delay >= delay_threshold)
if (consequentDelay >= delay_threshold) {
yield return new IssueTemplateConsequentDelay(this).Create(file.Filename, consequentDelay); if (consequentDelay > 0)
else if (consequentDelay + delay >= delay_threshold) yield return new IssueTemplateDelay(this).Create(file.Filename, consequentDelay, delay);
{ else
if (consequentDelay > 0) yield return new IssueTemplateDelayNoSilence(this).Create(file.Filename, delay);
yield return new IssueTemplateDelay(this).Create(file.Filename, consequentDelay, delay); }
else else if (consequentDelay + delay >= delay_threshold_negligible)
yield return new IssueTemplateDelayNoSilence(this).Create(file.Filename, delay); {
} if (consequentDelay > 0)
else if (consequentDelay + delay >= delay_threshold_negligible) yield return new IssuTemplateMinorDelay(this).Create(file.Filename, consequentDelay, delay);
{ else
if (consequentDelay > 0) yield return new IssuTemplateMinorDelayNoSilence(this).Create(file.Filename, delay);
yield return new IssuTemplateMinorDelay(this).Create(file.Filename, consequentDelay, delay); }
else
yield return new IssuTemplateMinorDelayNoSilence(this).Create(file.Filename, delay);
} }
} }
} }