Movie with audio after audio file

    

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');



So apparently you already tried different audio APIs (via deviceid parameter of PsychPortAudio('Open',...), related to audio_index in your code).
How about removing the PsychPortAudio module altogether with "clear PsychPortAudio" after closing the audio port?
If PsychPortAudio doesn't close down the audio device correctly, that would be a Windows operating system or audio device driver bug, nothing we could do about it. Maybe a PsychPortAudio('Close') would help, as it shuts down the whole driver?

However, if you don't actually need the precise audio timing and control of PsychPortAudio, you can also use the movie playback functions to play back sound files == "movies without video". You can try just passing the name of an audio file instead of a movie file to the 'OpenMovie' function and it would play it. You couldn't use 'GetMovieImage' for obvious reasons, but would have to check progress in playback time via 'GetMovieTimeIndex' to know when the playback ends == returned time no longer progressing.

-mario