How can I play a sound for last second of displaying an image?
2 ビュー (過去 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
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 Center および File Exchange で Code Generation and Deployment についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!