Hanno Zulla
2016-04-01 12:57:13 UTC
Hello,
I would appreciate some help debugging / improving the PortAudio
interface of SuperCollider.
When using SuperCollider's PortAudio driver on Linux, I have two
problems:
- it works with PulseAudio's "default" device,
but there are occasional buffer underruns
- it does NOT work with pure ALSA's "default" device,
(very choppy audio, see [1])
- it works with a hardware device like "hw:0,0" in pure ALSA,
no buffer underruns on my system (but not sure)
I don't know if the "buffer underrun" issue and the "ALSA default device
choppy audio" are the same or not.
After digging into the code, I found that SuperCollider unnecessarily
allocates all channels reported back by PortAudio, but my patch [2]
for that wouldn't fix the issues above.
Some background to explain the problem, please bear with me for this
writeup.
SuperCollider [3] is a programming language for audio synthesis, or
in other words, a programmable electronic synthesizer.
SuperCollider is also the synthesizer inside of Sonic Pi [4], a
Live Coding synthesizer used in schools to teach coding. Sonic Pi is
using a ruby interpreter as a more kids-friendly programming language
and converts the commands to SuperCollider's language while hiding its
complexity from the users.
Sonic Pi is mainly developed for Raspberry Pi, but just like
SuperCollider, it is distributed for OS X, Windows and generic Linux
distributions.
I'm a casual contributor to the Sonic Pi team and our Linux users
experience recurring problems with SuperCollider's default JACK driver.
Well, it works fine, but most Linux desktop distributions ship with
PulseAudio and for an average user, it's fairly complicated to get JACK
and PulseAudio cooperate. (You can use one of them at a time, but
they'll stomp each other's feet once you try to run both.) So a simple
way to use SuperCollider without JACK would be a major advantage for
Sonic Pi users who don't want to fiddle with their audio backends.
The SuperCollider scsynth backend comes with three different
AUDIOAPI drivers:
- jack (default for Linux)
- portaudio (default for Windows)
- coreaudio (default for OSX).
The portaudio driver SC_PortAudio.cpp works fine on Windows. The
JACK driver SC_JACK.cpp works fine on Linux. Both drivers use more or
less the same code structure and flow.
It is possible to build SuperCollider on Linux using the PortAudio
driver:
git clone https://github.com/supercollider/supercollider.git
cd supercollider
# see README_LINUX.md, install build dependencies, then:
git submodule init
git submodule update
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DAUDIOAPI=portaudio ..
make
sudo make install
/usr/local/bin/sclang
After this, you can enter SuperCollider code:
s.options.device="default"
s.boot
x = {PinkNoise.ar(0.1)}.play
// should result in pink noise on one channel
x.free
// leave with ^D
Try this sclang code with and without PulseAudio [5] and you'll
see the problems described above.
Help would be appreciated. The goal is to get SuperCollider's
SC_PortAudio.cpp working with pure ALSA's "default" device and get
rid of the buffer underruns. I've spent some time looking at this
problem now and haven't found an obvious way to debug/fix this.
Kind regards,
Hanno
[1] https://github.com/supercollider/supercollider/issues/1944
[2] https://github.com/supercollider/supercollider/pull/1943
[3] http://supercollider.github.io
[4] http://sonic-pi.net
[5] http://askubuntu.com/a/394872/274072
I would appreciate some help debugging / improving the PortAudio
interface of SuperCollider.
When using SuperCollider's PortAudio driver on Linux, I have two
problems:
- it works with PulseAudio's "default" device,
but there are occasional buffer underruns
- it does NOT work with pure ALSA's "default" device,
(very choppy audio, see [1])
- it works with a hardware device like "hw:0,0" in pure ALSA,
no buffer underruns on my system (but not sure)
I don't know if the "buffer underrun" issue and the "ALSA default device
choppy audio" are the same or not.
After digging into the code, I found that SuperCollider unnecessarily
allocates all channels reported back by PortAudio, but my patch [2]
for that wouldn't fix the issues above.
Some background to explain the problem, please bear with me for this
writeup.
SuperCollider [3] is a programming language for audio synthesis, or
in other words, a programmable electronic synthesizer.
SuperCollider is also the synthesizer inside of Sonic Pi [4], a
Live Coding synthesizer used in schools to teach coding. Sonic Pi is
using a ruby interpreter as a more kids-friendly programming language
and converts the commands to SuperCollider's language while hiding its
complexity from the users.
Sonic Pi is mainly developed for Raspberry Pi, but just like
SuperCollider, it is distributed for OS X, Windows and generic Linux
distributions.
I'm a casual contributor to the Sonic Pi team and our Linux users
experience recurring problems with SuperCollider's default JACK driver.
Well, it works fine, but most Linux desktop distributions ship with
PulseAudio and for an average user, it's fairly complicated to get JACK
and PulseAudio cooperate. (You can use one of them at a time, but
they'll stomp each other's feet once you try to run both.) So a simple
way to use SuperCollider without JACK would be a major advantage for
Sonic Pi users who don't want to fiddle with their audio backends.
The SuperCollider scsynth backend comes with three different
AUDIOAPI drivers:
- jack (default for Linux)
- portaudio (default for Windows)
- coreaudio (default for OSX).
The portaudio driver SC_PortAudio.cpp works fine on Windows. The
JACK driver SC_JACK.cpp works fine on Linux. Both drivers use more or
less the same code structure and flow.
It is possible to build SuperCollider on Linux using the PortAudio
driver:
git clone https://github.com/supercollider/supercollider.git
cd supercollider
# see README_LINUX.md, install build dependencies, then:
git submodule init
git submodule update
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DAUDIOAPI=portaudio ..
make
sudo make install
/usr/local/bin/sclang
After this, you can enter SuperCollider code:
s.options.device="default"
s.boot
x = {PinkNoise.ar(0.1)}.play
// should result in pink noise on one channel
x.free
// leave with ^D
Try this sclang code with and without PulseAudio [5] and you'll
see the problems described above.
Help would be appreciated. The goal is to get SuperCollider's
SC_PortAudio.cpp working with pure ALSA's "default" device and get
rid of the buffer underruns. I've spent some time looking at this
problem now and haven't found an obvious way to debug/fix this.
Kind regards,
Hanno
[1] https://github.com/supercollider/supercollider/issues/1944
[2] https://github.com/supercollider/supercollider/pull/1943
[3] http://supercollider.github.io
[4] http://sonic-pi.net
[5] http://askubuntu.com/a/394872/274072