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

1 次查看(过去 30 天)
Hi,
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];
commandwindow;
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)]);
tic
Screen(window,'Flip');
time = toc
WaitSecs(10);
position1Index=position1Index+4
position2Index=position2Index+4
% 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);
Screen('CloseAll');
end
end %end CSstimuli for loop
  1 个评论
Geoff Hayes
Geoff Hayes 2014-11-13
编辑:Geoff Hayes 2014-11-13
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)
WaitSecs(9);
% 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).

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Code Generation and Deployment 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by