Hi all,
I'm trying to write an experiment using PTB in which trials where a simple audio file is played are alternated with trials where a movie (including audio track) is played.
The trials work separately, and when I first play a movie and then an audiofile, this works fine as well. The issue is when a moviefile is played after an audiofile has already been played. PTB just shows the first frame of the movie and freezes.
I've written a short demo to locate the problem. I'm using Matlab R2016a and PTB 3.0.12 on a Windows 7 64-bit OS.
Note that when I replace the "Screen('PlayMovie', movie, 1);" line with
Screen('PlayMovie', movie, 1, [], [], 2) to block the movie's audio, the movie DOES play, but of course without audio. So it seems there is a clash between the movie's audio and the previous use of PsychPortAudio (although I do close the audio object handle).
Is there any way to get around this?
Thanks!
--------
%% PTB & window
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, grey, [10, 10, 550, 550]);
%% audio
InitializePsychSound;
audio = PsychPortAudio('Open', audio_index-1, 1, 0, [], 1); % mono
wavedata = audioread(audfilename)';
wavedata = resample(wavedata, 44100, 10000);
PsychPortAudio('FillBuffer', audio, wavedata);
PsychPortAudio('Stop', audio, 1);
PsychPortAudio('Close', audio);
%video
movie = Screen('OpenMovie', window, moviename);
% Start playback engine:
Screen('PlayMovie', movie, 1);
while true
% Wait for next movie frame, retrieve texture handle to it
tex = Screen('GetMovieImage', window, movie, 1);
% Valid texture returned? A negative value means end of movie reached:
if tex<=0
% We're done, break out of loop:
break;
end
Screen('DrawTexture', window, tex);
% Update display:
Screen('Flip', window);
% Release texture:
Screen('Close', tex);
end
% Close movie:
Screen('CloseMovie', movie);
%%
Screen('CloseAll');