Skip to content

setTargetAtTime events silently dropped when startTime equals previous event's endTime #1025

Description

@HamptonMakes

Description

setTargetAtTime silently drops events when the startTime equals the previous event's endTime. This is because AudioParam.cpp line 150 uses <= instead of <:

void AudioParam::setTargetAtTime(float target, double startTime, double timeConstant) {
  auto event = [target, startTime, timeConstant](AudioParam &param) {
    if (startTime <= param.getQueueEndTime()) {  // ← should be <
      return;
    }

Since setTargetAtTime sets its own endTime = startTime (the event has "infinite" conceptual duration), the getQueueEndTime() after a linearRampToValueAtTime ending at time T will be T. A subsequent setTargetAtTime starting at exactly T is then dropped because T <= T is true.

This breaks standard ADSR envelope patterns where setTargetAtTime (decay) is scheduled at exactly the moment linearRampToValueAtTime (attack) ends — a pattern used in every Web Audio ADSR tutorial.

Steps to reproduce

  1. Clone the repro repo: git clone https://github.com/HamptonMakes/rnaa-settargetattime-bug
  2. cd rnaa-settargetattime-bug && npm install && npx expo run:ios
  3. Press "Play broken (no EPS)" — flat beep, no decay
  4. Press "Play fixed (with EPS)" — tone decays naturally

The only difference is adding 0.0001 to the setTargetAtTime start time.

Or, in code:

const ac = new AudioContext();
const osc = ac.createOscillator();
const gain = ac.createGain();
osc.connect(gain);
gain.connect(ac.destination);

const now = ac.currentTime;
const attackEnd = now + 0.02;

gain.gain.setValueAtTime(0.0001, now);
gain.gain.linearRampToValueAtTime(0.3, attackEnd);
// ↓ SILENTLY DROPPED — attackEnd <= attackEnd is true
gain.gain.setTargetAtTime(0.03, attackEnd, 0.1);

osc.start(now);
osc.stop(now + 2);
// Expected: ramp up then exponential decay
// Actual: ramp up, stays at 0.3 forever (flat beep)

Snack or a link to a repository

https://github.com/HamptonMakes/rnaa-settargetattime-bug

React Native Audio API version

0.11.7

React Native version

0.81.5

Platforms

iOS

JavaScript runtime

Hermes

Workflow

Expo Dev Client

Architecture

Fabric (New Architecture)

Build type

Debug app & dev bundle

Device

iOS simulator

Device model

iPhone 16 Pro (iOS 18.6)

Acknowledgements

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions