Skip to content

Commit

Permalink
op/aaudio: Implement AAudio output plugin
Browse files Browse the repository at this point in the history
Support native audio on Android 8.1 and later.

- Better battery life.
- Configurable latency.
- Configurable capture policy.
- Configurable sharing mode.
- Configurable spatialization.
- Full multi-channel audio support.
- Supports `pause_on_output_change`.
  • Loading branch information
pgaskin committed Aug 7, 2024
1 parent d0a685d commit 208fbaf
Show file tree
Hide file tree
Showing 4 changed files with 962 additions and 3 deletions.
33 changes: 31 additions & 2 deletions Doc/cmus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1130,13 +1130,13 @@ mpris (true)

Note: This flag has no effect if cmus was compiled without MPRIS support.

output_plugin [roar, pulse, alsa, arts, oss, sndio, sun, coreaudio]
output_plugin [roar, pulse, alsa, arts, oss, sndio, sun, coreaudio, aaudio]
Name of output plugin.

pause_on_output_change (false)
Pauses playback when the audio output changes.

Supported output plugins: pulse.
Supported output plugins: pulse, aaudio.

pl_env_vars
Comma separated list of environment variables to substitute when saving
Expand Down Expand Up @@ -1484,6 +1484,35 @@ dsp.jack.resampling_quality
2 (default) is high quality but more CPU intensive. This option is only
available if cmus was compiled with libsamplerate support.

dsp.aaudio.performance_mode (power_saving) [power_saving, none]
Set the requested performance mode. If "power_saving", battery life is
prioritized over low latency. If "none", battery life is balanced with
low latency.

This option requires restarting cmus.

dsp.aaudio.allowed_capture (all) [all, system, none]
Specify whether the audio may or may not be captured by other apps or
the system.

This option is only supported on Android 10+ (API 29) and requires
restarting cmus.

dsp.aaudio.sharing_mode (shared) [shared, exclusive]
Request a mode for sharing the device. This is done on a best-effort
basis, and the requested sharing mode may not be available.

This option requires restarting cmus.

dsp.aaudio.disable_spatialization (false)
If true, disables Android's built-in audio spatializer even if it is
enabled for the current audio output. Note that spatialization only
applies to audio with at least 4 channels. See
https://developer.android.com/media/grow/spatial-audio for more details.

This option is only supported on Android 12L+ (API 32) and requires
restarting cmus.

input.cdio.cddb_url
CDDB URL (default: freedb.freedb.org:8880). Uses HTTP if prefixed with
"http://" (e.g.: http://freedb.musicbrainz.org:80/~cddb/cddb.cgi). Set
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ ao-objs := op/ao.lo
coreaudio-objs := op/coreaudio.lo
waveout-objs := op/waveout.lo
roar-objs := op/roar.lo
aaudio-objs := op/aaudio.lo

op-$(CONFIG_PULSE) += op/pulse.so
op-$(CONFIG_ALSA) += op/alsa.so
Expand All @@ -192,6 +193,7 @@ op-$(CONFIG_COREAUDIO) += op/coreaudio.so
op-$(CONFIG_AO) += op/ao.so
op-$(CONFIG_WAVEOUT) += op/waveout.so
op-$(CONFIG_ROAR) += op/roar.so
op-$(CONFIG_AAUDIO) += op/aaudio.so

$(pulse-objs): CFLAGS += $(PULSE_CFLAGS)
$(alsa-objs): CFLAGS += $(ALSA_CFLAGS)
Expand All @@ -204,6 +206,7 @@ $(ao-objs): CFLAGS += $(AO_CFLAGS)
$(coreaudio-objs): CFLAGS += $(COREAUDIO_CFLAGS)
$(waveout-objs): CFLAGS += $(WAVEOUT_CFLAGS)
$(roar-objs): CFLAGS += $(ROAR_CFLAGS)
$(aaudio-objs): CFLAGS += $(AAUDIO_CFLAGS)

op/pulse.so: $(pulse-objs) $(libcmus-y)
$(call cmd,ld_dl,$(PULSE_LIBS))
Expand Down Expand Up @@ -237,6 +240,9 @@ op/waveout.so: $(waveout-objs) $(libcmus-y)

op/roar.so: $(roar-objs) $(libcmus-y)
$(call cmd,ld_dl,$(ROAR_LIBS))

op/aaudio.so: $(aaudio-objs) $(libcmus-y)
$(call cmd,ld_dl,$(AAUDIO_LIBS))
# }}}

# man {{{
Expand Down
36 changes: 35 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,38 @@ check_ffmpeg()
return 1
}

aaudio_code="
#include <aaudio/AAudio.h>
int main() {
// ensure basic aaudio support
if (__builtin_available(android 26, *)) {
AAudioStreamBuilder *bld;
AAudio_createStreamBuilder(&bld);
// ensure we have at least api 32 headers
if (__builtin_available(android 32, *)) {
AAudioStreamBuilder_setChannelMask(bld, AAUDIO_CHANNEL_9POINT1POINT6);
}
}
return 0;
}
"

check_aaudio()
{
check_header aaudio/AAudio.h || return $?
check_library AAUDIO "-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__ -Werror=unguarded-availability" "-Wl,--no-as-needed -laaudio" || return $?

msg_checking "for working aaudio api 32 linkage"
if try_compile_link "$aaudio_code" $AAUDIO_CFLAGS $AAUDIO_LIBS
then
msg_result yes
return 0
fi
msg_result no
return 1
}

check_string_function()
{
msg_checking "for function $1"
Expand Down Expand Up @@ -543,6 +575,7 @@ Options:
Optional Features: y/n
CONFIG_AAC AAC (.aac, audio/aac, audio/aacp) [auto]
CONFIG_AAUDIO Android 8.0+ native audio output [auto]
CONFIG_ALSA ALSA [auto]
CONFIG_AO Libao cross-platform audio library [auto]
CONFIG_ARTS ARTS [auto]
Expand Down Expand Up @@ -646,6 +679,7 @@ check check_sndio CONFIG_SNDIO
check check_sun CONFIG_SUN
check check_waveout CONFIG_WAVEOUT
check check_roar CONFIG_ROAR
check check_aaudio CONFIG_AAUDIO

# discid is only needed if at least one cdda plugin is active
test -z "$CONFIG_DISCID" && CONFIG_DISCID=a
Expand Down Expand Up @@ -687,6 +721,6 @@ makefile_vars \
CONFIG_MAD CONFIG_MIKMOD CONFIG_MODPLUG CONFIG_MP4 CONFIG_MPC \
CONFIG_MPRIS CONFIG_OPUS CONFIG_OSS CONFIG_PULSE CONFIG_ROAR \
CONFIG_SAMPLERATE CONFIG_SNDIO CONFIG_SUN CONFIG_VORBIS CONFIG_VTX \
CONFIG_WAV CONFIG_WAVEOUT CONFIG_WAVPACK CONFIG_BASS
CONFIG_WAV CONFIG_WAVEOUT CONFIG_WAVPACK CONFIG_BASS CONFIG_AAUDIO

generate_config_mk
Loading

0 comments on commit 208fbaf

Please sign in to comment.