I have problem to play multichannel surround sound.
I use 3 speakers with soundblaster x4 driver.
In python cmd, i can play multichannel sound file using sounddevice module
ex) import soundfile as sf
import sounddevice as sd
print(sd.query_devices())
data,fs =sf.read(path+‘\left_footstep 2s.wav’,dtype=‘float32’)
sd.play(data,fs,device=3 )
status=sd.wait()
But, An error occurs when playing a sound file with code in coder or builder (channel error)
would you mind sharing the full code you ran together with the exact error message you received? Otherwise, there is a lot of guessing involved. As you stated, sounddevice can play multichannel sound. As stated in the docs, each column of the input array is treated as a channel and the assignment of data to output channels can be controlled with the mapping argument of sounddevice.play(). You typically get a channel-related error message if the number of data channels does not match the output channels of the device.
Just to update - I got 8 channels working using Psychtoolbox with matlab and a Soundblaster X4 (usb connected) surround sound device. I build the wave signals into a data buffer in Matlab before ‘playing’ them.
NB I disabled surround sound in windows sound settings for this to work.
I’ve not tried it using audio files but I imagine that you could sue something like Audacity to create a multichannel sound file and use that.
the Python/PsychoPy solution is quite similar. Basically, the package sounddevice takes arrays with multiple columns as individual channels that can be directed to unique outputs. I attached a snipped below. In the example, mono sounds are imported first in .wav format:
import soundfile as sf
import sounddevice as sd
import numpy as np
from psychopy import core
# Set path to sound files:
file1 = "/path/to/sound/file/sound1.wav"
file2 = "/path/to/sound/file/sound2.wav"
# Read sound files:
data1, sr1 = sf.read(file1, dtype='float32')
data2, sr2 = sf.read(file2, dtype='float32')
# Combine data into array:
data12 = np.stack((data1, data2), axis=1)
# Play sounds (mapping determines the routing to outputs of the specified device):
sd.play(data=data12, samplerate=44100, device=2, mapping=[1, 2])
# Wait until sound is played:
core.wait(1, 1)