mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-08-05 02:28:36 +02:00
fix(analysis): detect full-band spectral cutoff
This commit is contained in:
@@ -250,6 +250,30 @@ lavfi.r128.true_peak=0.907
|
||||
expect(cutoff, nyquist);
|
||||
});
|
||||
|
||||
test(
|
||||
'reports Nyquist for full-band music with a natural spectral tilt',
|
||||
() {
|
||||
const cdNyquist = 22050.0;
|
||||
final intensity = _blankIntensity(width, height);
|
||||
_paintNaturalSpectralTilt(
|
||||
intensity,
|
||||
width: width,
|
||||
height: height,
|
||||
lowFrequencyIntensity: 140,
|
||||
nyquistIntensity: 26,
|
||||
);
|
||||
|
||||
final cutoff = estimateEffectiveSpectralCutoffHz(
|
||||
intensity: intensity,
|
||||
width: width,
|
||||
height: height,
|
||||
maxFrequencyHz: cdNyquist,
|
||||
);
|
||||
|
||||
expect(cutoff, cdNyquist);
|
||||
},
|
||||
);
|
||||
|
||||
test('does not report an isolated line as a broadband cutoff', () {
|
||||
final intensity = _blankIntensity(width, height);
|
||||
_paintFrequencyBand(
|
||||
@@ -312,3 +336,24 @@ void _paintFrequencyBand(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _paintNaturalSpectralTilt(
|
||||
Uint8List values, {
|
||||
required int width,
|
||||
required int height,
|
||||
required int lowFrequencyIntensity,
|
||||
required int nyquistIntensity,
|
||||
}) {
|
||||
final span = lowFrequencyIntensity - nyquistIntensity;
|
||||
for (var y = 0; y < height; y++) {
|
||||
final normalizedFrequency = (height - y - 0.5) / height;
|
||||
final intensity =
|
||||
(lowFrequencyIntensity -
|
||||
span * normalizedFrequency * normalizedFrequency)
|
||||
.round()
|
||||
.clamp(0, 255);
|
||||
for (var x = 0; x < width; x++) {
|
||||
values[y * width + x] = intensity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user