audio

package
v0.0.0-...-683b059 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package audio interacts with audio operation.

Package audio interacts with audio operation.

Index

Constants

View Source
const AloopCrasNodeType = "ALSA_LOOPBACK"

AloopCrasNodeType defines CrasNode type for ALSA loopback.

Variables

This section is empty.

Functions

func CheckRecordingQuality

func CheckRecordingQuality(ctx context.Context, fileName string) error

CheckRecordingQuality checks the recording file to see whether internal mic works normally. A qualified file must meet these requirements: 1. The RMS must be smaller than the threshold. If not, it may be the static noise inside. 2. The recorded samples can not be all zeros. It is impossible for a normal internal mic.

func ConvertRawToWav

func ConvertRawToWav(ctx context.Context, rawFileName, wavFileName string, rate, channels int) error

ConvertRawToWav converts the audio raw file to wav file.

func GenerateTestRawData

func GenerateTestRawData(ctx context.Context, testData TestRawData) error

GenerateTestRawData generates sine raw data by sox with specified parameters in testData, and stores in testData.Path.

func GetRmsAmplitude

func GetRmsAmplitude(ctx context.Context, testData TestRawData) (float64, error)

GetRmsAmplitude gets signal RMS of testData by sox.

func LoadAloop

func LoadAloop(ctx context.Context) (func(ctx context.Context), error)

LoadAloop loads snd-aloop module on kernel. A deferred call to the returned unloadAloop function to unload snd-aloop should be scheduled by the caller if err is non-nil.

func RestartCras

func RestartCras(ctx context.Context) error

RestartCras restart cras and waits for it to be ready

func TrimFileFrom

func TrimFileFrom(ctx context.Context, oldFileName, newFileName string, startTime time.Duration) error

TrimFileFrom removes all samples before startTime from the file.

func WaitForDevice

func WaitForDevice(ctx context.Context, streamType StreamType) error

WaitForDevice waits for specified types of stream nodes to be active. You can pass the streamType as a bitmap to wait for both input and output nodes to be active. Ex: WaitForDevice(ctx, InputStream|OutputStream) It should be used to verify the target types of nodes exist and are active before the real test starts. Notice that some devices use their displays as an internal speaker (e.g. monroe). When a display is closed, the internal speaker is removed, too. For this case, we should call power.TurnOnDisplay to turn on a display to re-enable an internal speaker.

Types

type Cras

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

Cras is used to interact with the cras process over D-Bus. For detailed spec, please find src/third_party/adhd/cras/README.dbus-api.

func NewCras

func NewCras(ctx context.Context) (*Cras, error)

NewCras connects to CRAS via D-Bus and returns a Cras object.

func (*Cras) GetNodeByType

func (c *Cras) GetNodeByType(ctx context.Context, t string) (*CrasNode, error)

GetNodeByType returns the first node with given type.

func (*Cras) GetNodes

func (c *Cras) GetNodes(ctx context.Context) ([]CrasNode, error)

GetNodes calls cras.Control.GetNodes over D-Bus.

func (*Cras) GetVolumeState

func (c *Cras) GetVolumeState(ctx context.Context) (*VolumeState, error)

GetVolumeState calls cras.Control.GetVolumeState over D-Bus.

func (*Cras) SelectedOutputDevice

func (c *Cras) SelectedOutputDevice(ctx context.Context) (deviceName, deviceType string, err error)

SelectedOutputDevice returns the active output device name and type.

func (*Cras) SetActiveNode

func (c *Cras) SetActiveNode(ctx context.Context, node CrasNode) error

SetActiveNode calls cras.Control.SetActiveInput(Output)Node over D-Bus.

func (*Cras) SetActiveNodeByType

func (c *Cras) SetActiveNodeByType(ctx context.Context, nodeType string) error

SetActiveNodeByType sets node with specified type active.

func (*Cras) SetOutputNodeVolume

func (c *Cras) SetOutputNodeVolume(ctx context.Context, node CrasNode, volume int) error

SetOutputNodeVolume calls cras.Control.SetOutputNodeVolume over D-Bus.

func (*Cras) WaitForDeviceUntil

func (c *Cras) WaitForDeviceUntil(ctx context.Context, condition func(*CrasNode) bool, timeout time.Duration) error

WaitForDeviceUntil waits until any cras node meets the given condition. condition is a function that takes a cras node as input and returns true if the node status satisfies the criteria.

type CrasNode

type CrasNode struct {
	ID         uint64
	Type       string
	Active     bool
	IsInput    bool
	DeviceName string
	NodeVolume uint64
}

CrasNode contains the metadata of Node in Cras. Currently fields which are actually needed by tests are defined. Please find src/third_party/adhd/cras/README.dbus-api for the meaning of each fields.

type Helper

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

Helper helps to set/get system volume and provides volume related functions.

func NewVolumeHelper

func NewVolumeHelper(ctx context.Context) (*Helper, error)

NewVolumeHelper returns a new volume Helper instance.

func (*Helper) GetVolume

func (vh *Helper) GetVolume(ctx context.Context) (int, error)

GetVolume returns the current volume.

func (*Helper) IsMuted

func (vh *Helper) IsMuted(ctx context.Context) (bool, error)

IsMuted gets the mute status of the user.

func (*Helper) SetVolume

func (vh *Helper) SetVolume(ctx context.Context, volume int) error

SetVolume sets the volume to the given value.

func (*Helper) VerifyVolumeChanged

func (vh *Helper) VerifyVolumeChanged(ctx context.Context, doChange func() error) error

VerifyVolumeChanged verifies volume is changed before and after calling doChange().

type StreamType

type StreamType uint

StreamType is used to specify the type of node we want to use for tests and helper functions.

const (
	// InputStream describes nodes with true IsInput attributes.
	InputStream StreamType = 1 << iota
	// OutputStream describes nodes with false IsInput attributes.
	OutputStream
)

func (StreamType) String

func (t StreamType) String() string

type TestRawData

type TestRawData struct {
	// Path specifies the file path of audio data.
	Path string
	// BitsPerSample specifies bits per data sample.
	BitsPerSample int
	// Channels specifies the channel count of audio data.
	Channels int
	// Rate specifies the sampling rate.
	Rate int
	// Frequencies specifies the frequency of each channel, whose length should be equal to Channels.
	// This is only used in the sine tone generation of sox.
	Frequencies []int
	// Volume specifies the volume scale of sox, e.g. 0.5 to scale volume by half. -1.0 to invert.
	// This is only used in the sine tone generation of sox.
	Volume float32
	// Duration specifies the duration of audio data in seconds.
	Duration int
}

TestRawData is used to specify parameters of the audio test data, which should be raw, signed, and little-endian.

type VolumeState

type VolumeState struct {
	OutputVol      int
	OutputMute     bool
	InputMute      bool
	OutputUserMute bool
}

VolumeState contains the metadata of volume state in Cras. Currently fields which are actually needed by tests are defined. Please find src/third_party/adhd/cras/dbus_bindings/org.chromium.cras.Control.xml for the meaning of each fields.

Directories

Path Synopsis
Package crastestclient provides functions to interact cras_test_client
Package crastestclient provides functions to interact cras_test_client

Jump to

Keyboard shortcuts

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