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

조회 수: 1 (최근 30일)
Chelsea
Chelsea 2014년 11월 13일
편집: Geoff Hayes 2014년 11월 13일
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