Clear Filters
Clear Filters

How can I play a sound for last second of displaying an image?

2 views (last 30 days)
I have a for loop that displays pairs of images. For some of the image pairs, I want to play a one second white noise clip, for the last second that the pictures are displayed (they're displayed for 10 seconds). How can I do this? Here's the part of code I'm working on now... Thanks!
AllTexture = [CSTexture, USTexture];
Screen('DrawTexture',window,CSTexture, [], [position1Order(position1Index), position1Order(position1Index+1), position1Order(position1Index+2), position1Order(position1Index+3)]);
Screen('DrawTexture',window,USTexture, [], [position2Order(position2Index), position2Order(position2Index+1), position2Order(position2Index+2), position2Order(position2Index+3)]);
time = toc
% Sound
if time==9
pahandle = PsychPortAudio('Open', [], [], 0, freq, nrchannels);
% Fill the audio playback buffer with the audio data 'wavedata':
PsychPortAudio('FillBuffer', pahandle, wavedata);
t1 = PsychPortAudio('Start', pahandle, 1, 1, 0);
PsychPortAudio('Stop', pahandle, 1,0);
% Wait for release of all keys on keyboard:
% Close the audio device:
PsychPortAudio('Close', pahandle);
end %end CSstimuli for loop
  1 Comment
Geoff Hayes
Geoff Hayes on 13 Nov 2014
Edited: Geoff Hayes on 13 Nov 2014
Chelsea - why not just wait for nine seconds then play the one second sound clip before moving to the next pair of pictures (rather than using tic and toc)
% now play sound for one second
% now continue to next pair
I don't think that the above code in the if block would ever fire due to the elapsed time because toc is immediately called after tic (or one line later) without there ever being a pause of at least one second. So probably time is less than one (very close to zero).

Sign in to comment.

Answers (0)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!