Welcome! Log In Create A New Profile

Advanced

Playing background music/noise

Posted by Jaewon 
Playing background music/noise
November 02, 2020 01:47PM
If you want to play a sound/music the whole time during the task, turn on the alert_function, as shown in this link, and write your alert_function.m as below. The wav file will be played during the ITI and even while the task is paused.

function alert_function(hook,MLConfig,TrialRecord)

persistent id
filename = 'noise.wav';  % change the filename appropriately

switch hook
    case 'init'          % when the [RUN] button is clicked
        id = mgladdsound(filename);
        mglsetproperty(id, 'looping',true, 'collective',false);
        mglplaysound(id);

    case 'fini'          % when the task window is closed
        mgldestroysound(id);
end

end
Attachments:
open | download - alert_function.m (2.2 KB)

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.