Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(speech): livelier recording equalizer — faster poll, sqrt gain, per-bar silhouette
enesedf460816b34
diff --git a/src/renderer/components/DictationOverlay.tsx b/src/renderer/components/DictationOverlay.tsxindex 0b688d840..c9249f8f7 100644--- a/src/renderer/components/DictationOverlay.tsx+++ b/src/renderer/components/DictationOverlay.tsx@@ -77,7 +77,11 @@ export function appendTake(existing: string, take: string): string {return `${a} ${b}`}-const LEVEL_POLL_MS = 100 // ~10Hz+// Faster than the visual 12-bar window needs on its own — the point is to feed more DISTINCT+// samples into that scrolling window (see dictation-equalizer.ts) so the equalizer reads as live+// motion instead of a slow crawl. PcmCapture.level() (RMS of the last chunk) is cheap enough that+// polling twice as often here has no measurable cost.+const LEVEL_POLL_MS = 50 // ~20Hz// Base64-encoded int16 PCM runs ~2.6 MB/min. The ws bridge caps a single frame at// WS_MAX_PAYLOAD (8 MiB, see src/server/ws.ts) — a take left running past ~3 minutes woulddiff --git a/src/renderer/lib/dictation-equalizer.test.ts b/src/renderer/lib/dictation-equalizer.test.tsindex bb85c0746..e24a564e9 100644--- a/src/renderer/lib/dictation-equalizer.test.ts+++ b/src/renderer/lib/dictation-equalizer.test.ts@@ -1,5 +1,34 @@import { describe, expect, it } from 'vitest'-import { EQUALIZER_BAR_COUNT, EQUALIZER_IDLE_FLOOR, equalizerBars } from './dictation-equalizer'+import { EQUALIZER_BAR_COUNT, EQUALIZER_IDLE_FLOOR, equalizerBars, scaleLevel } from './dictation-equalizer'++describe('scaleLevel', () => {+ it('maps silence to 0 (the idle floor is applied by equalizerBars, not here)', () => {+ expect(scaleLevel(0)).toBe(0)+ })++ it('applies sqrt + gain so typical speech reads solidly mid-to-upper height', () => {+ // sqrt(0.1) * 2.5 ≈ 0.7906 — well above the floor, short of full.+ expect(scaleLevel(0.1)).toBeCloseTo(0.7906, 3)+ })++ it('reads a quiet take (~0.05 RMS) at around half height, not near the floor', () => {+ // sqrt(0.05) * 2.5 ≈ 0.559+ expect(scaleLevel(0.05)).toBeCloseTo(0.559, 2)+ })++ it('clamps loud/out-of-range input at full height', () => {+ expect(scaleLevel(1)).toBe(1)+ expect(scaleLevel(0.3)).toBe(1) // already past the point sqrt*gain saturates+ expect(scaleLevel(5)).toBe(1)+ })++ it('is NaN/infinity/negative safe — non-finite or negative input counts as 0', () => {+ expect(scaleLevel(Number.NaN)).toBe(0)+ expect(scaleLevel(-1)).toBe(0)+ expect(scaleLevel(Number.NEGATIVE_INFINITY)).toBe(0)+ expect(scaleLevel(Number.POSITIVE_INFINITY)).toBe(0) // non-finite, same as NaN+ })+})describe('equalizerBars', () => {it('pads an empty history with the idle floor, at the default bar count', () => {@@ -8,32 +37,38 @@ describe('equalizerBars', () => {expect(bars.every((h) => h === EQUALIZER_IDLE_FLOOR)).toBe(true)})- it('left-pads a short history and keeps sample order (most-recent last)', () => {- const bars = equalizerBars([0.5, 0.9], 5, 0.1)- expect(bars).toEqual([0.1, 0.1, 0.1, 0.5, 0.9])+ it('silence (level 0) still floors to a visible minimum, never a flat 0', () => {+ expect(equalizerBars([0], 1)).toEqual([EQUALIZER_IDLE_FLOOR])+ expect(EQUALIZER_IDLE_FLOOR).toBeGreaterThan(0)})- it('keeps only the most recent barCount samples when history overflows', () => {- const history = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]- expect(equalizerBars(history, 3, 0)).toEqual([0.4, 0.5, 0.6])+ it('typical speech (RMS ~0.1) reads solidly mid-height', () => {+ const [h] = equalizerBars([0.1], 1)+ expect(h).toBeGreaterThan(0.4)+ expect(h).toBeLessThan(0.9)})- it('clamps out-of-range samples into [0,1]', () => {- expect(equalizerBars([-5, 5], 2, 0)).toEqual([0, 1])+ it('loud input (RMS 1.0) hits full height', () => {+ expect(equalizerBars([1], 1)).toEqual([1])})- it('floors every bar (including clamped/def NaN samples) at idleFloor', () => {- expect(equalizerBars([0, 0.02, Number.NaN], 3, 0.08)).toEqual([0.08, 0.08, 0.08])+ it('left-pads a short history and keeps sample order (most-recent last)', () => {+ const bars = equalizerBars([0, 1], 5, 0.1)+ // raw 0 → scaleLevel 0 → floored up to 0.1; raw 1 → scaleLevel 1 (unaffected by the floor)+ expect(bars).toEqual([0.1, 0.1, 0.1, 0.1, 1])+ })++ it('keeps only the most recent barCount samples when history overflows', () => {+ const history = [0, 0, 0, 0, 0, 1]+ expect(equalizerBars(history, 3, 0)).toEqual([0, 0, 1])})- it('treats non-finite samples as 0 before flooring', () => {- expect(equalizerBars([Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY], 2, 0.1)).toEqual([- 0.1, 0.1- ])+ it('is NaN/out-of-range safe (non-finite/negative samples floor to idleFloor)', () => {+ expect(equalizerBars([Number.NaN, -5], 2, 0.08)).toEqual([0.08, 0.08])})- it('is a no-op passthrough (modulo floor/clamp) when history already equals barCount', () => {- const history = [0.1, 0.2, 0.3]+ it('is a passthrough at the extremes (0 and 1 map to themselves) when history equals barCount', () => {+ const history = [0, 1, 0]expect(equalizerBars(history, 3, 0)).toEqual(history)})})diff --git a/src/renderer/lib/dictation-equalizer.ts b/src/renderer/lib/dictation-equalizer.tsindex 19fc267b5..bd95ad9fa 100644--- a/src/renderer/lib/dictation-equalizer.ts+++ b/src/renderer/lib/dictation-equalizer.ts@@ -3,17 +3,44 @@// into a fixed-length array of bar heights (0..1) for the ~12-bar equalizer. Pure — no side// effects, no DOM; the component re-renders every poll tick and lets a CSS `transition` on each// bar's height smooth the visual change between calls, so this only needs to pick the numbers.+//+// Per-bar life comes from feeding one recent sample per bar (newest at the right, scrolling left)+// rather than fanning a single current reading out across a static per-index silhouette (e.g.+// "center bars taller"): real speech has moment-to-moment amplitude variation, and a scrolling+// history renders that variation directly as distinct bar heights — closer to a live waveform. A+// static per-index weight curve would have every bar rise and fall in lockstep off one shared+// reading, which reads as a synced pulse, not "alive". Faster polling (see LEVEL_POLL_MS in+// DictationOverlay, 50ms) feeds more distinct samples into the same visible window, which is what+// actually makes the scroll read as motion instead of a slow crawl.export const EQUALIZER_BAR_COUNT = 12// A recording that's just starting (or briefly silent) shouldn't render as 12 flat-zero bars —// a small floor keeps the pill visibly "alive" instead of looking frozen/broken.export const EQUALIZER_IDLE_FLOOR = 0.08+// PcmCapture.level() reports RMS amplitude, and speech RMS sits mostly in ~0.05-0.3 — a linear+// pass-through leaves the bars looking flat/dead even while talking, since that whole range sits+// near the bottom of a 0..1 bar. sqrt() bends the low end of that range upward (a perceptual/+// compressor-style curve, same idea as dB metering), and the gain pushes typical speech up into a+// visibly-moving range instead of hugging the floor. Tuned so a quiet take (~0.05 RMS) still reads+// around half height, typical speech (~0.1) sits solidly mid-to-upper height, and louder speech+// (~0.2+) hits full — clamped so nothing overshoots 100%.+export const EQUALIZER_GAIN = 2.5++/**+ * Nonlinear amplitude → bar-height mapping. `raw` is clamped to [0,1] first (NaN/negative/+ * infinite/out-of-range samples count as 0), then mapped through `sqrt(raw) * gain` and clamped+ * back to [0,1]. Pure — see EQUALIZER_GAIN above for why sqrt+gain instead of a linear pass.+ */+export function scaleLevel(raw: number, gain: number = EQUALIZER_GAIN): number {+ const clamped = Number.isFinite(raw) ? Math.min(1, Math.max(0, raw)) : 0+ return Math.min(1, Math.sqrt(clamped) * gain)+}/*** Maps `history` (oldest→newest amplitude samples) to exactly `barCount` heights, most-recent- * last. Fewer samples than `barCount` (the first ~1.2s of a take) are left-padded with- * `idleFloor`; more samples keep only the most recent `barCount`. Each height is clamped to- * [0,1] and floored at `idleFloor` (NaN/negative samples — a defensive case, `PcmCapture.level()`- * shouldn't produce them — count as 0 and floor the same way).+ * last. Fewer samples than `barCount` (the first ~600ms of a take at the 50ms poll rate) are+ * left-padded with `idleFloor`; more samples keep only the most recent `barCount`. Each sample is+ * run through `scaleLevel` (nonlinear gain, see above) and then floored at `idleFloor` so the pill+ * never looks fully dead, even during a genuinely silent stretch.*/export function equalizerBars(history: readonly number[],@@ -23,8 +50,7 @@ export function equalizerBars(const recent = history.slice(Math.max(0, history.length - barCount))const bars: number[] = new Array(Math.max(0, barCount - recent.length)).fill(idleFloor)for (const raw of recent) {- const clamped = Number.isFinite(raw) ? Math.min(1, Math.max(0, raw)) : 0- bars.push(Math.max(idleFloor, clamped))+ bars.push(Math.max(idleFloor, scaleLevel(raw)))}return bars}diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex 45d53883f..936fb2a04 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -769,10 +769,13 @@ body,.dictation__bar {flex: 1 1 0;max-width: 4px;- min-height: 2px;- border-radius: 2px;- background: #ff453a;- transition: height 90ms ease-out;+ min-height: 3px;+ /* Rounded tops, flat bottoms — reads as a bar rising off a baseline rather than a floating+ pill, and the flat bottom keeps the idle-floor row looking like a deliberate baseline+ (not a row of dots) when the take is quiet. */+ border-radius: 3px 3px 1px 1px;+ background: var(--accent);+ transition: height 70ms ease-out;}/* ---- Terminal node ---- */