<?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: Gesture Synth Weld</title>
    <description>The latest articles on DEV Community by Gesture Synth Weld (@gesturesynthweld).</description>
    <link>https://dev.to/gesturesynthweld</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4110560%2Fb4713ec6-8851-47c2-af65-51f03e9fe40a.png</url>
      <title>DEV Community: Gesture Synth Weld</title>
      <link>https://dev.to/gesturesynthweld</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gesturesynthweld"/>
    <language>en</language>
    <item>
      <title>Your Hand Is a Continuous Signal. A Scale Is Not. That Gap Is the Whole Problem.</title>
      <dc:creator>Gesture Synth Weld</dc:creator>
      <pubDate>Sat, 05 Sep 2026 02:47:07 +0000</pubDate>
      <link>https://dev.to/gesturesynthweld/your-hand-is-a-continuous-signal-a-scale-is-not-that-gap-is-the-whole-problem-2h6l</link>
      <guid>https://dev.to/gesturesynthweld/your-hand-is-a-continuous-signal-a-scale-is-not-that-gap-is-the-whole-problem-2h6l</guid>
      <description>&lt;p&gt;A webcam hand tracker hands you a position, thirty or sixty times a second, as a float&lt;br&gt;
between 0 and 1. A musical scale hands you seven notes per octave. Building a&lt;br&gt;
&lt;a href="https://gesturesynthweld.net/" rel="noopener noreferrer"&gt;browser hand-gesture synthesizer&lt;/a&gt; is mostly the work of&lt;br&gt;
getting from the first thing to the second thing without it sounding like a fax machine.&lt;/p&gt;

&lt;p&gt;I want to write down the specific failure modes, because they are not obvious until you&lt;br&gt;
have shipped one and watched somebody else use it.&lt;/p&gt;
&lt;h2&gt;
  
  
  The naive mapping is unusable, and it is unusable immediately
&lt;/h2&gt;

&lt;p&gt;The obvious first version is one line:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;noteIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;handY&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Map vertical hand position onto the scale, floor it, play that note. This works&lt;br&gt;
perfectly in your head and falls apart the moment a real hand is in front of the camera.&lt;/p&gt;

&lt;p&gt;The reason is that a hand does not hold still. Even braced against a desk, the landmark&lt;br&gt;
estimate jitters — partly real micro-movement, partly the model's own frame-to-frame&lt;br&gt;
noise. If your hand happens to sit near a boundary between two notes, that jitter&lt;br&gt;
straddles the boundary, and &lt;code&gt;Math.floor&lt;/code&gt; faithfully converts a 2-pixel tremor into a&lt;br&gt;
stream of alternating note-on events. You get a trill you did not ask for, at whatever&lt;br&gt;
rate your tracker runs.&lt;/p&gt;

&lt;p&gt;This is not a tuning problem you can smooth away with a lower threshold. It is&lt;br&gt;
structural: you are sampling a noisy continuous signal with a hard comparator.&lt;/p&gt;
&lt;h2&gt;
  
  
  Hysteresis is the fix, and it costs you something real
&lt;/h2&gt;

&lt;p&gt;The standard answer is hysteresis: make the boundary for entering a note different from&lt;br&gt;
the boundary for leaving it. Once note 4 is playing, you have to move meaningfully past&lt;br&gt;
the 4/5 line before note 5 takes over. A Schmitt trigger, borrowed from analog&lt;br&gt;
electronics and applied to pitch.&lt;/p&gt;

&lt;p&gt;It works. It also introduces a genuine trade-off that no amount of cleverness removes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;narrow deadband   →  responsive, but chatters near boundaries
wide deadband     →  stable, but notes feel "sticky" and fast runs get eaten
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where you land depends on what you think the instrument is for. A theremin-style&lt;br&gt;
continuous mode wants almost no quantization at all — the sliding pitch &lt;em&gt;is&lt;/em&gt; the point.&lt;br&gt;
A scale-locked mode wants a deadband wide enough that a beginner can hold a note without&lt;br&gt;
concentrating. These are different instruments wearing the same interface, which is why&lt;br&gt;
&lt;a href="https://gesturesynthweld.net/#scales" rel="noopener noreferrer"&gt;the scale modes&lt;/a&gt; are a mode switch rather than a&lt;br&gt;
slider: they need different deadbands, not different values of one deadband.&lt;/p&gt;
&lt;h2&gt;
  
  
  Latency is a budget, and the tracker spends most of it
&lt;/h2&gt;

&lt;p&gt;End-to-end latency for a gesture instrument is roughly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;camera exposure + capture     ~16-33 ms   (frame rate bound)
hand landmark inference        ~10-30 ms   (model + device bound)
your mapping logic             &amp;lt;1 ms
Web Audio scheduling           ~5-20 ms   (buffer size bound)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Musicians start noticing around 20 ms and start compensating around 40 ms. You are&lt;br&gt;
already at the edge before you have written a line of your own code, and the two big&lt;br&gt;
line items are not yours to optimise — they belong to the camera pipeline and the&lt;br&gt;
inference model.&lt;/p&gt;

&lt;p&gt;The practical consequences:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Do not add smoothing filters casually.&lt;/strong&gt; A 5-frame moving average on the landmark
position is 80 ms at 60fps. You just doubled your latency to fix jitter that
hysteresis fixes for free.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do not schedule notes "now".&lt;/strong&gt; Web Audio's &lt;code&gt;currentTime&lt;/code&gt; plus a small fixed lookahead
is more stable than firing immediately, because it decouples your note timing from
whenever the render quantum happens to land.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frame rate matters more than model accuracy.&lt;/strong&gt; A slightly worse landmark at 60fps
plays better than a slightly better one at 24fps. For this application, precision is
cheaper than latency.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  MIDI export is a different clock, and mixing them up will bite you
&lt;/h2&gt;

&lt;p&gt;Recording the performance for export looks trivial — push &lt;code&gt;{note, time}&lt;/code&gt; on every event —&lt;br&gt;
until you notice you have three candidate clocks in the room:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;performance.now()&lt;/code&gt; — wall clock, drifts against audio&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;audioCtx.currentTime&lt;/code&gt; — the audio clock, what you actually heard&lt;/li&gt;
&lt;li&gt;MIDI ticks — musical time, relative to a tempo you have to choose&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you record wall-clock timestamps and write them out as MIDI ticks, the file will be&lt;br&gt;
subtly wrong in a way that is very hard to hear in isolation and very obvious once it is&lt;br&gt;
sitting next to a drum track in a DAW. The audio clock is the correct source, because&lt;br&gt;
it is the one that produced the sound the performer was responding to.&lt;/p&gt;

&lt;p&gt;The tempo choice is the other trap. A gesture performance has no metronome — the player&lt;br&gt;
was not thinking in bars. Writing the file at an arbitrary 120 BPM means every note&lt;br&gt;
lands on a fractional tick and the DAW's quantize function becomes useless. Picking a&lt;br&gt;
high tick resolution and writing the true durations is more honest: the&lt;br&gt;
&lt;a href="https://gesturesynthweld.net/#midi" rel="noopener noreferrer"&gt;exported .mid&lt;/a&gt; then represents what was played,&lt;br&gt;
and the DAW can impose a grid afterwards if the user wants one.&lt;/p&gt;

&lt;h2&gt;
  
  
  The keyboard fallback is not a consolation prize
&lt;/h2&gt;

&lt;p&gt;Every camera-based instrument needs a no-camera mode, and the reflex is to treat it as&lt;br&gt;
an accessibility checkbox. It is more useful than that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is the only way to A/B your audio engine without the tracker in the signal path.
When something sounds wrong, keyboard mode tells you within seconds whether it is the
synth or the hand tracking.&lt;/li&gt;
&lt;li&gt;It works in the situations where a webcam does not — bad lighting, a shared office, a
locked-down machine, someone who does not want to grant camera permission to a page
they found thirty seconds ago.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That last one is worth dwelling on. Asking for camera access is a large request. A page&lt;br&gt;
that does something useful &lt;em&gt;before&lt;/em&gt; it asks, and that never uploads a frame, is making a&lt;br&gt;
much smaller one. Local-only processing here is not a privacy feature bolted on — it is&lt;br&gt;
what makes the permission prompt reasonable in the first place.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would tell someone starting one
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Build the audio engine first and drive it from the keyboard. Get it sounding good with
zero tracking involved.&lt;/li&gt;
&lt;li&gt;Add the tracker as a second input source, not as the foundation.&lt;/li&gt;
&lt;li&gt;Put hysteresis in before you put smoothing in. You will probably not need smoothing.&lt;/li&gt;
&lt;li&gt;Record on the audio clock from day one. Retrofitting this is miserable.&lt;/li&gt;
&lt;li&gt;Decide early whether you are building a theremin or a keyboard. Trying to be both with
one deadband produces something that is bad at both.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The interesting part of this problem was never the machine learning — the hand tracking&lt;br&gt;
is a solved component you import. The interesting part is that a hand is an analog&lt;br&gt;
controller with no detents, and music mostly is not. Everything that makes&lt;br&gt;
&lt;a href="https://gesturesynthweld.net/" rel="noopener noreferrer"&gt;a gesture instrument&lt;/a&gt; feel like an instrument rather than&lt;br&gt;
a demo lives in how you handle that mismatch.&lt;/p&gt;

</description>
      <category>webaudio</category>
      <category>javascript</category>
      <category>machinelearning</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
