Cannot set volume when using PTB

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2020.1.0
Standard Standalone? (y/n) If not then what?: Y

I’m using the PTB sound library to generate pure tones using the sound component. Unfortunately, it won’t let me change the volume of the tone. No matter what I set the volume to, it always plays the tone at the same volume. There is no difference if I keep the volume constant, set on each repeat or on each frame. Neither does it change if I include a code component with “sound_1.volume = 0.2”, for example.

Any ideas what the reason might be or am I just doing something completely wrong?

A further question (and an attempt to bump the post)
What I’m trying to do is change the volume from the default 1.0 to 0.5.
The following code does not work

import psychtoolbox as ptb
from psychopy import sound

mySound = sound.Sound('A')
mySound.volume = 0.5
now = ptb.GetSecs()
mySound.play(when=now+0.5)

While this code does:

import psychtoolbox as ptb
from psychopy import sound

mySound = sound.Sound('A', volume = 0.5)
now = ptb.GetSecs()
mySound.play(when=now+0.5)

Am I missing something (not unlikely) or should both chunks be equivalent?

Try mySound.setVolume(0.5) – seems the Sound class still has a somewhat “un-Pythonic” interface. Not sure if this is going to fix your issue, though :S

Edit: It seems _setSndFromArray should be called once the PTB sound volume was changed, if I’m not mistaken. This is obviously currently not happening, so this is probably why you don’t witness any change in volume when changing .volume. So this seems to be a bug that should be reported to the Issue tracker on GitHub.

2 Likes

Hey! Thanks for replying.

Yeah I sort of figured something must be bugged in regards to PTB. Thanks for figuring it out!

Can confirm this is still an issue, which is strange for such a core component of the builder. I cannot change the volume of my sound components (v2020.1.3. and using PTB).

Did you try .setVolume(.5) ?

Yes, I did back when I was trying this out. Nothing worked.
And from what Don is saying, it sounds like this is still the case.

I am having the same problems with PTB. With sounddevice it is working …

I faced the exact same problem (Oct 2020), and it reminded me of this: https://xkcd.com/979/

The problem seems to be that with the psychtoolbox backend, the volume of the track variable inside the object needs to be changed. There are many ways to solve this, but one way that I think conforms to the design philosophy of the SoundPTB class is to use the property attributes. I have submitted a bugfix here (please go to Files changed):

If anyone sees this in the meantime, the changes can be copied to the SoundPTB class in the file:

C:\Program Files\PsychoPy3\Lib\site-packages\psychopy\sound\backend_ptb.py

(The location will differ based on OS and installation path).

Best
Suddha

2 Likes

I’ve pulled that in and it will be fixed in the 2020.2.5 release :rocket: :champagne:

Wow! Thanks a lot Suddha and Jon :smiley:
This was still bugging me as late as a month ago.

Looking forward to the next release then :grin: