Audio presentation interrupts moving stimulus/ Error preloading audio files

OS (e.g. Win10): Win 10
PsychoPy version (e.g. 1.84.x): v2020.2.10
Standard Standalone? yes

What are you trying to achieve?:
I’m trying to play multiple audio files during the presentation of a smoothly moving dot. (Participants should follow the moving dot with their eyes while they perform the auditorily presented operations in mind).

What did you try to make it work?:
Changing the audio file during the presentation leads to lags in the moving circle, which I couldn’t fix with adding StaticPeriod for loading, as the period needed to preload the audio files was still too large to allow a smooth moving circle.

All in one Code in Each Frame which leads to lags:

# operations
tt = core.getTime()
if tt >= next_op_time:
    playsound = 1
    if idx == setsize:
        continueRoutine = False
        break
if not continueRoutine:
    break

if playsound == 1:
    soundd = operation_audio[int(idx)]
    sound_2.setSound(soundd)
    sound_2.play()
    next_op_time = tt + isis_operations[int(idx)]
    start_times_operations.append(tt)
    circle_pos_at_opartion_start.append(coords)
    idx = idx +1
    playsound = 0

# circle
# try to correct for lags in time
difftime = (core.getTime() - tt)
changee = pace*(1+difftime)
angle += changee
coords = math.cos(angle)*radius, math.sin(angle)*radius
circle1.pos = coords

win.flip()

So, I tried to preload the audio files per trial before the trial like it is suggested for images.

Code Begin Experiment:

# create sound objects

sound_1 = sound.Sound("A")
sound_2 = sound.Sound("A")
sound_3 = sound.Sound("A")
sound_4 = sound.Sound("A")
sound_5 = sound.Sound("A")
sound_6 = sound.Sound("A")
sound_7 = sound.Sound("A")
sound_8 = sound.Sound("A")
sound_9 = sound.Sound("A")
sound_10 = sound.Sound("A")
sound_11 = sound.Sound("A")

sound_list = [sound_1, sound_2, sound_3, sound_4, sound_5, sound_6, sound_7, sound_8, sound_9, sound_10, sound_11]

Code Begin Routine:

# preload audio files
for i in range(0,setsize):
    sound_list[i].setSound(operation_audio[i])

Code Each Frame:

# operations
tt = core.getTime()
if tt >= next_op_time:
    playsound = 1
    if idx == setsize:
        continueRoutine = False
        break
if not continueRoutine:
    break

if playsound == 1:
    sound_list[idx].play
    next_op_time = tt + isis_operations[int(idx)]
    start_times_operations.append(tt)
    circle_pos_at_opartion_start.append(coords)
    idx = idx +1
    playsound = 0

# circle
angle += pace
coords = math.cos(angle)*radius, math.sin(angle)*radius
circle1.pos = coords

win.flip()

What specifically went wrong when you tried that?:

However, then I get the Error:

PTB-ERROR: Audio device 12 has 1 output channels, but provided matrix has non-matching number of 2 columns.
Error in function FillBuffer:     Usage error
Number of columns of audio data matrix doesn't match number of output channels of selected audio device.

PsychPortAudio:FillBuffer: Usage:

[underflow, nextSampleStartIndex, nextSampleETASecs] = PsychPortAudio('FillBuffer', pahandle, bufferdata [, streamingrefill=0][, startIndex=Append]);
Traceback (most recent call last):
  File "Y:\CreaLab.Project\EyeMag2\Paradigmen\visuospatial_task_audio\visuospatial_task0402_smoothpursuit3_lastrun.py", line 345, in <module>
    name='sound_2')
  File "C:\Users\walchers\AppData\Local\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 334, in __init__
    hamming=self.hamming)
  File "C:\Users\walchers\AppData\Local\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 428, in setSound
    _SoundBase.setSound(self, value, secs, octave, hamming, log)
  File "C:\Users\walchers\AppData\Local\PsychoPy3\lib\site-packages\psychopy\sound\_base.py", line 179, in setSound
    hamming=hamming)
  File "C:\Users\walchers\AppData\Local\PsychoPy3\lib\site-packages\psychopy\sound\_base.py", line 213, in _setSndFromNote
    self._setSndFromFreq(thisFreq, secs, hamming=hamming)
  File "C:\Users\walchers\AppData\Local\PsychoPy3\lib\site-packages\psychopy\sound\_base.py", line 229, in _setSndFromFreq
    self._setSndFromArray(outArr)
  File "C:\Users\walchers\AppData\Local\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 501, in _setSndFromArray
    volume=self.volume)
  File "C:\Users\walchers\AppData\Local\PsychoPy3\lib\site-packages\psychtoolbox\audio.py", line 300, in __init__
    self.fill_buffer(data)
  File "C:\Users\walchers\AppData\Local\PsychoPy3\lib\site-packages\psychtoolbox\audio.py", line 242, in fill_buffer
    self.buffer = Buffer(stream=self, data=data)
  File "C:\Users\walchers\AppData\Local\PsychoPy3\lib\site-packages\psychtoolbox\audio.py", line 260, in __init__
    data)
Exception: Number of columns of audio data matrix doesn't match number of output channels of selected audio device.

I tried a similar approach as for images presented here: https://groups.google.com/g/psychopy-users/c/fWSl36UFYUA
However I also get an Error referring to buffering of audio files

Hello SoAnWa

most of it is beyond my abilities, but shouldn’t it read

sound_list[idx].play()

instead of

Best wishes Jens

Hey,
I spotted this typo too. But it didn’t change anything.

I took a closer look at the script to find at which point the error appears before psychopy stops the script.
The error occurs as soon as a second sound object is created (e.g. sound_2), no matter which one.

1 Like

hi, did you ever solve this? I’m running into the same problem.