Hi! I’m coding an experiment in which we show short (3-5 s) videos containing audio, in which actors say some words. This works well. Now I need to add pink noise on top of the audio to make it hard to hear the actors’ words.
I can generate pink noise like that:
fs = 20e3;
duration = 100;
y = pinknoise(duration*fs);
I guess ‘PlayMovie’ + ‘Flip’ (see below) is what starts the audio, but I don’t know how to integrate the noise in the audio of the played video. Below is my min code. I’d appreciate any ideas!
A plus question is - how I could manipulate the loudness of the noise (to try out different signal-to-noise options)?
% open the window
[window, windowRect] = Screen('OpenWindow', max(Screen('Screens')))
% open the video
moviename = fullfile(path,'stim','stim_test.avi');
[movie, duration ,fps, None, None] = Screen('OpenMovie', window, moviename);
% Start playback engine: loop = 0, soundvolume = 100
Screen('PlayMovie', movie, 1, 0, 100);
%get an absolute timestamp
vbl = Screen('Flip', window);
% play until q is pressed, then break
while ~strcmp(key, 'q')
[pressed, tpress, keys] = KbCheck;
key = KbName(find(keys));
tex = Screen('GetMovieImage', window, movie, 0);
if tex<0 % End of the movie, break out of loop:
break;
end
if tex==0
continue;
end
% Draw the new texture to screen:
Screen('DrawTexture', window, tex);
% Update display:
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
% Release texture:
Screen('Close', tex);
if pressed == 0
[pressed, tpress, keys] = KbCheck;
key = KbName(find(keys))
end
end % end the loop
% Stop playback:
Screen('PlayMovie', movie, 0);
% Close movie:
Screen('CloseMovie', movie);
I use:
PTB 3.0.18; Windows 10; Matlab 2021a