Urgent.News

What's breaking now, across thousands of outlets.

Tech

Building a Cancellable Web Audio Tone Sequence (and the CSS Bug That Hid Nothing)

I recently added a small feature to a browser bass test : a "step-down" that plays 150, 120, 100, 80, 63, 50, 40, 31.5, 25 and 20 Hz in turn, while you press I can't hear it at the first step you lose. It sounds like ten lines of code. It turned into a nice little lesson in cancellation, clicks and one CSS gotcha. 1. Sequencing tones with async / await The simplest version is a loop that creates…

A recent update to a browser bass test introduced a feature that plays tones at frequencies of 150, 120, 100, 80, 63, 50, 40, 31.5, 25, and 20 Hz sequentially when the user presses a button. The test started as a simple concept but quickly became a valuable lesson in cancellation, clicks, and a CSS bug.

The initial approach to sequencing tones with async/await involved creating an oscillator for each step in a loop and waiting for the specified duration before moving on to the next step. However, this method had a major limitation - it did not account for user actions such as stopping, starting a new tone, or hiding the tab. As a result, the loop would continue playing tones even when the user requested otherwise.

To address this issue, the author turned to a simple counter-based cancellation pattern. Each time the stop function is called, the counter increments, invalidating any running sequences that do not match the current generation value. This approach allows for a single point of cancellation, making the code easier to manage and ensuring that all stopping methods adhere to the same cancellation logic.

The Stop button, starting another tone, the "I can't hear it" button, and the visibilitychange event all call the stop function, providing consistent behavior across different user interactions.

One key aspect of the solution was preventing clicks when starting or stopping sine waves. Abruptly turning a sine wave on or off produces an audible click, particularly noticeable at low frequencies on subwoofers. To avoid this issue, the author implemented gain ramps in and out of each tone, creating an exponential increase and decrease in the gain value over a specified duration. This technique smooths the transition between tones and eliminates the unwanted clicks that would otherwise be heard.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Week 1: Stabilizing the Handshake — Overcoming E2E Integration Roadblocks

Welcome to the final phase of development for MedReachAI. As we transition into the Software Integration phase, my partner, Collin, and I are shifting our focus from building core features to…

  • Solved memory crashes by implementing Direct-to-Bucket architecture for data ingestion.
  • Sprint 7 resolved integration bugs, including Auth & Header Parity and Endpoint Alignment.

How I Built a Referral System That Remembers Past Interactions

Getting a job referral may seem simple, but managing referrals can become difficult when multiple candidates and employees are involved.

  • ReferralHub simplifies referral process with persistent memory system
  • Hindsight technology integrated into ReferralHub backend for memory layer
  • Memory layer enhances referral workflow with historical context retrieval

When to Park an Over-Engineered Feature Branch

Engineering maturity involves knowing when not to ship. Many development teams face a moment where technical ambition outpaces practical utility.

  • Engineering teams struggle to determine when to stop developing over-engineered features.
  • Team decided to park experimental branch to preserve technical research and prevent technical debt.

More from Tuesday 29 September →