From da02c8977e1813e8bcad4658fe2de3f42fde16e9 Mon Sep 17 00:00:00 2001 From: Jens Mohrmann Date: Sat, 27 Dec 2025 18:54:43 +0100 Subject: [PATCH] Increase mic sensitivity range --- src/audio/PitchAnalyzer.ts | 18 ++++++++---------- src/components/SettingsModal.tsx | 15 ++++++++++----- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/audio/PitchAnalyzer.ts b/src/audio/PitchAnalyzer.ts index 2a80dda..5f9104c 100644 --- a/src/audio/PitchAnalyzer.ts +++ b/src/audio/PitchAnalyzer.ts @@ -17,22 +17,20 @@ export class PitchAnalyzer { /** * Set sensitivity from 0.0 (least sensitive) to 1.0 (most sensitive). - * Maps to RMS threshold: - * 0.0 -> 0.1 (Requires loud input) - * 0.5 -> 0.03 (Default) - * 1.0 -> 0.005 (Very sensitive) + * Maps to approximate dB Thresholds: + * 0.0 -> -20 dB (0.1 RMS) - Requires loud input + * 1.0 -> -60 dB (0.001 RMS) - Very sensitive, picks up background noise */ setSensitivity(value: number) { // Clamp value 0-1 const v = Math.max(0, Math.min(1, value)); - // Linear interpolation or something that feels right - // Let's do a simple mapping: - // 1.0 -> 0.002 - // 0.0 -> 0.1 - // linear: 0.1 - (0.098 * v) roughly + // Linear map to dB: -20dB to -60dB + // High sensitivity (1.0) = Lower Threshold (-60dB) + const db = -20 - (v * 40); - this.sensitivityThreshold = 0.1 - (0.095 * v); + // Convert dB to RMS amplitude + this.sensitivityThreshold = Math.pow(10, db / 20); } async start(): Promise { diff --git a/src/components/SettingsModal.tsx b/src/components/SettingsModal.tsx index 147d387..8d8e235 100644 --- a/src/components/SettingsModal.tsx +++ b/src/components/SettingsModal.tsx @@ -119,8 +119,14 @@ export const SettingsModal: React.FC = ({ isOpen, onClose, s -
- Low +
+
+ Low (-20dB) + + {Math.round(-20 - ((settings.micSensitivity ?? 0.5) * 40))} dB + + High (-60dB) +
= ({ isOpen, onClose, s step="0.05" value={settings.micSensitivity ?? 0.5} onChange={(e) => onUpdateSettings({ ...settings, micSensitivity: parseFloat(e.target.value) })} - style={{ flex: 1 }} + style={{ width: '100%' }} /> - High

- Adjust if notes are not detected (increase) or if background noise triggers notes (decrease). + Adjust if notes are not detected (increase/right) or if background noise triggers notes (decrease/left).