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:
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:spotiflac_android/widgets/audio_analysis_widget.dart';
|
||||
|
||||
void main() {
|
||||
group('spectral cutoff formatting', () {
|
||||
test('formats a detected cutoff frequency', () {
|
||||
expect(
|
||||
formatAudioAnalysisSpectralCutoff(
|
||||
22605,
|
||||
notDetectedLabel: 'Not detected',
|
||||
),
|
||||
'22.6 kHz',
|
||||
);
|
||||
});
|
||||
|
||||
test('keeps the metric visible when no cutoff is detected', () {
|
||||
expect(
|
||||
formatAudioAnalysisSpectralCutoff(
|
||||
null,
|
||||
notDetectedLabel: 'Not detected',
|
||||
),
|
||||
'Not detected',
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -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