<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: aboagye Dunca</title>
    <description>The latest articles on DEV Community by aboagye Dunca (@aboagye_dunca_82f13fe1afa).</description>
    <link>https://dev.to/aboagye_dunca_82f13fe1afa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3840034%2F3aea2056-c917-421d-affd-dc1c11e89e09.png</url>
      <title>DEV Community: aboagye Dunca</title>
      <link>https://dev.to/aboagye_dunca_82f13fe1afa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aboagye_dunca_82f13fe1afa"/>
    <language>en</language>
    <item>
      <title>How I Built a Precise Browser Metronome (And Why setTimeout Wasn't Good Enough)</title>
      <dc:creator>aboagye Dunca</dc:creator>
      <pubDate>Mon, 23 Mar 2026 11:43:04 +0000</pubDate>
      <link>https://dev.to/aboagye_dunca_82f13fe1afa/how-i-built-a-precise-browser-metronome-and-why-settimeout-wasnt-good-enough-2cm6</link>
      <guid>https://dev.to/aboagye_dunca_82f13fe1afa/how-i-built-a-precise-browser-metronome-and-why-settimeout-wasnt-good-enough-2cm6</guid>
      <description>&lt;p&gt;&lt;em&gt;A deep dive into Web Audio API timing, and the surprising complexity behind a "simple" click.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The Problem With Online Metronomes
&lt;/h2&gt;

&lt;p&gt;I play guitar. Not professionally — just a hobby I've had for years. Like most self-taught musicians, I knew I needed a metronome, and like most people in 2026, I reached for a browser-based one.&lt;/p&gt;

&lt;p&gt;What I found was disappointing.&lt;/p&gt;

&lt;p&gt;Most online metronomes fall into two categories: overly bloated apps with ads everywhere, or minimal tools that drift at higher tempos. Try setting one to 180 BPM and you'll hear it — the clicks start to feel uneven, rushed, then behind. It's subtle, but as a musician, you &lt;em&gt;feel&lt;/em&gt; it.&lt;/p&gt;

&lt;p&gt;So I decided to build my own: &lt;a href="https://tapmetronome.app/" rel="noopener noreferrer"&gt;Tap Metronome&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why JavaScript Timers Fail at Music
&lt;/h2&gt;

&lt;p&gt;Here's something most web developers don't realize: &lt;strong&gt;&lt;code&gt;setTimeout&lt;/code&gt; and &lt;code&gt;setInterval&lt;/code&gt; are not accurate enough for music.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The browser's event loop is single-threaded. When you write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;playClick&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 120 BPM&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You're asking the browser to schedule a callback &lt;em&gt;approximately&lt;/em&gt; every 500ms. But if the main thread is busy — rendering, garbage collecting, handling a scroll event — that callback could fire 10ms, 30ms, or even 100ms late.&lt;/p&gt;

&lt;p&gt;For a visual animation, 30ms of drift is invisible. For a metronome, it's the difference between "tight" and "sloppy."&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution: Web Audio API Scheduling
&lt;/h2&gt;

&lt;p&gt;The Web Audio API has its own high-precision clock, separate from the main thread. It runs on a dedicated audio thread with sample-accurate timing.&lt;/p&gt;

&lt;p&gt;The key insight is &lt;strong&gt;look-ahead scheduling&lt;/strong&gt;: instead of playing sounds reactively, you schedule them ahead of time into the audio context's timeline.&lt;/p&gt;

&lt;p&gt;The approach works like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use &lt;code&gt;setInterval&lt;/code&gt; as a coarse "wake-up" call (~25ms interval)&lt;/li&gt;
&lt;li&gt;Each wake-up, calculate which beats fall within the next ~100ms window&lt;/li&gt;
&lt;li&gt;Schedule those beats using &lt;code&gt;AudioContext.currentTime&lt;/code&gt; with precise timestamps&lt;/li&gt;
&lt;li&gt;The audio thread plays them at exactly the right moment
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Main Thread:    |--wake--|--wake--|--wake--|--wake--|
Audio Thread:   tick.........tick.........tick.........
                 ^ scheduled ahead    ^ sample-accurate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This two-tier architecture means the main thread can be janky, laggy, or busy — the clicks still land on time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Beyond the Click: Features That Mattered
&lt;/h2&gt;

&lt;p&gt;Once I had rock-solid timing, I focused on what musicians actually need during practice:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multiple Time Signatures&lt;/strong&gt; — Not everything is 4/4. Waltzes need 3/4, marches need 2/4, and many jazz and folk pieces use 6/8. The metronome accents the first beat of each measure for clear phrasing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Subdivisions&lt;/strong&gt; — Quarter notes, eighth notes, and triplets. When you're working on a fast passage, slowing down and subdividing is one of the most effective practice techniques.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tap Tempo&lt;/strong&gt; — Sometimes you hear a song and want to match its tempo. Tap along and the BPM calculates automatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Visual Beat Indicators&lt;/strong&gt; — Especially useful when you can't or don't want to hear the click (late night practice with headphones, checking your internal timing).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Preset BPM Ranges&lt;/strong&gt; — Quick access to common tempos: 60 BPM for slow practice, 120 BPM as the universal standard, genre-specific presets for rock, jazz, ballads, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lessons Learned
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Audio on mobile is a minefield.&lt;/strong&gt; iOS requires a user gesture before any audio can play. Android Chrome has its own quirks. I spent more time on cross-browser audio initialization than on any other single feature.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Less is more.&lt;/strong&gt; My early versions had too many options visible at once. Musicians want to set a tempo and &lt;em&gt;play&lt;/em&gt;, not configure a spaceship. Every UI element I removed made the tool better.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Performance tempo affects psychology.&lt;/strong&gt; This was a rabbit hole I didn't expect to fall into. Research shows that tempos near 120 BPM feel "natural" to most humans — it matches a brisk walking pace. Below 60 BPM, music feels like it's dragging. Above 160, it becomes physically stimulating. I used these insights to inform the default settings and practice recommendations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Internationalization matters for music tools.&lt;/strong&gt; Musicians are everywhere. The app now supports English, Chinese, Japanese, Korean, and Spanish, with more planned.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try It
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://tapmetronome.app/" rel="noopener noreferrer"&gt;&lt;strong&gt;Tap Metronome&lt;/strong&gt;&lt;/a&gt; is free, runs entirely in your browser, no sign-up required. It works on desktop and mobile.&lt;/p&gt;

&lt;p&gt;If you're a musician, I'd love to hear how it fits into your practice routine. If you're a developer, I'd welcome feedback on the Web Audio API implementation.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Have questions or feedback? Reach out at &lt;a href="https://tapmetronome.app/contact" rel="noopener noreferrer"&gt;tapmetronome.app/contact&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
