diff --git a/docs/markdown_docs/core_library/jspsych-pluginAPI.md b/docs/markdown_docs/core_library/jspsych-pluginAPI.md index f9d9016a..4cc0396c 100644 --- a/docs/markdown_docs/core_library/jspsych-pluginAPI.md +++ b/docs/markdown_docs/core_library/jspsych-pluginAPI.md @@ -172,7 +172,7 @@ Gets an AudioBuffer that can be played with the WebAudio API or an Audio object var source = context.createBufferSource(); source.buffer = jsPsych.pluginAPI.getAudioBuffer(trial.stimulus); source.connect(context.destination); -startTime = context.currentTime + 0.1; +startTime = context.currentTime; source.start(startTime); ``` diff --git a/plugins/jspsych-audio-button-response.js b/plugins/jspsych-audio-button-response.js index cfd72d26..c27481a8 100644 --- a/plugins/jspsych-audio-button-response.js +++ b/plugins/jspsych-audio-button-response.js @@ -161,7 +161,7 @@ jsPsych.plugins["audio-button-response"] = (function() { // function to end trial when it is time function end_trial() { - + // stop the audio file if it is playing // remove end event listeners if they exist if(context !== null){ @@ -194,7 +194,7 @@ jsPsych.plugins["audio-button-response"] = (function() { // start audio if(context !== null){ - startTime = context.currentTime + 0.1; + startTime = context.currentTime; source.start(startTime); } else { audio.play(); diff --git a/plugins/jspsych-audio-keyboard-response.js b/plugins/jspsych-audio-keyboard-response.js index 784dbbec..106cefdd 100644 --- a/plugins/jspsych-audio-keyboard-response.js +++ b/plugins/jspsych-audio-keyboard-response.js @@ -142,7 +142,7 @@ jsPsych.plugins["audio-keyboard-response"] = (function() { // start audio if(context !== null){ - startTime = context.currentTime + 0.1; + startTime = context.currentTime; source.start(startTime); } else { audio.play(); diff --git a/plugins/jspsych-audio-slider-response.js b/plugins/jspsych-audio-slider-response.js index 2769a027..fa21351a 100644 --- a/plugins/jspsych-audio-slider-response.js +++ b/plugins/jspsych-audio-slider-response.js @@ -41,7 +41,7 @@ jsPsych.plugins['audio-slider-response'] = (function() { button_label: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Button label', - default: undefined, + default: 'Continue', array: false, description: 'Label of the button to advance.' }, @@ -72,7 +72,7 @@ jsPsych.plugins['audio-slider-response'] = (function() { } } - plugin.trial = function(display_element, trial) { + plugin.trial = function(display_element, trial) { // setup stimulus var context = jsPsych.pluginAPI.audioContext(); @@ -97,8 +97,7 @@ jsPsych.plugins['audio-slider-response'] = (function() { } var html = '
'; - html += '
'; - html += '
'; + html += '
'; html += ''; html += '
' for(var j=0; j < trial.labels.length; j++){ @@ -127,7 +126,12 @@ jsPsych.plugins['audio-slider-response'] = (function() { display_element.querySelector('#jspsych-audio-slider-response-next').addEventListener('click', function() { // measure response time var endTime = (new Date()).getTime(); - response.rt = endTime - startTime; + var rt = endTime - startTime; + if(context !== null){ + endTime = context.currentTime; + rt = Math.round((endTime - startTime) * 1000); + } + response.rt = rt; response.response = display_element.querySelector('#jspsych-audio-slider-response-response').value; if(trial.response_ends_trial){ @@ -142,6 +146,14 @@ jsPsych.plugins['audio-slider-response'] = (function() { jsPsych.pluginAPI.clearAllTimeouts(); + if(context !== null){ + source.stop(); + source.onended = function() { } + } else { + audio.pause(); + audio.removeEventListener('ended', end_trial); + } + // save data var trialdata = { "rt": response.rt, @@ -154,10 +166,13 @@ jsPsych.plugins['audio-slider-response'] = (function() { jsPsych.finishTrial(trialdata); } - if (trial.stimulus_duration > 0) { - jsPsych.pluginAPI.setTimeout(function() { - display_element.querySelector('#jspsych-audio-slider-response-stimulus').style.visibility = 'hidden'; - }, trial.stimulus_duration); + var startTime = (new Date()).getTime(); + // start audio + if(context !== null){ + startTime = context.currentTime; + source.start(startTime); + } else { + audio.play(); } // end trial if trial_duration is set @@ -167,7 +182,7 @@ jsPsych.plugins['audio-slider-response'] = (function() { }, trial.trial_duration); } - var startTime = (new Date()).getTime(); + }; return plugin;