-
Hello, I have a question about a jsPsych experiment that I haven't send on pavlovia yet. In the newest version the getAudioBuffer function returns a promise, not the buffer as it did before. I used this function to make my own sound plugin because I do multi-talker situations so I need to load all sounds before calcutate their rms value and apply them some gain (in fact a SNR because one sound is +6 dB higher than the sum of the others). I think I will not be able to do that with the newest version of this function so I keep the ancient for the moment but wonder what can I do if I have to update in the future ? I know promises are prefered because the code doesn't have to wait for the result but in my case, as I do some sound processing it's a necessity to load the sound before... I think... I'm not sure because I'm not familiar with asynchronous code and promises so I may not understand how powerful it is and how to make full use of it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @Franck-El, We use a If you look at the audio-button-response plugin as an example, you'll see that we put all of the code that needs to run after the audio is loaded into a function called To convert old plugin code, you can use a similar strategy. Just wrap everything your old plugin did inside a function, and then invoke that function in the |
Beta Was this translation helpful? Give feedback.
Hi @Franck-El,
We use a
Promise
in order to guarantee that the audio buffer is loaded before the trial starts. The old version of the audio plugins required that users preload their audio files, which led to some confusion when folks didn't preload and were unsure why the audio wasn't playing. ThePromise
allows us to write the plugin in a way that we check that the audio has finished loading before trying to make use of it, and if it hasn't finished loading we can try to load it and wait.If you look at the audio-button-response plugin as an example, you'll see that we put all of the code that needs to run after the audio is loaded into a function called
setupTrial
. This function is call…