Skip to content

Commit

Permalink
Fixed negative rt bug by making recording startTime with AudioContext
Browse files Browse the repository at this point in the history
  • Loading branch information
Bankminer78 committed Jul 17, 2024
1 parent 7db7095 commit a84ca70
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
13 changes: 8 additions & 5 deletions packages/plugin-audio-button-response/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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;
});
}
Expand Down
7 changes: 5 additions & 2 deletions packages/plugin-audio-slider-response/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a84ca70

Please sign in to comment.