aaudio

package
v1.17.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package aaudio is the AAudio backend of the audio service on Android (SPEC §28.3, step 31.6): playback and capture of float32 frames through libaaudio.so (Android 8, API 26), called through purego, with a data callback that is made once, the low-latency performance mode, a stream that is made again when the device it was on is disconnected, and a device that pauses while the app is hidden. libaaudio is loaded when the app first lists or opens a device. The design follows the AAudio driver of SDL 3 (src/audio/aaudio/SDL_aaudio.c; zlib license, third_party/sdl/LICENSE), translated to Go and changed: the stream is in float32 with the sample rate and channels the app asks for (AAudio converts), the error callback hands the work of a disconnect to a goroutine (a stream cannot be closed from its own callbacks), and `RECORD_AUDIO` is asked through the Java side of the embedding.

The package has only the tag of the Linux kernel (Android has it too), so that its tests run on the desktop with a scripted library, as the tests of the PulseAudio backend do; it is used on Android only.

Flutter: no counterpart

Index

Constants

View Source
const LibraryEnv = "GLUTTER_AAUDIO_LIBRARY"

LibraryEnv names the environment variable that overrides the path of libaaudio (SPEC §8.1).

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Permissions asks for the permission to record; nil means that none is needed (tests, and a system that never asks).
	Permissions Permissions
	// Log gets what cannot be returned (nil discards it).
	Log *slog.Logger
}

Options are what New is given.

type Permissions

type Permissions interface {
	// RecordAudio makes sure that the app may record: it asks the user when the permission is not granted yet and waits for the answer
	// until ctx ends. It reports false when the user said no.
	RecordAudio(ctx context.Context) (granted bool, err error)
}

Permissions is what the backend needs of the Java side to record: the permission RECORD_AUDIO, which Android asks the user for while the app runs.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the AAudio backend: it implements platform.Audio.

Flutter: no counterpart

func New

func New(opts Options) *Service

New makes a Service. libaaudio is not loaded yet.

Flutter: no counterpart

func (*Service) Devices

func (s *Service) Devices(kind platform.AudioKind) ([]platform.AudioDeviceInfo, error)

Devices lists the default device of the kind: AAudio has no list of devices (the identifiers that the Java side's AudioManager gives are numbers, which Open takes as the ID of a device). It fails with AudioUnavailable when libaaudio is not there.

Flutter: no counterpart

func (*Service) Open

Open opens a device and starts its stream. It fails with AudioUnavailable when libaaudio is not there, AudioCapturePermissionDenied when the user refuses the microphone, AudioFormatUnsupported when the device takes no such format, and AudioDeviceOpenFailed for the rest.

Flutter: no counterpart

func (*Service) SetBackground

func (s *Service) SetBackground(hidden bool)

SetBackground says that the app is hidden (or shown again): the devices that were opened with PauseInBackground pause, and go on when the app is shown, unless their owner paused them.

Flutter: no counterpart

func (*Service) SetChangeHandler

func (s *Service) SetChangeHandler(fn func())

SetChangeHandler is for the platforms that tell when the list of devices changes; AAudio's list is the default devices, and a stream that is on one that went away is made again on the new default one, so nothing is ever told.

Flutter: no counterpart

type Stats

type Stats interface {
	// Timestamp is the time (CLOCK_MONOTONIC, nanoseconds) at which the stream's frame number was; ok is false before the stream has one.
	Timestamp() (frame, nanos int64, ok bool)
	// XRuns is how many times the stream ran out of frames.
	XRuns() int
	// BufferFrames is the stream's buffer and the burst of the hardware, in frames.
	BufferFrames() (buffer, burst int)
}

Stats is what a device of this backend shows besides platform.AudioDevice: the timestamp of the stream, how often it ran dry and the size of its buffer. A test finds it with a type assertion on the device that Open returned.

Flutter: no counterpart

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL