Increase mic sensitivity range

This commit is contained in:
2025-12-27 18:54:43 +01:00
parent 03a5e8e3c1
commit da02c8977e
2 changed files with 18 additions and 15 deletions

View File

@@ -17,22 +17,20 @@ export class PitchAnalyzer {
/** /**
* Set sensitivity from 0.0 (least sensitive) to 1.0 (most sensitive). * Set sensitivity from 0.0 (least sensitive) to 1.0 (most sensitive).
* Maps to RMS threshold: * Maps to approximate dB Thresholds:
* 0.0 -> 0.1 (Requires loud input) * 0.0 -> -20 dB (0.1 RMS) - Requires loud input
* 0.5 -> 0.03 (Default) * 1.0 -> -60 dB (0.001 RMS) - Very sensitive, picks up background noise
* 1.0 -> 0.005 (Very sensitive)
*/ */
setSensitivity(value: number) { setSensitivity(value: number) {
// Clamp value 0-1 // Clamp value 0-1
const v = Math.max(0, Math.min(1, value)); const v = Math.max(0, Math.min(1, value));
// Linear interpolation or something that feels right // Linear map to dB: -20dB to -60dB
// Let's do a simple mapping: // High sensitivity (1.0) = Lower Threshold (-60dB)
// 1.0 -> 0.002 const db = -20 - (v * 40);
// 0.0 -> 0.1
// linear: 0.1 - (0.098 * v) roughly
this.sensitivityThreshold = 0.1 - (0.095 * v); // Convert dB to RMS amplitude
this.sensitivityThreshold = Math.pow(10, db / 20);
} }
async start(): Promise<void> { async start(): Promise<void> {

View File

@@ -119,8 +119,14 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, s
<label className="control-label" style={{ marginBottom: '12px', fontSize: '16px' }}> <label className="control-label" style={{ marginBottom: '12px', fontSize: '16px' }}>
<span>Microphone Sensitivity</span> <span>Microphone Sensitivity</span>
</label> </label>
<div style={{ display: 'flex', alignItems: 'center', gap: '12px' }}> <div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
<span style={{ fontSize: '12px', opacity: 0.7, minWidth: '30px' }}>Low</span> <div style={{ display: 'flex', justifyContent: 'space-between', fontSize: '12px', opacity: 0.7 }}>
<span>Low (-20dB)</span>
<span style={{ color: '#4cc9f0' }}>
{Math.round(-20 - ((settings.micSensitivity ?? 0.5) * 40))} dB
</span>
<span>High (-60dB)</span>
</div>
<input <input
type="range" type="range"
min="0" min="0"
@@ -128,12 +134,11 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, s
step="0.05" step="0.05"
value={settings.micSensitivity ?? 0.5} value={settings.micSensitivity ?? 0.5}
onChange={(e) => onUpdateSettings({ ...settings, micSensitivity: parseFloat(e.target.value) })} onChange={(e) => onUpdateSettings({ ...settings, micSensitivity: parseFloat(e.target.value) })}
style={{ flex: 1 }} style={{ width: '100%' }}
/> />
<span style={{ fontSize: '12px', opacity: 0.7, minWidth: '30px' }}>High</span>
</div> </div>
<p style={{ fontSize: '12px', opacity: 0.7, margin: '8px 0 0 0' }}> <p style={{ fontSize: '12px', opacity: 0.7, margin: '8px 0 0 0' }}>
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).
</p> </p>
</div> </div>
</div> </div>