AETERNAE AI RESEARCH LLC INDEPENDENT RESEARCH
ÆAETERNAERESEARCH
Sign inRequest access
← Malware catalog

Attributed metadata history

REPORTPUBLIC METADATA

Building a Piano in the Browser: From Keyboard Input to Musical Frequency

Building a Piano in the Browser: From Keyboard Input to Musical Frequency Have you ever wondered how complex it is to build a responsive, polyphonic musical instrument using vanilla JavaScript and modern browser APIs? A lot of developers assume that creating a playable web piano requires heavy third-party gaming frameworks or WebAssembly engines. In reality, modern browser primitives—specifically the Web Audio API and DOM pointer events—provide everything necessary to build a lightning-fast keyboard with under 15ms of latency. In this tutorial, we will build a polyphonic browser piano engine from scratch: Mapping computer keyboard inputs to musical pitches Calculating equal temperament frequencies mathematically Managing low-latency polyphonic voice triggering Designing a clean visual keyboard in CSS Step 1: Mapping Computer Keys to Musical Pitches To allow users to play immediately using their laptop keyboard, we can map the QWERTY keyboard's home row to white piano keys, and the row above it to black accidentals: // Key mapping: QWERTY key code -> Standard MIDI Note Number // Middle C (C4) is MIDI note 60 const KEY_MAP: Record<string, number> = { // White Keys 'KeyA': 60, // C4 'KeyS': 62, // D4 'KeyD': 64, // E4 'KeyF': 65, // F4 'KeyG': 67, // G4 'KeyH': 69, // A4 (Concert Pitch 440 Hz) 'KeyJ': 71, // B4 'KeyK': 72, // C5 // Black Keys (Accidentals) 'KeyW': 61, // C#4 / Db4 'KeyE': 63, // D#4 / Eb4 'KeyT': 66, // F#4 / Gb4 'KeyY': 68, // G#4 / Ab4 'KeyU': 70, // A#4 / Bb4 }; Step 2: Synthesizing the Audio Voice While production applications often use high-resolution acoustic samples, you can synthesize rich musical tones directly using Web Audio's native OscillatorNode with an exponential decay envelope: class SynthVoice { private ctx: AudioContext; constructor(ctx: AudioContext) { this.ctx = ctx; } public trigger(frequency: number, durationSeconds: number = 1.5): void { const osc = this.ctx.createOscillator(); const gain = this.ctx.createGain(); // A triangle wave offers warm, harmonic character similar to a wooden tone osc.type = 'triangle'; osc.frequency.setValueAtTime(frequency, this.ctx.currentTime); // Exponential gain decay mimics acoustic piano string dampening const now = this.ctx.currentTime; gain.gain.setValueAtTime(0.001, now); gain.gain.exponentialRampToValueAtTime(0.4, now + 0.02); // 20ms attack gain.gain.exponentialRampToValueAtTime(0.0001, now + durationSeconds); // Decay osc.connect(gain); gain.connect(this.ctx.destination); osc.start(now); osc.stop(now + durationSeconds); } } Step 3: Polyphony and Preventing Key Repeat Glitches When a user holds down a key on a physical keyboard, the operating system's accessibility daemon triggers repeated keydown events (e.g., aaaaaaaa). In a music tool, this causes machine-gun re-triggering. We solve this by maintaining an active Set of currently depressed keys: const activeKeys = new Set<string>(); const audioCtx = new AudioContext(); const synth = new SynthVoice(audioCtx); window.addEventListener('keydown', (e) => { // Prevent repeating key events when key is held down if (e.repeat || activeKeys.has(e.code)) return; const midi = KEY_MAP[e.code]; if (midi) { activeKeys.add(e.code); // Unlock browser audio context if suspended if (audioCtx.state === 'suspended') { audioCtx.resume(); } // Convert MIDI to frequency: f = 440 * 2^((midi - 69) / 12) const freq = 440 * Math.pow(2, (midi - 69) / 12); synth.trigger(freq); highlightKeyUI(midi, true); } }); window.addEventListener('keyup', (e) => { if (activeKeys.has(e.code)) { activeKeys.delete(e.code); const midi = KEY_MAP[e.code]; if (midi) { highlightKeyUI(midi, false); } } }); Step 4: Styling the Keyboard Layout In CSS, keyboard layouts use absolute positioning for black

Reference details

Source category
research-report
First reported
Dec 03, 2026 18:19 UTC
Last reported
Dec 03, 2026 18:19 UTC
Catalog updated
Dec 03, 2026 18:26 UTC
Record ID
bc4d8219f3f818fa0d8fdde43f56016cda4af85e1f247659698d58ea5ace2220

Published indicators

Network indicators are visibly defanged. This page does not make them clickable or send them to another service.

No validated file hashes or network indicators are stored for this record.

Source observations

intelligence_src_6dc544294b7f21f98a

Source-provided label
Publisher RSS metadata
Evidence class
mentioned in report
Confidence
Not reported
Observed
Dec 03, 2026 18:19 UTC
Retrieved
Dec 03, 2026 18:26 UTC

This record contains metadata and attribution only. It does not host, download, unpack, render, or execute malware samples.

Feed collection status

Sources represented on this page. Publication and observation dates describe the content; successful batch dates describe local collection. A recent batch does not certify complete coverage or current provider availability.

1 sources: 0 stale, 0 needing attention, 0 paused, 0 unverified.

Review source update dates and status
  • intelligence_src_6dc544294b7f21f98aRecent successful batchLast successful batch: Last attempt:

Stale means older than twice the recorded collection interval, with a minimum of one hour; without an interval, the threshold is 24 hours. Cached content remains available while a feed is stale, paused, or unverified.