Noise_Volume_regulation.m 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. function [volume] = Noise_Volume_regulation()
  2. %% code eventually not used but present in the scripts
  3. % 'AirCool_Magstim_48000.wav'
  4. % arrow right for increase
  5. % arrow left for decrease
  6. volume = 0.2;
  7. [audiodata, infreq] = psychwavread('AirCool_Magstim_48000.wav');
  8. noise_seconds = 60;
  9. noise_short = audiodata(1:infreq*noise_seconds)';
  10. pasound2 = PsychPortAudio('Open', []);
  11. sound2 = [noise_short; noise_short];
  12. PsychPortAudio('Volume', pasound2, volume);
  13. PsychPortAudio('FillBuffer', pasound2, sound2);
  14. noise_ts = PsychPortAudio('Start',pasound2, 1, 1);
  15. while 1
  16. [z key_tmp] = KbPressWait;
  17. key = find(key_tmp);
  18. if key == 37 % arrow left
  19. PsychPortAudio('Stop', pasound2,0);
  20. noise_ts = PsychPortAudio('Start',pasound2, 1, 0);
  21. volume = volume-0.05;
  22. if volume <= 0
  23. volume = 0;
  24. end
  25. PsychPortAudio('Volume', pasound2, volume);
  26. disp(num2str(volume))
  27. end
  28. if key == 39 % arrow right (increases)
  29. PsychPortAudio('Stop', pasound2,0);
  30. noise_ts = PsychPortAudio('Start',pasound2, 1, 0);
  31. volume = volume+0.05;
  32. if volume >= 1
  33. volume = 1;
  34. end
  35. PsychPortAudio('Volume', pasound2, volume);
  36. disp(num2str(volume))
  37. end
  38. % stop it
  39. if key(1) == 27 || key(1) == 17 % esc
  40. PsychPortAudio('Close');
  41. break
  42. end
  43. end