BeepDemo Repetition Parameter Not Working?

OS: Windows 10 (64 Bit)
Matlab R2019a
PTB Version 3.0.16

I’ve been playing around with PTB, more specifically the audio end of things, for the last few ours. I came across this demo by Peter Scarfe which allows the user to play a beep repeatedly:

https://peterscarfe.com/beepdemo.html

However when I try running the demo, the beep plays twice and then stops (the default is set to 1 sec beep, 1 sec off, 1 sec beep). When I try changing the repetition to anything more than 1, it increases the duration of the beep, not the number of times the beep is played!

Edit: I should include that when I set the number of repetitions to 0 it does not play infinitely as it should, instead no audio plays (I simply hear a quiet click come from my speakers)

Then you probably did something wrong when you made the change. Check carefully again first, and if you can’t figure it out, please show here what you did. Your current message has no question, nor anything for us to work with

All I did was take the code from the website and run it in Matlab.

When I run the script, the number of repetitions (repetitions=1;) in line 14 is set to “1” and the beep plays twice (1 sec beep on, 1 sec beep off, 1 sec beep on). Here’s what happens or other values of

repetitions=0;
This should make the 1 sec beep on and 1 sec beep off repeat infinitely but I don’t hear any audio, just a single click

repetitions=2;
This should make the 1 sec beep on and 1 sec beep off play twice. Instead I hear a 2 sec beep on followed by 1 sec beep off followed by 2 sec beep on.

repetitions=3;
This should make the 1 sec beep on and 1 sec beep off repeat three times. Instead I hear a 3 sec beep on followed by 1 sec beep off followed by 3 sec beep on.

So on and so forth. With repetitions=10; I hear a 10 sec beep on followed by 1 sec beep off followed by 10 sec beep on.

Instead of changing the number of repetitions the sound makes (as indicated when you type “PsychPortAudio” into the command window and hit enter), why is changing the number of repetitions in line 14 changing the length of the beep on periods?

The demo does exactly what it should, but the repetitions parameter has a different meaning than you think. repetitions in the PsychPortAudio(‘Start’, …) function defines how often the specified sound will repeat. Given that the specified sound vector defines a beep sound of 1 sec duration, setting repetitions to 4 will repeat that 1 second sound 4 times, so you get a 4 second sound. And then after 4 repetitions the playback stops, and the PsychPortAudio(‘Stop’) function, which was set up to pause and wait for end of playback, will be done waiting and the script continues to the next lines, where a ‘Start’ command asks to start the sound playback again, starting exactly 1 second after sound offset from the previous sound playback.

So setting repetitions to anything other than 1 doesn’t make sense in the context of that demo, it is just another way to control the duration of the two beep sounds. If you set repetitions=0, which means infinite repetitions, the help text actually says to repeat infinitely until the next ‘Stop’ command or a specified stop time. As the ‘Stop’ command follows immediately after the ‘Start’ command, it would stop the sound almost instantaneously after it started.

If you wanted to repeat the sequence, you’d need to put a proper for-loop around the right bits of the code. Or use a different approach. But the demo “as is” is fine and working as intended.