Sound stimulus not playing online

sifiExp2.psyexp (55.8 KB)

Code: Michael Barnett-Cowan / sifi · GitLab

I have built a quick experiment in the builder and uploaded the code to Pavlovia. It runs fine when running from psychopy (ie offline) but when I ran it online it gave me the error:

error: invalid argument to cancelandholdattime: null

after displaying a fixation cross on the screen for some time but not playing a sound. The sound is initialized as:

soundFlash1 = new sound.Sound({
    win: psychoJS.window,
    value: 'A',
    secs: 0.016,
    });
  soundFlash1.setVolume(1);
  soundFlash2 = new sound.Sound({
    win: psychoJS.window,
    value: 'A',
    secs: 0.016,
    });
  soundFlash2.setVolume(1);

When looking at the console, the following error message is logged:

Error: Invalid argument to cancelAndHoldAtTime: null
    Kn Debug.ts:8
    cancelAndHoldAtTime Param.ts:417
    setRampPoint Param.ts:298
    targetRampTo Param.ts:356
    targetRampTo Signal.ts:134
    triggerRelease Envelope.ts:420
    _triggerEnvelopeRelease Synth.ts:123
    triggerRelease Monophonic.ts:91
    stop sound-2020.2.js:220
    stop sound-2020.2.js:436
    audioRoutineEachFrame sifiExp2.js:782
    _runNextTasks util-2020.2.js:1567
    _runNextTasks util-2020.2.js:1571
    _runNextTasks util-2020.2.js:1571
    update util-2020.2.js:1524
core-2020.2.js:1822:12
    onerror https://run.pavlovia.org/MBClab/sifi/lib/core-2020.2.js:1822

I’m assuming the code error lies when it comes to my stopping condition for audio; the start/stop sequence is given by:

// start/stop soundFlash1
    if (t >= 1 && soundFlash1.status === PsychoJS.Status.NOT_STARTED) {
      // keep track of start time/frame for later
      soundFlash1.tStart = t;  // (not accounting for frame time here)
      soundFlash1.frameNStart = frameN;  // exact frame index

      psychoJS.window.callOnFlip(function(){ soundFlash1.play(); });  // screen flip
      soundFlash1.status = PsychoJS.Status.STARTED;

    }
    frameRemains = 1 + VAR_LENGTH_MS - psychoJS.window.monitorFramePeriod * 0.75;  // most of one frame period left

    if ((soundFlash1.status === PsychoJS.Status.STARTED || soundFlash1.status === PsychoJS.Status.FINISHED) && t >= frameRemains) {
      if (t >= 1 + VAR_LENGTH_MS){
        soundFlash1.stop();
        soundFlash1.status = PsychoJS.Status.FINISHED;
        console.log("Stopping SF1, status: ", soundFlash1.status);
      }
    }

I know it starts, but it doesn’t get to the “stopping SF1” console log, presumably the error is in soundFlash1.stop(). Note that while it says the start condition is reached, in the first clause, no sound is ever made.

I would appreciate any pointers for how to solve this issue!