10 bands (dB) */ public const PRESETS = [ 'Plat' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'Classique' => [0, 0, 0, 0, 0, 0, -4, -4, -4, -6], 'Club' => [0, 0, 5, 3, 3, 3, 2, 0, 0, 0], 'Dance' => [6, 4, 1, 0, 0, -3, -4, -4, 0, 0], 'Graves' => [6, 6, 6, 3, 1, -2, -5, -6, -7, -7], 'Graves et aigus' => [4, 3, 0, -4, -3, 1, 5, 7, 7, 7], 'Aigus' => [-6, -6, -6, -2, 1, 7, 10, 10, 10, 11], 'Casque' => [3, 7, 3, -2, -1, 1, 3, 6, 8, 9], 'Grande salle' => [6, 6, 3, 3, 0, -3, -3, -3, 0, 0], 'Live' => [-3, 0, 2, 3, 3, 3, 2, 1, 1, 1], 'FĂȘte' => [4, 4, 0, 0, 0, 0, 0, 0, 4, 4], 'Pop' => [-1, 3, 4, 4, 3, 0, -1, -1, -1, -1], 'Reggae' => [0, 0, 0, -3, 0, 4, 4, 0, 0, 0], 'Rock' => [5, 3, -3, -5, -2, 2, 5, 7, 7, 7], 'Ska' => [-1, -3, -2, 0, 2, 3, 5, 6, 7, 6], 'Doux' => [3, 1, 0, -1, 0, 2, 5, 6, 7, 8], 'Techno' => [5, 3, 0, -3, -3, 0, 5, 6, 6, 5], ]; public bool $on = true; public bool $auto = false; public float $preamp = 0.0; /** @var list */ public array $bands; public function __construct() { $this->bands = array_fill(0, 10, 0.0); } /** @param array $data */ public static function fromArray(array $data): self { $eq = new self(); $eq->on = (bool)($data['on'] ?? true); $eq->auto = (bool)($data['auto'] ?? false); $eq->preamp = self::clamp((float)($data['preamp'] ?? 0)); foreach (array_slice(array_values((array)($data['bands'] ?? [])), 0, 10) as $i => $v) { $eq->bands[$i] = self::clamp((float)$v); } return $eq; } /** @return array{on: bool, auto: bool, preamp: float, bands: list} */ public function toArray(): array { return ['on' => $this->on, 'auto' => $this->auto, 'preamp' => $this->preamp, 'bands' => $this->bands]; } public function preset(string $name): bool { if (!isset(self::PRESETS[$name])) { return false; } $this->bands = array_map('floatval', self::PRESETS[$name]); return true; } public static function clamp(float $db): float { return round(max(self::MIN, min(self::MAX, $db)), 1); } /** The gain of the preamp (what is really applied): 0 dB when off. */ public function preampDb(): float { return $this->on ? $this->preamp : 0.0; } }