I am trying to play two sounds at the same time. A pink noise that onsets about 1.5 seconds before a word. PsychoPy is handling the simultaneous playing exactly as expected. However, the experimental manipulation is that while the pink noise always plays at full volume (1.0), the word should play at a lower volume (e.g. 0.5).
This is where the behavior gets weird. In the minimal working example below, I play the pink noise at full volume and the word at 0.5 volume for three trials. While .getVolume() returns the appropriate stimulus volume - that is, whatever I set in .setVolume() - the true volume that gets played is not consistent, as seen in this waveform recording of the 3 trials.
At the onset of the word (~1.5 seconds after the noise), the volume samples down for both the noise stimulus AND the word in the first trial. In the second trial, the initial volume of the pink noise is much lower. In the third trial, the behavior is different still (seems like the volume of the word is higher?)
I know that you can’t change the volume of a given stimulus once it’s started, but It seems like for simultenous sounds, volume is handled kind of like .draw() order for visual stims? I’m guessing it just plays both sounds at the same time out of the same channels, and then adjusts the volume of the channels whenever it gets any volume adjustment? (thus all sounds are effected?)
I’m hoping someone can confirm there is no way for psychopy to handle this before I try to find a satisfactory audio package to pull that can do precise loudness/gain manipulations and mixing (e.g. sox, pydub, pyaudio).
Thanks in advance!
Katie
# psychopy version 1.84.1
# OSX 10.11.5 (El Capitan)
from psychopy import prefs, visual, sound, core
# set the preferred audio drivers / libs
prefs.general['audioLib'] = ['pyo']
prefs.general['audioDriver']= ['portaudio']
# initialize the window and sounds
exp_window = visual.Window(screen = 0, units = 'pix', color = 'gray',fullscr = False)
pink_noise = sound.Sound(value = 'stims/pinknoise.wav', sampleRate = 48000)
word = sound.Sound(value = 'stims/audio_easy/bead.wav', sampleRate = 48000)
for trial in range(3):
# set the volume of the pink noise to full volume
pink_noise.setVolume(1.0)
# flip the window
exp_window.flip()
# start a static period to play just the pink noise
thisISI = core.StaticPeriod(screenHz = 60.0, name = "ISI")
thisISI.start(1.0)
pink_noise.play()
# while you are doing that, set the volume of the word
word.setVolume(0.5)
# end the static period and start the word
ISI_accurate = thisISI.complete()
exp_window.flip()
word.play()
# when you start playing the word, return the volume
# of both stimuli and wait 2.5 seconds
print pink_noise.getVolume(), word.getVolume()
core.wait(2.5)