From a84ca70ab1d0cae6267042d9a0ee87ceaf80dddc Mon Sep 17 00:00:00 2001 From: Bankminer78 Date: Wed, 17 Jul 2024 10:41:53 -0400 Subject: [PATCH 1/2] Fixed negative rt bug by making recording startTime with AudioContext --- packages/plugin-audio-button-response/src/index.ts | 13 ++++++++----- packages/plugin-audio-slider-response/src/index.ts | 7 +++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/plugin-audio-button-response/src/index.ts b/packages/plugin-audio-button-response/src/index.ts index 954c7b64..96ad72ec 100644 --- a/packages/plugin-audio-button-response/src/index.ts +++ b/packages/plugin-audio-button-response/src/index.ts @@ -147,8 +147,6 @@ class AudioButtonResponsePlugin implements JsPsychPlugin { } async trial(display_element: HTMLElement, trial: TrialType, on_load: () => void) { - // hold the .resolve() function from the Promise that ends the trial - this.trial_complete; this.params = trial; this.display = display_element; // setup stimulus @@ -217,9 +215,6 @@ class AudioButtonResponsePlugin implements JsPsychPlugin { this.disable_buttons(); } - // start time - this.startTime = performance.now(); - // end trial if time limit is set if (trial.trial_duration !== null) { this.jsPsych.pluginAPI.setTimeout(() => { @@ -229,9 +224,17 @@ class AudioButtonResponsePlugin implements JsPsychPlugin { on_load(); + // start time + this.startTime = performance.now(); + if (this.context !== null) { + this.startTime = this.context.currentTime; + } + + // start audio this.audio.play(); return new Promise((resolve) => { + // hold the .resolve() function from the Promise that ends the trial this.trial_complete = resolve; }); } diff --git a/packages/plugin-audio-slider-response/src/index.ts b/packages/plugin-audio-slider-response/src/index.ts index 2a803a74..f43e376f 100644 --- a/packages/plugin-audio-slider-response/src/index.ts +++ b/packages/plugin-audio-slider-response/src/index.ts @@ -156,8 +156,6 @@ class AudioSliderResponsePlugin implements JsPsychPlugin { } async trial(display_element: HTMLElement, trial: TrialType, on_load: () => void) { - // record webaudio context start time - this.startTime; this.params = trial; this.display = display_element; // for storing data related to response @@ -325,7 +323,12 @@ class AudioSliderResponsePlugin implements JsPsychPlugin { } }); + //record start time this.startTime = performance.now(); + // record webaudio context start time + if (this.context !== null) { + this.startTime = this.context.currentTime; + } // start audio this.audio.play(); From 5552e48b4bd0961c0dcb7dea31b7218e22e10de2 Mon Sep 17 00:00:00 2001 From: Bankminer78 Date: Wed, 17 Jul 2024 10:51:31 -0400 Subject: [PATCH 2/2] Added patch changeset --- .changeset/cuddly-coins-fold.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/cuddly-coins-fold.md diff --git a/.changeset/cuddly-coins-fold.md b/.changeset/cuddly-coins-fold.md new file mode 100644 index 00000000..eb675c9f --- /dev/null +++ b/.changeset/cuddly-coins-fold.md @@ -0,0 +1,6 @@ +--- +"@jspsych/plugin-audio-button-response": patch +"@jspsych/plugin-audio-slider-response": patch +--- + +Fixed negative response times being recorded by ensuring if the AudioContext object exists, startTime is recorded with respect to that.