Thanks for your reply Mario, it really helped me to understand the issue. However, now that I managed to ‘append’ to the buffer while in playback, the appended segments don’t actually get played. I attach a minimal example:
pahandle = PsychPortAudio('Open', 0, 1, 1, 44100, 1); %deviceID, mode, latency mode, freq, chann, buffersize, suddestedLate, select
PsychPortAudio('RunMode', pahandle, 1);%
% Make a beep which we will play back to the user
myBeep = MakeBeep(500, 1, 44100);
silence= zeros(1, 22050) ;
PsychPortAudio('FillBuffer', pahandle, [myBeep silence myBeep silence myBeep silence]);
PsychPortAudio('Start', pahandle);
PsychPortAudio('FillBuffer', pahandle, myBeep , 1);
and the output:
PTB-INFO: Closing handle 0.
PTB-INFO: Trying to resume potentially suspended PulseAudio server... ... status 0
PTB-INFO: Trying to suspend potentially running PulseAudio server... ... status 0
PTB-INFO: Using modified PortAudio V19.6.0-devel, revision 396fe4b6699ae929d3a685b3ef8a7e97396139a4
PTB-INFO: New audio device 0 with handle 0 opened as PortAudio stream:
PTB-INFO: For 1 channels Playback: Audio subsystem is ALSA, Audio device name is HDA Intel PCH: ALC3260 Analog (hw:0,0)
PTB-INFO: Real samplerate 44100.000000 Hz. Input latency 0.000000 msecs, Output latency 9.977324 msecs.
Tested on two machines.
EDIT: to clarify, it doesn’t throw an error for ‘FillBuffer’ , it also returns the values for ETA and so on, but the beep never gets played (I can hear 3 beeps instead of 4). If I define 2 repetitions when starting the device, I can hear 6 beeps, indicating the first fill gets played 2 times.
EDIT2:
(changed frequency of the second fill to differentiate between the intial fill vs the one during playback)
I tried several ‘repetition’ values, and it looks like the value 0 is the problem. It only plays the initial fill. For example here
%-----------
% Setup and cleanup
%-----------
AssertOpenGL;
InitializePsychSound(1);
PsychPortAudio('Close'); %make sure all audio devices are closed
PsychPortAudio('Verbosity', 12); %how much info to print out
%-----------
% Audio
%-----------
%find ID of your device
x = PsychPortAudio('GetDevices'); % run to choose ID - usually many devices
pahandle = PsychPortAudio('Open', 5, 1, 1, 44100, 1); %deviceID, mode, latency mode, freq, chann, buffersize, suddestedLate, select
PsychPortAudio('RunMode', pahandle, 1);%
% Make a beep which we will play back to the user
myBeep = MakeBeep(500, 1, 44100);
myBeep2 = MakeBeep(600, 1, 44100);
silence = zeros(1, 0.5*44100);
bigBuffer = PsychPortAudio('CreateBuffer', [], [myBeep silence myBeep silence myBeep silence]);
smallBuffer = PsychPortAudio('CreateBuffer', [], [myBeep2 silence]);
PsychPortAudio('FillBuffer', pahandle, bigBuffer);
PsychPortAudio('Start', pahandle, 0);
[x, y, z] = PsychPortAudio('FillBuffer', pahandle, smallBuffer , 1);
[x, y, z] = PsychPortAudio('FillBuffer', pahandle, smallBuffer , 1);
[x, y, z] = PsychPortAudio('FillBuffer', pahandle, smallBuffer , 1);
PsychPortAudio('Stop', pahandle, 1);
The sound myBeep2
never gets played. When I set the repetitions to 2, it correctly playes for the length of the buffer initiated with the initial fill times 2, and I can hear myBeep2
.
Scheduling is not an option because it doesn’t give me access to the timing(unless I’m missing something), and I need it (at least the ETA).