audio

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package audio provides Go bindings for Android AAudio.

Index

Constants

View Source
const (
	AAUDIO_SYSTEM_USAGE_OFFSET = 1000
	AAUDIO_UNSPECIFIED         = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AAudioStream_errorCallback

type AAudioStream_errorCallback = capi.AAudioStream_errorCallback

type AUDIO

type AUDIO int32
const (
	AAUDIO_USAGE_MEDIA                          AUDIO = 1
	AAUDIO_USAGE_VOICE_COMMUNICATION            AUDIO = 2
	AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING AUDIO = 3
	AAUDIO_USAGE_ALARM                          AUDIO = 4
	AAUDIO_USAGE_NOTIFICATION                   AUDIO = 5
	AAUDIO_USAGE_NOTIFICATION_RINGTONE          AUDIO = 6
	AAUDIO_USAGE_NOTIFICATION_EVENT             AUDIO = 10
	AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY       AUDIO = 11
	AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE AUDIO = 12
	AAUDIO_USAGE_ASSISTANCE_SONIFICATION        AUDIO = 13
	AAUDIO_USAGE_GAME                           AUDIO = 14
	AAUDIO_USAGE_ASSISTANT                      AUDIO = 16
	AAUDIO_SYSTEM_USAGE_EMERGENCY               AUDIO = 1000
	AAUDIO_SYSTEM_USAGE_SAFETY                  AUDIO = 1001
	AAUDIO_SYSTEM_USAGE_VEHICLE_STATUS          AUDIO = 1002
	AAUDIO_SYSTEM_USAGE_ANNOUNCEMENT            AUDIO = 1003
)

type AUDIO_ALLOW_CAPTURE_BY

type AUDIO_ALLOW_CAPTURE_BY int32
const (
	AAUDIO_ALLOW_CAPTURE_BY_ALL    AUDIO_ALLOW_CAPTURE_BY = 1
	AAUDIO_ALLOW_CAPTURE_BY_SYSTEM AUDIO_ALLOW_CAPTURE_BY = 2
	AAUDIO_ALLOW_CAPTURE_BY_NONE   AUDIO_ALLOW_CAPTURE_BY = 3
)

type AUDIO_CALLBACK_RESULT

type AUDIO_CALLBACK_RESULT int32
const (
	AAUDIO_CALLBACK_RESULT_CONTINUE AUDIO_CALLBACK_RESULT = 0
	AAUDIO_CALLBACK_RESULT_STOP     AUDIO_CALLBACK_RESULT = 1
)

type AUDIO_CHANNEL

type AUDIO_CHANNEL int32
const (
	AAUDIO_CHANNEL_INVALID               AUDIO_CHANNEL = -1
	AAUDIO_CHANNEL_FRONT_LEFT            AUDIO_CHANNEL = 1
	AAUDIO_CHANNEL_FRONT_RIGHT           AUDIO_CHANNEL = 2
	AAUDIO_CHANNEL_FRONT_CENTER          AUDIO_CHANNEL = 4
	AAUDIO_CHANNEL_LOW_FREQUENCY         AUDIO_CHANNEL = 8
	AAUDIO_CHANNEL_BACK_LEFT             AUDIO_CHANNEL = 16
	AAUDIO_CHANNEL_BACK_RIGHT            AUDIO_CHANNEL = 32
	AAUDIO_CHANNEL_FRONT_LEFT_OF_CENTER  AUDIO_CHANNEL = 64
	AAUDIO_CHANNEL_FRONT_RIGHT_OF_CENTER AUDIO_CHANNEL = 128
	AAUDIO_CHANNEL_BACK_CENTER           AUDIO_CHANNEL = 256
	AAUDIO_CHANNEL_SIDE_LEFT             AUDIO_CHANNEL = 512
	AAUDIO_CHANNEL_SIDE_RIGHT            AUDIO_CHANNEL = 1024
	AAUDIO_CHANNEL_TOP_CENTER            AUDIO_CHANNEL = 2048
	AAUDIO_CHANNEL_TOP_FRONT_LEFT        AUDIO_CHANNEL = 4096
	AAUDIO_CHANNEL_TOP_FRONT_CENTER      AUDIO_CHANNEL = 8192
	AAUDIO_CHANNEL_TOP_FRONT_RIGHT       AUDIO_CHANNEL = 16384
	AAUDIO_CHANNEL_TOP_BACK_LEFT         AUDIO_CHANNEL = 32768
	AAUDIO_CHANNEL_TOP_BACK_CENTER       AUDIO_CHANNEL = 65536
	AAUDIO_CHANNEL_TOP_BACK_RIGHT        AUDIO_CHANNEL = 131072
	AAUDIO_CHANNEL_TOP_SIDE_LEFT         AUDIO_CHANNEL = 262144
	AAUDIO_CHANNEL_TOP_SIDE_RIGHT        AUDIO_CHANNEL = 524288
	AAUDIO_CHANNEL_BOTTOM_FRONT_LEFT     AUDIO_CHANNEL = 1048576
	AAUDIO_CHANNEL_BOTTOM_FRONT_CENTER   AUDIO_CHANNEL = 2097152
	AAUDIO_CHANNEL_BOTTOM_FRONT_RIGHT    AUDIO_CHANNEL = 4194304
	AAUDIO_CHANNEL_LOW_FREQUENCY_2       AUDIO_CHANNEL = 8388608
	AAUDIO_CHANNEL_FRONT_WIDE_LEFT       AUDIO_CHANNEL = 16777216
	AAUDIO_CHANNEL_FRONT_WIDE_RIGHT      AUDIO_CHANNEL = 33554432
	AAUDIO_CHANNEL_MONO                  AUDIO_CHANNEL = 1
	AAUDIO_CHANNEL_STEREO                AUDIO_CHANNEL = 3
	AAUDIO_CHANNEL_2POINT1               AUDIO_CHANNEL = 11
	AAUDIO_CHANNEL_TRI                   AUDIO_CHANNEL = 7
	AAUDIO_CHANNEL_TRI_BACK              AUDIO_CHANNEL = 259
	AAUDIO_CHANNEL_3POINT1               AUDIO_CHANNEL = 15
	AAUDIO_CHANNEL_2POINT0POINT2         AUDIO_CHANNEL = 786435
	AAUDIO_CHANNEL_2POINT1POINT2         AUDIO_CHANNEL = 786443
	AAUDIO_CHANNEL_3POINT0POINT2         AUDIO_CHANNEL = 786439
	AAUDIO_CHANNEL_3POINT1POINT2         AUDIO_CHANNEL = 786447
	AAUDIO_CHANNEL_QUAD                  AUDIO_CHANNEL = 51
	AAUDIO_CHANNEL_QUAD_SIDE             AUDIO_CHANNEL = 1539
	AAUDIO_CHANNEL_SURROUND              AUDIO_CHANNEL = 263
	AAUDIO_CHANNEL_PENTA                 AUDIO_CHANNEL = 55
	AAUDIO_CHANNEL_5POINT1               AUDIO_CHANNEL = 63
	AAUDIO_CHANNEL_5POINT1_SIDE          AUDIO_CHANNEL = 1551
	AAUDIO_CHANNEL_6POINT1               AUDIO_CHANNEL = 319
	AAUDIO_CHANNEL_7POINT1               AUDIO_CHANNEL = 1599
	AAUDIO_CHANNEL_5POINT1POINT2         AUDIO_CHANNEL = 786495
	AAUDIO_CHANNEL_5POINT1POINT4         AUDIO_CHANNEL = 184383
	AAUDIO_CHANNEL_7POINT1POINT2         AUDIO_CHANNEL = 788031
	AAUDIO_CHANNEL_7POINT1POINT4         AUDIO_CHANNEL = 185919
	AAUDIO_CHANNEL_9POINT1POINT4         AUDIO_CHANNEL = 50517567
	AAUDIO_CHANNEL_9POINT1POINT6         AUDIO_CHANNEL = 51303999
	AAUDIO_CHANNEL_FRONT_BACK            AUDIO_CHANNEL = 260
)

type AUDIO_CONTENT_TYPE

type AUDIO_CONTENT_TYPE int32
const (
	AAUDIO_CONTENT_TYPE_SPEECH       AUDIO_CONTENT_TYPE = 1
	AAUDIO_CONTENT_TYPE_MUSIC        AUDIO_CONTENT_TYPE = 2
	AAUDIO_CONTENT_TYPE_MOVIE        AUDIO_CONTENT_TYPE = 3
	AAUDIO_CONTENT_TYPE_SONIFICATION AUDIO_CONTENT_TYPE = 4
)

type AUDIO_DIRECTION

type AUDIO_DIRECTION int32
const (
	AAUDIO_DIRECTION_OUTPUT AUDIO_DIRECTION = 0
	AAUDIO_DIRECTION_INPUT  AUDIO_DIRECTION = 1
)

type AUDIO_FORMAT

type AUDIO_FORMAT int32
const (
	AAUDIO_FORMAT_INVALID        AUDIO_FORMAT = -1
	AAUDIO_FORMAT_UNSPECIFIED    AUDIO_FORMAT = 0
	AAUDIO_FORMAT_PCM_I16        AUDIO_FORMAT = 1
	AAUDIO_FORMAT_PCM_FLOAT      AUDIO_FORMAT = 2
	AAUDIO_FORMAT_PCM_I24_PACKED AUDIO_FORMAT = 3
	AAUDIO_FORMAT_PCM_I32        AUDIO_FORMAT = 4
	AAUDIO_FORMAT_IEC61937       AUDIO_FORMAT = 5
)

type AUDIO_INPUT_PRESET

type AUDIO_INPUT_PRESET int32
const (
	AAUDIO_INPUT_PRESET_GENERIC               AUDIO_INPUT_PRESET = 1
	AAUDIO_INPUT_PRESET_CAMCORDER             AUDIO_INPUT_PRESET = 5
	AAUDIO_INPUT_PRESET_VOICE_RECOGNITION     AUDIO_INPUT_PRESET = 6
	AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION   AUDIO_INPUT_PRESET = 7
	AAUDIO_INPUT_PRESET_UNPROCESSED           AUDIO_INPUT_PRESET = 9
	AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE     AUDIO_INPUT_PRESET = 10
	AAUDIO_INPUT_PRESET_SYSTEM_ECHO_REFERENCE AUDIO_INPUT_PRESET = 1997
	AAUDIO_INPUT_PRESET_SYSTEM_HOTWORD        AUDIO_INPUT_PRESET = 1999
)

type AUDIO_PERFORMANCE_MODE

type AUDIO_PERFORMANCE_MODE int32
const (
	AAUDIO_PERFORMANCE_MODE_NONE         AUDIO_PERFORMANCE_MODE = 10
	AAUDIO_PERFORMANCE_MODE_POWER_SAVING AUDIO_PERFORMANCE_MODE = 11
	AAUDIO_PERFORMANCE_MODE_LOW_LATENCY  AUDIO_PERFORMANCE_MODE = 12
)

type AUDIO_SESSION_ID

type AUDIO_SESSION_ID int32
const (
	AAUDIO_SESSION_ID_NONE     AUDIO_SESSION_ID = -1
	AAUDIO_SESSION_ID_ALLOCATE AUDIO_SESSION_ID = 0
)

type AUDIO_SHARING_MODE

type AUDIO_SHARING_MODE int32
const (
	AAUDIO_SHARING_MODE_EXCLUSIVE AUDIO_SHARING_MODE = 0
	AAUDIO_SHARING_MODE_SHARED    AUDIO_SHARING_MODE = 1
)

type AUDIO_SPATIALIZATION_BEHAVIOR

type AUDIO_SPATIALIZATION_BEHAVIOR int32
const (
	AAUDIO_SPATIALIZATION_BEHAVIOR_AUTO  AUDIO_SPATIALIZATION_BEHAVIOR = 1
	AAUDIO_SPATIALIZATION_BEHAVIOR_NEVER AUDIO_SPATIALIZATION_BEHAVIOR = 2
)

type AUDIO_STREAM_STATE

type AUDIO_STREAM_STATE int32
const (
	AAUDIO_STREAM_STATE_UNINITIALIZED AUDIO_STREAM_STATE = 0
	AAUDIO_STREAM_STATE_UNKNOWN       AUDIO_STREAM_STATE = 1
	AAUDIO_STREAM_STATE_OPEN          AUDIO_STREAM_STATE = 2
	AAUDIO_STREAM_STATE_STARTING      AUDIO_STREAM_STATE = 3
	AAUDIO_STREAM_STATE_STARTED       AUDIO_STREAM_STATE = 4
	AAUDIO_STREAM_STATE_PAUSING       AUDIO_STREAM_STATE = 5
	AAUDIO_STREAM_STATE_PAUSED        AUDIO_STREAM_STATE = 6
	AAUDIO_STREAM_STATE_FLUSHING      AUDIO_STREAM_STATE = 7
	AAUDIO_STREAM_STATE_FLUSHED       AUDIO_STREAM_STATE = 8
	AAUDIO_STREAM_STATE_STOPPING      AUDIO_STREAM_STATE = 9
	AAUDIO_STREAM_STATE_STOPPED       AUDIO_STREAM_STATE = 10
	AAUDIO_STREAM_STATE_CLOSING       AUDIO_STREAM_STATE = 11
	AAUDIO_STREAM_STATE_CLOSED        AUDIO_STREAM_STATE = 12
	AAUDIO_STREAM_STATE_DISCONNECTED  AUDIO_STREAM_STATE = 13
)

type Clockid_t

type Clockid_t = capi.Clockid_t

type DataCallbackResult

type DataCallbackResult int32
const (
	Continue DataCallbackResult = 0
	Stop     DataCallbackResult = 1
)

type Direction

type Direction int32
const (
	Output Direction = 0
	Input  Direction = 1
)

func (Direction) String

func (v Direction) String() string

type Error

type Error int32

Error represents an NDK error code.

const (
	ErrBase            Error = -900
	ErrDisconnected    Error = -899
	ErrIllegalArgument Error = -898
	ErrInternal        Error = -896
	ErrInvalidState    Error = -895
	ErrInvalidHandle   Error = -892
	ErrUnimplemented   Error = -890
	ErrUnavailable     Error = -889
	ErrNoFreeHandles   Error = -888
	ErrNoMemory        Error = -887
	ErrNull            Error = -886
	ErrTimeout         Error = -885
	ErrWouldBlock      Error = -884
	ErrInvalidFormat   Error = -883
	ErrOutOfRange      Error = -882
	ErrNoService       Error = -881
	ErrInvalidRate     Error = -880
)

func (Error) Error

func (e Error) Error() string

type Format

type Format int32
const (
	Invalid      Format = -1
	Unspecified  Format = 0
	PcmI16       Format = 1
	PcmFloat     Format = 2
	PcmI24Packed Format = 3
	PcmI32       Format = 4
	Iec61937     Format = 5
)

type PerformanceMode

type PerformanceMode int32
const (
	None        PerformanceMode = 10
	PowerSaving PerformanceMode = 11
	LowLatency  PerformanceMode = 12
)

type SharingMode

type SharingMode int32
const (
	Exclusive SharingMode = 0
	Shared    SharingMode = 1
)

type Stream

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

Stream wraps the NDK AAudioStream handle.

func NewStreamFromPointer

func NewStreamFromPointer(ptr unsafe.Pointer) *Stream

NewStreamFromPointer wraps a raw AAudioStream pointer.

func (*Stream) ChannelCount

func (h *Stream) ChannelCount() int32

ChannelCount returns the value directly.

func (*Stream) Close

func (h *Stream) Close() error

Close releases the underlying NDK handle.

func (*Stream) Flush

func (h *Stream) Flush() error

Flush calls the underlying NDK function.

func (*Stream) FramesPerBurst

func (h *Stream) FramesPerBurst() int32

FramesPerBurst returns the value directly.

func (*Stream) GetBufferCapacityInFrames

func (h *Stream) GetBufferCapacityInFrames() error

GetBufferCapacityInFrames calls the underlying NDK function.

func (*Stream) GetBufferSizeInFrames

func (h *Stream) GetBufferSizeInFrames() error

GetBufferSizeInFrames calls the underlying NDK function.

func (*Stream) GetDeviceID

func (h *Stream) GetDeviceID() error

GetDeviceID calls the underlying NDK function.

func (*Stream) GetFramesPerDataCallback

func (h *Stream) GetFramesPerDataCallback() error

GetFramesPerDataCallback calls the underlying NDK function.

func (*Stream) GetFramesRead

func (h *Stream) GetFramesRead() int64

GetFramesRead returns the value directly.

func (*Stream) GetFramesWritten

func (h *Stream) GetFramesWritten() int64

GetFramesWritten returns the value directly.

func (*Stream) GetHardwareChannelCount

func (h *Stream) GetHardwareChannelCount() error

GetHardwareChannelCount calls the underlying NDK function.

func (*Stream) GetHardwareSampleRate

func (h *Stream) GetHardwareSampleRate() error

GetHardwareSampleRate calls the underlying NDK function.

func (*Stream) GetSamplesPerFrame

func (h *Stream) GetSamplesPerFrame() error

GetSamplesPerFrame calls the underlying NDK function.

func (*Stream) IsContentSpatialized

func (h *Stream) IsContentSpatialized() bool

IsContentSpatialized returns the value directly.

func (*Stream) IsPrivacySensitive

func (h *Stream) IsPrivacySensitive() bool

IsPrivacySensitive returns the value directly.

func (*Stream) Pause

func (h *Stream) Pause() error

Pause calls the underlying NDK function.

func (*Stream) Pointer

func (h *Stream) Pointer() unsafe.Pointer

Pointer returns the underlying pointer as unsafe.Pointer.

func (*Stream) Read

func (h *Stream) Read(buffer []byte, numFrames int32, timeout time.Duration) (int32, error)

Read calls the underlying NDK function and returns the frame count.

func (*Stream) SampleRate

func (h *Stream) SampleRate() int32

SampleRate returns the value directly.

func (*Stream) Start

func (h *Stream) Start() error

Start calls the underlying NDK function.

func (*Stream) State

func (h *Stream) State() StreamState

State returns the value directly.

func (*Stream) Stop

func (h *Stream) Stop() error

Stop calls the underlying NDK function.

func (*Stream) Write

func (h *Stream) Write(buffer []byte, numFrames int32, timeout time.Duration) (int32, error)

Write calls the underlying NDK function and returns the frame count.

func (*Stream) XRunCount

func (h *Stream) XRunCount() int32

XRunCount returns the value directly.

type StreamBuilder

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

StreamBuilder wraps the NDK AAudioStreamBuilder handle.

func NewStreamBuilder

func NewStreamBuilder() (*StreamBuilder, error)

NewStreamBuilder creates a new StreamBuilder.

func NewStreamBuilderFromPointer

func NewStreamBuilderFromPointer(ptr unsafe.Pointer) *StreamBuilder

NewStreamBuilderFromPointer wraps a raw AAudioStreamBuilder pointer.

func (*StreamBuilder) Close

func (h *StreamBuilder) Close() error

Close releases the underlying NDK handle.

func (*StreamBuilder) Open

func (h *StreamBuilder) Open() (*Stream, error)

Open creates a new Stream from this StreamBuilder.

func (*StreamBuilder) Pointer

func (h *StreamBuilder) Pointer() unsafe.Pointer

Pointer returns the underlying pointer as unsafe.Pointer.

func (*StreamBuilder) SetAttributionTag

func (h *StreamBuilder) SetAttributionTag(attributionTag string)

SetAttributionTag calls the underlying NDK function.

func (*StreamBuilder) SetBufferCapacityInFrames

func (h *StreamBuilder) SetBufferCapacityInFrames(numFrames int32) *StreamBuilder

SetBufferCapacityInFrames sets a property and returns the receiver for chaining.

func (*StreamBuilder) SetChannelCount

func (h *StreamBuilder) SetChannelCount(channelCount int32) *StreamBuilder

SetChannelCount sets a property and returns the receiver for chaining.

func (*StreamBuilder) SetDeviceID

func (h *StreamBuilder) SetDeviceID(deviceID int32) *StreamBuilder

SetDeviceID sets a property and returns the receiver for chaining.

func (*StreamBuilder) SetDirection

func (h *StreamBuilder) SetDirection(direction Direction) *StreamBuilder

SetDirection sets a property and returns the receiver for chaining.

func (*StreamBuilder) SetFormat

func (h *StreamBuilder) SetFormat(format Format) *StreamBuilder

SetFormat sets a property and returns the receiver for chaining.

func (*StreamBuilder) SetFramesPerDataCallback

func (h *StreamBuilder) SetFramesPerDataCallback(numFrames int32)

SetFramesPerDataCallback calls the underlying NDK function.

func (*StreamBuilder) SetIsContentSpatialized

func (h *StreamBuilder) SetIsContentSpatialized(isSpatialized bool)

SetIsContentSpatialized calls the underlying NDK function.

func (*StreamBuilder) SetPackageName

func (h *StreamBuilder) SetPackageName(packageName string)

SetPackageName calls the underlying NDK function.

func (*StreamBuilder) SetPerformanceMode

func (h *StreamBuilder) SetPerformanceMode(mode PerformanceMode) *StreamBuilder

SetPerformanceMode sets a property and returns the receiver for chaining.

func (*StreamBuilder) SetPrivacySensitive

func (h *StreamBuilder) SetPrivacySensitive(privacySensitive bool)

SetPrivacySensitive calls the underlying NDK function.

func (*StreamBuilder) SetSampleRate

func (h *StreamBuilder) SetSampleRate(sampleRate int32) *StreamBuilder

SetSampleRate sets a property and returns the receiver for chaining.

func (*StreamBuilder) SetSamplesPerFrame

func (h *StreamBuilder) SetSamplesPerFrame(samplesPerFrame int32)

SetSamplesPerFrame calls the underlying NDK function.

func (*StreamBuilder) SetSharingMode

func (h *StreamBuilder) SetSharingMode(sharingMode SharingMode) *StreamBuilder

SetSharingMode sets a property and returns the receiver for chaining.

type StreamState

type StreamState int32
const (
	Uninitialized StreamState = 0
	Unknown       StreamState = 1
	Open          StreamState = 2
	Starting      StreamState = 3
	Started       StreamState = 4
	Pausing       StreamState = 5
	Paused        StreamState = 6
	Flushing      StreamState = 7
	Flushed       StreamState = 8
	Stopping      StreamState = 9
	Stopped       StreamState = 10
	Closing       StreamState = 11
	Closed        StreamState = 12
	Disconnected  StreamState = 13
)

func (StreamState) String

func (v StreamState) String() string

Jump to

Keyboard shortcuts

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