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