Problems running Pyo using Win 10 and external soundcard

Hi all,
I have some trouble getting sound files played with pyo using an external soundcard (scarlett focusrite 6i6) and win10 as operating system. Running the same code on MacOs works perfectly fine and the code runs as it is supposed to be. I already tried to change the preferences to solve the problem with no success. Setting the winhost to any of the listed APIS will cause the following error:

Error

Portaudio error in Pa_OpenStream: Invalid device
Pyo error: From portaudio, Invalid device
Portaudio error in Pa_CloseStream (pa_deinit): PortAudio not initialized
Portaudio error in Pa_Terminate (pa_deinit): PortAudio not initialized
Pyo error:
Server not booted.

If I do not assign any specific APIS the code will not cause any error and starts to run but will stop after 1 or 2 seconds without any sound played.

As I mentioned the same code is running on MacOS using the same hardware. I think it has something to do with the audio drivers but I dont know how to solve it. In the preferences of psychopy “coreaudio” and “portaudio” are listed as audio drivers under MacOS whereas “Audigy” and “Primary Sound” are listed under win10. I read that the asio4all driver could help but I dont know how to implement it for the use with psychopy. Does anyone has an idea how to solve this problem? I really appreciate your help.

Here are the APIS as well as input and output devices using win10:

Audio host APIS:

Host APIS:
index: 0, id: 2, name: MME, num devices: 6, default in: 1, default out: 4
index: 1, id: 1, name: Windows DirectSound, num devices: 6, default in: 6, default out: 9
index: 2, id: 13, name: Windows WASAPI, num devices: 4, default in: 15, default out: 12
index: 3, id: 11, name: Windows WDM-KS, num devices: 6, default in: 18, default out: 19

AUDIO devices:

0: IN, name: Microsoft Soundmapper - Input, host api index: 0, default sr: 44100 Hz, latency: 0.090000 s
1: IN, name: Focusrite USB (Focusrite USB Au, host api index: 0, default sr: 44100 Hz, latency: 0.090000 s
2: IN, name: Internal Microphone (Cirrus Log, host api index: 0, default sr: 44100 Hz, latency: 0.090000 s
3: OUT, name: Microsoft Soundmapper - Output, host api index: 0, default sr: 44100 Hz, latency: 0.090000 s
4: OUT, name: Focusrite USB (Focusrite USB Au, host api index: 0, default sr: 44100 Hz, latency: 0.090000 s
5: OUT, name: Lautsprecher (Cirrus Logic CS84, host api index: 0, default sr: 44100 Hz, latency: 0.090000 s
6: IN, name: Primärer Soundaufnahmetreiber, host api index: 1, default sr: 44100 Hz, latency: 0.120000 s
7: IN, name: Focusrite USB (Focusrite USB Audio), host api index: 1, default sr: 44100 Hz, latency: 0.120000 s
8: IN, name: Internal Microphone (Cirrus Logic CS8409 (AB 54)), host api index: 1, default sr: 44100 Hz, latency: 0.120000 s
9: OUT, name: Primärer Soundtreiber, host api index: 1, default sr: 44100 Hz, latency: 0.120000 s
10: OUT, name: Focusrite USB (Focusrite USB Audio), host api index: 1, default sr: 44100 Hz, latency: 0.120000 s
11: OUT, name: Lautsprecher (Cirrus Logic CS8409 (AB 54)), host api index: 1, default sr: 44100 Hz, latency: 0.120000 s
12: OUT, name: Focusrite USB (Focusrite USB Audio), host api index: 2, default sr: 48000 Hz, latency: 0.003000 s
13: OUT, name: Lautsprecher (Cirrus Logic CS8409 (AB 54)), host api index: 2, default sr: 48000 Hz, latency: 0.002500 s
14: IN, name: Internal Microphone (Cirrus Logic CS8409 (AB 54)), host api index: 2, default sr: 48000 Hz, latency: 0.002667 s
15: IN, name: Focusrite USB (Focusrite USB Audio), host api index: 2, default sr: 48000 Hz, latency: 0.003000 s
16: IN, name: Mikrofon (HD Audio-Mikrofon 2), host api index: 3, default sr: 44100 Hz, latency: 0.010000 s
17: OUT, name: Speakers (HD Audio-Lautsprecher), host api index: 3, default sr: 48000 Hz, latency: 0.010000 s
18: IN, name: Focusrite USB (fniusbwave_48), host api index: 3, default sr: 48000 Hz, latency: 0.010000 s
19: OUT, name: Analog Out (fniusbwave_48), host api index: 3, default sr: 48000 Hz, latency: 0.010000 s
20: OUT, name: Kopfhörer (), host api index: 3, default sr: 44100 Hz, latency: 0.010000 s
21: OUT, name: Kopfhörer (), host api index: 3, default sr: 44100 Hz, latency: 0.010000 s

Default input device: 1
Default output device: 4
Default Host: 0
Max Input Channels: 0
Max Output Channels: 0

Here is an example code leading to this problem:

Code

from pyo import *
import random
import time
from psychopy import prefs
prefs.general['audioLib'] = ['pyo']

# Configure server, channels, host, Api, duplex
s = Server(nchnls=2, duplex=0, sr = 44100) 
# Set server input and output devices in case default is not intended
#s.setInputDevice(7)
#s.setOutputDevice(10)

# Boot server
s.boot()


# Sound bank
folder = r'C:/Users/MartinWin/Desktop/Paradigma_md_laptop_windows/Sounds/'
sounds_mix = ["ABM1_trial1.wav", "ABF0_trial1.wav", "ABF2_trial1.wav", "ABM2_trial1.wav", "trigger.wav"]
sounds_male1 = ["ABM1_trial1.wav", "ABM1_trial7.wav", "ABM1_trial8.wav", "ABM1_trial16.wav", "trigger.wav"]
sounds_male2 = ["ABM2_trial1.wav", "ABM2_trial6.wav", "ABM2_trial8.wav", "ABM2_trial12.wav", "trigger.wav"]
sounds_female1 = ["ABF0_trial1.wav", "ABF0_trial6.wav", "ABF0_trial8.wav", "ABF0_trial13.wav", "trigger.wav"]
sounds_female2 = ["ABF2_trial1.wav", "ABF2_trial4.wav", "ABF2_trial5.wav", "ABF2_trial17.wav", "trigger.wav"]

# Start server
s.start()
# Male one 
sfR = SfPlayer(folder+sounds_male1[0], speed=1, mul=0.5).out(0)
sfL = SfPlayer(folder+sounds_male1[1], speed=1, mul=0.5).out(1)
#sbL = SfPlayer(folder+sounds_male1[2], speed=1, mul=0.5).out(2)
#sbR = SfPlayer(folder+sounds_male1[3], speed=1, mul=0.5).out(3)
#strig = SfPlayer(folder+sounds_male1[4], speed=1, mul=0.5).out(5)

# Male two
#sfR = SfPlayer(folder+sounds_male2[0], speed=1, mul=0.2).out(0)
#sfL = SfPlayer(folder+sounds_male2[1], speed=1, mul=0.2).out(1)
#sbL = SfPlayer(folder+sounds_male2[2], speed=1, mul=0.5).out(2)
#sbR = SfPlayer(folder+sounds_male2[3], speed=1, mul=0.5).out(3)
#strig = SfPlayer(folder+sounds_male2[4], speed=1, mul=0.5).out(5)

time.sleep(120)
s.stop()

Thank you very much in advance for your help!

Kind regards
Martin

Your code doesn’t actually include/need any PsychoPy code (other than to set the preferences but they aren’t then used).

I think this is a pure pyo issue, for @belangeo

Hi Jon,
thank you for your reply! You are absolutly right, the code above is just an abstract to point out my problem and does not contain any psychopy code at all. Nevertheless my project in general wilI use the psychopy standalone version and therefore contains a lot of psychopy code in combination with pyo to realize and run my project. Because the ‘portaudio’ and ‘asio4all’ drivers do not get listed in psychopy either I thought it is an general issue for both psychopy and pyo.

Hi,

If ASIO4ALL is installed, it should be visible in pa_list_host_apis() and pa_list_devices() outputs.

What happen when you explicitly initialize the Server with winhost=“directsound” ?

s = Server(sr=44100, nchnls=2, winhost="directsound").boot()

This should use the “Primary Sound Driver” device. If it doesn’t work with,

s.setInputDevice(7)
s.setOutputDevice(10)

I guess, it’s because directsound can’t handle correctly your soundcard, or something like this… Are you running Windows 10 on an Apple computer? Is there any ASIO drivers you can install for this soundcoard, that couldbe the solution?

Hi belangeo,

I installed ASIO4ALL and I am able to use in general but it seems like Pyo can´t find it since it is not getting listed using pa_list_host_apis() and pa_list_devices(). I also installed the drivers coming with the external soundcard and those should contain ASIO drivers as well. Indeed, I do run windows 10 with bootcamp support on my MacBook. Considering this do you think this is part of the problem? But if I remember right I tried it on a desktop pc a while ago and ran into the same problem but I´m not quite sure about this right now. I will try it out tomorrow and give you a short report back. So far thank you for your help!

Kind regards
Martin

Hi again,

first of all the code runs fine on win10 using same external sound card but different laptop (surface book). However I don’t get it running on win10 using bootcamp on my macbook neither by setting winhost = “directsound” nor by installing ASIO4ALL driver. So I’m sure now it is a drivers problem caused because I run win10 with bootcamp on a macbook. For now I can exchange my macbook with another device but it would have been nice to get a solution anyways. For this, do you have any further ideas or suggestions?

Thanks a lot!

Best regards

Martin

Hi,
we seem to be having a similar issue. Asio4all is installed, but pyo does not list it as one of the apis/devices in pa_list_devices() or pa_list_host_apis()

We have reinstalled asio4all several times, but it hasn’t helped…
Can you please advise?

Hi,

for me the only thing that worked was to switch the operating system to macOS. Thus everthing worked perfectly fine (maybe it is because of Apple´s ‘CoreAudio’ API). Since I still need to run it on Win10 I´m still interested in a solution too. Are you running your experiment on an ordinary Win10 system or do you run Win10 with Bootcamp? I´m asking because meanwhile I faced the problem for both, running it with and without Bootcamp support.
Best regards

Martin