belangeo / pyo

Python DSP module
GNU Lesser General Public License v3.0
1.28k stars 130 forks source link

Hello world not playing any sounds on Ubuntu 20.04 #200

Closed cirosantilli closed 3 years ago

cirosantilli commented 3 years ago

pyo 1.0.3 installed with pip3 install, I try to run the hello world from http://ajaxsoundstudio.com/pyodoc/gettingstarted.html

from pyo import *
s = Server().boot()
s.start()
a = Sine(mul=0.01).out()

So first that was failing with:

WxPython is not found for the current python version.
Pyo will use a minimal GUI toolkit written with Tkinter (if available).
This toolkit has limited functionnalities and is no more
maintained or updated. If you want to use all of pyo's
GUI features, you should install WxPython, available here:
http://www.wxpython.org/

ALSA lib conf.c:3558:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so (/usr/lib/alsa-lib/libasound_module_conf_pulse.so: libasound_module_conf_pulse.so: cannot open shared object file: No such file or directory)
ALSA lib control.c:1375:(snd_ctl_open_noupdate) Invalid CTL hw:0
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_rate_samplerate.so ((null): /usr/lib/alsa-lib/libasound_module_rate_samplerate.so: cannot open shared object file: No such file or directory)
ALSA lib pcm_rate.c:1450:(snd_pcm_rate_open) Cannot find rate converter
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_rate_samplerate.so ((null): /usr/lib/alsa-lib/libasound_module_rate_samplerate.so: cannot open shared object file: No such file or directory)
ALSA lib pcm_rate.c:1450:(snd_pcm_rate_open) Cannot find rate converter
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_rate_speexrate.so ((null): /usr/lib/alsa-lib/libasound_module_rate_speexrate.so: cannot open shared object file: No such file or directory)
ALSA lib pcm_rate.c:1450:(snd_pcm_rate_open) Cannot find rate converter
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_rate_speexrate.so ((null): /usr/lib/alsa-lib/libasound_module_rate_speexrate.so: cannot open shared object file: No such file or directory)
ALSA lib pcm_rate.c:1450:(snd_pcm_rate_open) Cannot find rate converter
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_jack.so ((null): /usr/lib/alsa-lib/libasound_module_pcm_jack.so: cannot open shared object file: No such file or directory)
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_jack.so ((null): /usr/lib/alsa-lib/libasound_module_pcm_jack.so: cannot open shared object file: No such file or directory)
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_oss.so ((null): /usr/lib/alsa-lib/libasound_module_pcm_oss.so: cannot open shared object file: No such file or directory)
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_oss.so ((null): /usr/lib/alsa-lib/libasound_module_pcm_oss.so: cannot open shared object file: No such file or directory)
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_pulse.so ((null): /usr/lib/alsa-lib/libasound_module_pcm_pulse.so: cannot open shared object file: No such file or directory)
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_pulse.so ((null): /usr/lib/alsa-lib/libasound_module_pcm_pulse.so: cannot open shared object file: No such file or directory)
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_upmix.so ((null): /usr/lib/alsa-lib/libasound_module_pcm_upmix.so: cannot open shared object file: No such file or directory)
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_upmix.so ((null): /usr/lib/alsa-lib/libasound_module_pcm_upmix.so: cannot open shared object file: No such file or directory)
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_vdownmix.so ((null): /usr/lib/alsa-lib/libasound_module_pcm_vdownmix.so: cannot open shared object file: No such file or directory)
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_vdownmix.so ((null): /usr/lib/alsa-lib/libasound_module_pcm_vdownmix.so: cannot open shared object file: No such file or directory)
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_usb_stream.so ((null): /usr/lib/alsa-lib/libasound_module_pcm_usb_stream.so: cannot open shared object file: No such file or directory)
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_usb_stream.so ((null): /usr/lib/alsa-lib/libasound_module_pcm_usb_stream.so: cannot open shared object file: No such file or directory)
Pyo warning: Portaudio input device `HDA NVidia: HDMI 0 (hw:1,3)` has fewer channels (0) than requested (2).
Portaudio error in Pa_OpenStream: Invalid number of channels
Pyo error: From portaudio, Invalid number of channels
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.
ALSA lib conf.c:3558:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so (/usr/lib/alsa-lib/libasound_module_conf_pulse.so: libasound_module_conf_pulse.so: cannot open shared object file: No such file or directory)
ALSA lib seq.c:935:(snd_seq_open_noupdate) Unknown SEQ default
Pyo warning: Portmidi warning: no midi device found!
Portmidi closed.
Pyo warning: The Server must be booted before calling the start method!
Traceback (most recent call last):
  File "./main.py", line 5, in <module>
    a = Sine(mul=0.01).out()
  File "/home/ciro/.local/lib/python3.8/site-packages/pyo/lib/generators.py", line 60, in __init__
    PyoObject.__init__(self, mul, add)
  File "/home/ciro/.local/lib/python3.8/site-packages/pyo/lib/_core.py", line 1201, in __init__
    PyoObjectBase.__init__(self)
  File "/home/ciro/.local/lib/python3.8/site-packages/pyo/lib/_core.py", line 889, in __init__
    raise PyoServerStateException("The Server must be booted before "
pyo.lib._core.PyoServerStateException: The Server must be booted before creating any audio object.

One thing that solved that was:

sudo ln -s /usr/lib/x86_64-linux-gnu/alsa-lib /usr/lib/alsa-lib

but although the exception is gone, I still have no sound played, logs:

./main.py

WxPython is not found for the current python version.
Pyo will use a minimal GUI toolkit written with Tkinter (if available).
This toolkit has limited functionnalities and is no more
maintained or updated. If you want to use all of pyo's
GUI features, you should install WxPython, available here:
http://www.wxpython.org/

ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card

Any clues?

My goal is to compose some music for fun manually note by note from a script, hopefully with a few instruments/beats. Is this the right software, or do you know anything that would make that easier? :-)

DataTriny commented 3 years ago

Hello @cirosantilli , I recently switched to Ubuntu 20.04 and I am also experiencing troubles getting sound out of Pyo.

First, if you haven't already, install wxPython with pip or pip3 (I also had to install SDL2 on my system).

Next, you can use something like this to find a working output device:

import time
from pyo import *

devices = pa_count_devices()
for i in range(devices):
    s = Server()
    s.setOutputDevice(i)
    try:
        s.boot().start()
        print("Trying device #" + str(i))
        a = Sine(freq = 440, mul = 0.5)
        a.out()
        time.sleep(2)
        a.stop()
        s.stop()
    except:
        pass

Unfortunately, it appears that Pyo won't produce any sound as soon as another sound emitting program is running, which bothers me as I have to have speechd open.

I have not yet been able to output stereo either.

@belangeo Are you doing something special with ALSA, or is it broken on Ubuntu 20.04?

Apart from that, yes Pyo can be used to manually compose music pieces, that's what I was trying to do on Windows (where the setup was simpler).

belangeo commented 3 years ago

Not sure why you would need to symlink alsa-lib... Maybe Ubuntu moved it in 20.04 (on debian, it's still /usr/lib/x86_64-linux-gnu/alsa-lib. I'll have to install ubuntu to sort it out.

As for the multi-client, your best shot is clearly Jack!

cirosantilli commented 3 years ago

@DataTriny @belangeo thanks for your suggestions.

Just to clarify, I'm a complete audio newbie, and was just having a look at a bunch of possibilities to have some fun with algorithmic composition, and since Python's my favorite scripting language, I naturally Googled into this. As a result, I might be doing very stupid things :-) I have also tried several things, so maybe system state changed.

Anyways, at last, I was able to get some sound out of pyo on Ubuntu 20.04.

First, without the symlink sudo ln -s /usr/lib/x86_64-linux-gnu/alsa-lib /usr/lib/alsa-lib (note that this creates /usr/lib/alsa-lib, /usr/lib/x86_64-linux-gnu/alsa-lib is the default one present), the following worked:

sudo apt install python3-pyo

and:

from pyo import *
s = Server().boot()
s.start()
a = Sine(freq = 440, mul = 0.5)
a.out()
time.sleep(2)
a.stop()
s.stop()

Part of the problem is that the first example from http://ajaxsoundstudio.com/pyodoc/gettingstarted.html does not have the sleep and I was not sure if that was needed or not (thanks to DataTriny for pointing that out), and highly recommend patching it in that example, including one on the README.md maybe (and remove the >>> from the code blocks so that people can just copy paste those ;-)).

Now, sudo apt install python3-pyo installs pyo 1.0.0, and some dependencies without which things blow up, dep list is:

apt-cache depends python3-pyo
python3-pyo
  Depends: libc6
 |Depends: libjack-jackd2-0
  Depends: <libjack-0.125>
    libjack-jackd2-0
    libjack0
  Depends: liblo7
  Depends: libportaudio2
  Depends: libportmidi0
  Depends: libsndfile1
  Depends: python3
  Depends: python3
  Depends: <python3:any>
    python3:i386
    python3
  Recommends: python3-tk
  Recommends: jackd2

OK, with that still installed, I then also installed with:

pip install --user pyo==1.0.X

to see if there was a problem with newer versions, and the results are as follows:

cirosantilli commented 3 years ago

(@DataTriny BTW, when I tried your approach under certain configurations, it pyo segfaulted due to some C assert, so the loop stops before going through all devices. Gotta do a shell while loop instead I guess :-) But once I fixed the above things, the default device started working, so I don't have to worry about that for the moment)

DataTriny commented 3 years ago

Hello @cirosantilli ,

Glad you made some progress. Please note that:

DataTriny commented 3 years ago

I ended up installing jack and it works great! Here's what I did:

Now when you create a Pyo server object, initialize it like so:

s = Server(audio = "jack")
s.boot().start()

And you should be good to go!

Don't forget to uninstall python-pyo with apt.

Hope it helps.

Regards.

belangeo commented 3 years ago

Fixed in version 1.0.4.