-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pianobar in Termux: /!\ Cannot open audio device #664
Comments
This is the readme for the It says it is using OpenSL ES: https://www.khronos.org/opensles/ |
I also followed this troubleshooting for pulseaudio, which worked for playing a .WAV file. The output of the
|
Can you recall which audio backends were enabled by libao’s ./configure?
It might be helpful to switch on libao’s debug output by adding
``debug=1`` to ``~/.libao``. You can force the pulseaudio driver by
adding ``default_driver=pulse`` to the same file.
|
I think the libao was configured for pulseaudio and something that might have been called "null output". My libao conf file has a different name. I will try to rename it and add the debug option |
With the debug option, it shows this error on startup:
Looks like the problem is with libao. |
@tcaddy I think we need to port it by using another audio playback library that suitable for Android just like the project "play-audio", rather than using libao and pulse audio. |
@tcaddy: I assume libpulse.so does not exist?
@edward-p: Writing a plugin for libao would be the better solution imo.
It’s really not that difficult and every other projects using libao
benefits.
Edit: Also I probably won’t accept pull requests adding support for other audio libraries, unless they are universal and replace libao on all supported platforms (i.e. no Android-specific solution).
|
It seems that libpulseaudio on termux isn't fully functional now, which can be tracked here Integrating ALSA and Pulseaudio into Termux #821 |
It's just
|
So this runs without error, but there is no sound: |
@tcaddy |
@tcaddy I found that pulseaudio in termux is also started with lots of preloaded libraries.
So we need a script just like this:
|
Correct, it works for me when I manually start pulseaudio, too. This is pretty cool. Thanks for your help! |
@tcaddy |
Actually, this could be pianobar’s fault. If you look at the player code
you will find it decodes chunks of data, then passes them to libao and
only after libao returned, decodes the next chunk. It should do this in
parallel.
|
@PromyLOPh |
@PromyLOPh I tried putting |
Can you share your code? Does the problem exist with other programs that
use pulseaudio on termux and don’t use libao (paplay for example)?
|
@PromyLOPh here is my changes. It looks not so good, I think. Because I'm not familiar with ffmpeg, I can't rewrite the whole player. I tried cmus on termux which doesn't use libao, it works perfectly. |
Well, it’s not too bad. Copying av frames/packets is obviously not the
most efficient thing to do, but that should’t be the problem. Also
the new AoPlayThread spins until queue_element!=NULL, which can consume
a lot of CPU time. Still, in theory it should fix the issue.
A different approach would be to offload playback to an external program
entirely. I already tried that, see
https://github.com/PromyLOPh/pianobar/tree/externalplay and – except for
a few unsolved issue – it works quite well. Unfortunately that branch is
very outdated and not easily portable to master.
|
@PromyLOPh That's an ingenious idea to use external program and pipe. I've learned a lot from you, thanks! Now I think temux users can, somehow, enjoy |
@PromyLOPh I tried to avoid copying av frames/packets, and adjust the time when |
Now I added force pause feature. Do force pause at start or queue is run out until the queue size get back to 256(may need adjustment) or the decoding is done(EOF element added at the end of the queue) . This may help with CPU time consumming issue. |
Rebased and sent pull request pull/665. |
Another issue may lead to random choppy sound. $ termux-audio-info
{
"PROPERTY_OUTPUT_SAMPLE_RATE": "48000",
"PROPERTY_OUTPUT_FRAMES_PER_BUFFER": "192",
"AUDIOTRACK_SAMPLE_RATE": 48000,
"AUDIOTRACK_BUFFER_SIZE_IN_FRAMES": 3844,
"AUDIOTRACK_SAMPLE_RATE_LOW_LATENCY": 48000,
"AUDIOTRACK_BUFFER_SIZE_IN_FRAMES_LOW_LATENCY": 384,
"BLUETOOTH_A2DP_IS_ON": false,
"WIREDHEADSET_IS_CONNECTED": true
} As you can see But in pulseaudio $ pulseaudio --dump-conf
...
enable-lfe-remixing = no
lfe-crossover-freq = 0
default-sample-format = s16le
default-sample-rate = 44100
alternate-sample-rate = 48000
default-sample-channels = 2
default-channel-map = front-left,front-right
default-fragments = 4
default-fragment-size-msec = 25
... The This cause the audio sample need to be converted to 48000 by the android system's audioserver before output, which waste a lot of CPU resources (I have monitored it by So it's important to modify the |
While setting pulse sink rate to the current optimum is mostly a good thing to do, it shouldn't cause any underrun even if it is on a non-optimal rate (at least not with my recent rewrite of the sink module). So the sound shouldn't be choppy unless your device is really low end that it literally can't afford Android's (redundant) resampling. You can report back with a pulse log (e.g. Note that 48kHz is not some universal optimum. The value depends on your (current) audio device and even your Android configuration. So there isn't really an issue in Termux/pulse on the respect. SLES in Android provides no means for getting the current optimal rate. AAudio does though, while it is only available in Oreo or later. Might port the SLES sink module to an (extra) AAudio one when I have time. |
I think this could be the problem of LineageOS 15.1 I'm using, which is in development and unofficial build for a sdm845 device. I get the random choppy sound mostly when I'm using my phone(e.g. screen rotated). p.s. pianobar talks to libao instead of talking to pulseaudio directly. |
Actually I think it's a libao issue. Its code for negotiating buffer/latency with pulse doesn't seem to be really proper, while at the same time it requests really little of that (base on a 20ms factor). Normally the configured latency of the sink would prevent that from happening, but with libao's code weird things seem to happen. There is a workaround, which is to set The reason that the underruns happen more often when a non-optimal rate is used is, Android has a higher buffer/latency requirement with such track. It also gets way higher if you were on Bluetooth audio, where 44 is hardly enough. Didn't test with pianobar, but could reproduce similar problem with cmus if it outputs to pulse via libao. No problem if it outputs to pulse via libpulse directly. |
Yeah, I think you're right. Setting However, libao still may need maintenance for Bluetooth audio, since 44 is hardly enough. |
Nah I was testing with cmus/libao/libpulse in an Arch proot with the help of this trick. Didn't bother to build them under Termux. This is what happen with
This is what happen with
|
Only two underruns get each song at the start with
No underrun get during the song is playing. I haven't tested with Bluetooth audio yet. |
@edward-p Okay I found and fixed problem. You can find the patches here: xiph/libao#8 |
@tomty89 That's great, thanks! I will apply the first when building libao for termux. |
Can either of you check whether the latest version of patch #665 fixes the underrun issue reported here? |
I've tested it with xiph/libao#8, works well on both of my Nexus 6P and Oneplus 6 in termux. I also tested it in WSL with a pulseaudio windows port sinking on local tcp, works fine too:) |
Works pretty good. Sometimes you have to force stop the APP if it doesn't recognize the device and keeps playing. Keeps running during phone calls. Great work guys! Big fan promy. Pianobar has definitely enriched my life. I read the man pages for pianobar but I do not see where I can store my creds for the mobile version. It is amazing what you guys have done I am still learning about packages on mobile. |
Termux has its own
Then |
Cannot open audio device
I was able to get pianobar to compile in the Termux app on a Chromebook. However, when I try to run the app I get console errors that say:
Pulseaudio is running. There is a Termux package called
play-audio
. It will play a sample MP3 file from the Termux command line.Your environment
termux-info
command:bash-4.4$ termux-info Updatable packages: All packages up to date System information: Linux localhost 3.18.0-18024-gc429fbc8b604 #1 SMP PREEMPT Tue Jun 19 04:33:31 PDT 2018 i686 Android Termux-packages arch: i686 Android version: 7.1.1 Device manufacturer: google Device model: Acer Chromebook R11 (CB5-132T / C738T)
pkg
app in TermuxSteps to reproduce
Getting pianobar to compile in the Termux environment was tricky and I didn't document it, so this is my best guess. LMK if I missed anything.
install packages
Use the
pkg install
command to install:install libao
There is no
libao
package available so I had to build it from source.curl -o libao-1.2.0.tar.gz https://ftp.osuosl.org/pub/xiph/releases/ao/libao-1.2.0.tar.gz
tar -vxzf libao-1.2.0.tar.gz
cd libao-1.2.0
./configure --prefix=$PREFIX
make
make install
edit Makefile
On line 20 of the Make file, change the else block to return this:
CC:=gcc -std=c99
make pianobar
(I had to use
make
b/cgmake
isn't listed as a package in Termux)make clean
make
start pulseaudio
pulseaudio
run pianobar
pianobar
Expected behaviour
It should play audio after getting station and song.
Actual behaviour
It gives the error message and skips to the next track.
The text was updated successfully, but these errors were encountered: