Files
cutdex/lib/features/properties/audio_gain_scale.dart
T
lingjhf 27e77fff39 feat: initial Cutdex application
Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
2026-10-05 23:36:23 +08:00

28 lines
1.0 KiB
Dart

/// Slider travel is a presentation choice, independent of authored gain.
abstract final class AudioGainScale {
static const decimalPlaces = 1;
static double quantizeDb(double db) => double.parse(formatDb(db));
static String formatDb(double db) {
final text = db.toStringAsFixed(decimalPlaces);
return text == '-0.0' ? '0.0' : text;
}
// Reserve 70% of travel for -24...+6 dB. Zero is a separate mute endpoint.
static double dbAt(double position) {
if (!position.isFinite) throw ArgumentError.value(position);
final p = position.clamp(0.0, 1.0);
if (p <= .01) return -90;
if (p <= .2) return -90 + (p - .01) / .19 * 66;
if (p <= .9) return -24 + (p - .2) / .7 * 30;
return 6 + (p - .9) / .1 * 6;
}
static double positionAt(double db) {
if (!db.isFinite) throw ArgumentError.value(db);
final value = db.clamp(-90.0, 12.0);
if (value <= -24) return .01 + (value + 90) / 66 * .19;
if (value <= 6) return .2 + (value + 24) / 30 * .7;
return .9 + (value - 6) / 6 * .1;
}
}