Merge pull request #3348 from vzhang03/audio-player

Fixed negative rt bug in audio-button and audio-slider plugin.
This commit is contained in:
Josh de Leeuw 2024-07-17 19:04:54 -04:00 committed by GitHub
commit e374226e32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 7 deletions

View File

@ -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.

View File

@ -147,8 +147,6 @@ class AudioButtonResponsePlugin implements JsPsychPlugin<Info> {
}
async trial(display_element: HTMLElement, trial: TrialType<Info>, 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<Info> {
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<Info> {
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;
});
}

View File

@ -156,8 +156,6 @@ class AudioSliderResponsePlugin implements JsPsychPlugin<Info> {
}
async trial(display_element: HTMLElement, trial: TrialType<Info>, 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<Info> {
}
});
//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();