Play audio stimuli in CursorFeedbackTask

Forum for discussion on different user applications
Posts: 18
Joined: 04 Jan 2012, 08:29

Play audio stimuli in CursorFeedbackTask

Post by vladi » 15 Jan 2013, 09:01


I would like to play a audio file as a go signal and stop signal during a CursorFeedbackTask. In particular before the feedback starts and after it ends. Therefore I have somehow to combine the CursorTask Module and StimulusPresentation Module. Is that the right way??. I manged to play a audio file using a windows function PlaySounds but it is not really fluent because I have to freeze bci2000 for some time until the sound is played. So I think it would be more elegant to use some code from StimulusPresentation Module but I am not sure how to achieve this. Thank you in advance.


Posts: 1146
Joined: 12 Feb 2003, 11:06

Re: Play audio stimuli in CursorFeedbackTask

Post by mellinger » 30 Jan 2013, 12:57


BCI2000 contains a WavePlayer class, which wraps DirectSound on Windows, and uses QSound output on other platforms.

Using the WavePlayer class, you can play sound asynchronously. Just add one object of type WavePlayer for each sound to your task class, and load sounds during initialize. Unfortunately, on Windows versions newer than XP, DirectSound is not so direct any more, and is instead provided through a compatibility layer. That may introduce considerable delay the first time a sound is played through DirectSound. To avoid that, you should create a dummy sound file containing a second of silence, and play that through a temporary WavePlayer instance in OnInitialize().



Who is online

Users browsing this forum: No registered users and 2 guests