function [volume] = Noise_Volume_regulation() %% code eventually not used but present in the scripts % 'AirCool_Magstim_48000.wav' % arrow right for increase % arrow left for decrease volume = 0.2; [audiodata, infreq] = psychwavread('AirCool_Magstim_48000.wav'); noise_seconds = 60; noise_short = audiodata(1:infreq*noise_seconds)'; pasound2 = PsychPortAudio('Open', []); sound2 = [noise_short; noise_short]; PsychPortAudio('Volume', pasound2, volume); PsychPortAudio('FillBuffer', pasound2, sound2); noise_ts = PsychPortAudio('Start',pasound2, 1, 1); while 1 [z key_tmp] = KbPressWait; key = find(key_tmp); if key == 37 % arrow left PsychPortAudio('Stop', pasound2,0); noise_ts = PsychPortAudio('Start',pasound2, 1, 0); volume = volume-0.05; if volume <= 0 volume = 0; end PsychPortAudio('Volume', pasound2, volume); disp(num2str(volume)) end if key == 39 % arrow right (increases) PsychPortAudio('Stop', pasound2,0); noise_ts = PsychPortAudio('Start',pasound2, 1, 0); volume = volume+0.05; if volume >= 1 volume = 1; end PsychPortAudio('Volume', pasound2, volume); disp(num2str(volume)) end % stop it if key(1) == 27 || key(1) == 17 % esc PsychPortAudio('Close'); break end end