Hi, Here is the part of code playing movie and the insert sound (attention getter), Thanks!
% Playback loop: Runs until end of movie or keypress:
while 1
% Wait for next movie frame, retrieve texture handle to it
[tex, pts] = Screen('GetMovieImage', win, movie,1);
% Yes. Draw the new texture immediately to screen:
if (tex>0)
Screen('DrawTexture', win, tex);
% Update display:
Screen('Flip', win);
% Release texture:
Screen('Close', tex);
end
% Valid texture returned? A negative value means end of movie reached:
if tex<=0
% Screen('PlayMovie', movie, 1);
Screen('CloseMovie', movie);
trial = trial + 1;
break;
end
if (keyIsDown==1 && keyCode(up))
% attention getter
function_att_getter;
end;
end
function function_att_getter
global st_dir freqout att_getter deviceid
wavfilename = [st_dir 'sounds\mysound.WAV'];
% play sound file
[audiodata, freq] = audioread(char(wavfilename));
% Perform basic initialization of the sound driver:
InitializePsychSound(1);
% buffer = [];
nrchannels = 2;
audiodata = resample(audiodata, freqout, freq);
[~, ninchannels] = size(audiodata);
audiodata = repmat(transpose(audiodata), nrchannels/ninchannels, 1);
% Open the default audio device [], with default mode [] (==Only playback),
pahandle = PsychPortAudio('Open', deviceid, [], 1, freqout, nrchannels);
% pahandle = PsychPortAudio('Open', 12, [], 1, freqout, nrchannels);
% Fill the audio playback buffer with the audio data 'wavedata':
PsychPortAudio('FillBuffer', pahandle, audiodata);
PsychPortAudio('Start', pahandle, [], 0, 1);
% Wait for end of playback, then stop:
PsychPortAudio('Stop', pahandle, 1);
% Close audio device, shutdown driver:
PsychPortAudio('Close');
end
erm, your main video playing loop loads each frame and displays it. when you call your sound function, control passes to that function and it doesn't return until the sound has been played, so of course the video freezes.
firstly, you should setup sound output only once in your experiment. currently every time you play a sound you are unnecessarily initialising, opening, and closing the sound device.
secondly, when you start the sound playing you do not want to wait for it to finish. you want to start sound playback and go right back to looping and displaying your images...