I am new to psychtoolbox and love it! It’s by far the best software for experiments I’ve used… I’ve managed to code a task with visual stimulation and that all works perfectly. I am struggling a bit adding an auditory stimulus that is meant to change volume. However, it seems to always play the same volume. Here is minimal code that has this problem (my actual code also changes pitch and number of beeps, but I’ve deleted these parts as the problem does not depend on them). There are no error messages that come up.
I’d be very grateful for any advice!
% Perform basic initialization of the sound driver:
InitializePsychSound(1);
% Number of channels and Frequency of the sound
nrchannels = 2;
freq = 48000;
% hould we wait for the device to really start(1=yes), info:see help
% psychportaudio
waitForDeviceStart=1;
% Open Psych-Audio port, with the follow arguements
% (1) [] = default sound device
% (2) 1 = sound playback only
% (3) 1 = default level of latency
% (4) Requested frequency in samples per second
% (5) 2 = stereo putput
pahandle = PsychPortAudio('Open', [], 1, 1, freq, nrchannels);
% Settings for the sound
sound_pause= 0.01; % pause between beeps
total_sound_duration =0.3; % durations of the total train of beeps
% We want a loop to play sounds that differ in volume
vals = 0:0.1:1;
for iv = 1:length(vals)
% Set the volume
PsychPortAudio('Volume', sound_settings.pahandle, vals(iv));
% Make a beep
cur_freq = 500;
cur_beepDuration = total_sound_duration - sound_settings.sound_pause;
myBeep = MakeBeep(cur_freq, cur_beepDuration, 48000);
% Fill the audio playback buffer with the audio data, doubled for stereo presentation
PsychPortAudio('FillBuffer', pahandle, [myBeep; myBeep]);
% Set start delay for first beep, others will be computed in loop
start_delay=0; %'start immediately' - will later be replaced by start_delay specified above so that we get pauses between the beeps
% Play the sound (with a pause before to get a series of beeps,
% rather than just one long sound)
WaitSecs(2)
PsychPortAudio('Start',pahandle,1,start_delay,waitForDeviceStart)
% get exact time when the beep stopped
[actualStartTime, ~, ~, estStopTime] = PsychPortAudio('Stop',pahandle,1,1);
end
Additional info:
3.0.17 - Flavor: beta - Corresponds to SVN Revision 12153
Mac OS 10.15 (task will later be run on a windows computer; data collection behaviour + MEG), but to program I have a Mac… Matlab 2018a
========================================================================================
H77ZC-NL-202192413322:cc231de4e3094ca12b931ef0ced579a366890ed8ba2031cf6f784136bb7fa954
========================================================================================