Documentation
¶
Overview ¶
Package audio interacts with audio operation.
Package audio interacts with audio operation.
Index ¶
- Constants
- func CheckRecordingQuality(ctx context.Context, fileName string) error
- func ConvertRawToWav(ctx context.Context, rawFileName, wavFileName string, rate, channels int) error
- func GenerateTestRawData(ctx context.Context, testData TestRawData) error
- func GetRmsAmplitude(ctx context.Context, testData TestRawData) (float64, error)
- func LoadAloop(ctx context.Context) (func(ctx context.Context), error)
- func RestartCras(ctx context.Context) error
- func TrimFileFrom(ctx context.Context, oldFileName, newFileName string, startTime time.Duration) error
- func WaitForDevice(ctx context.Context, streamType StreamType) error
- type Card
- type Cras
- func (c *Cras) GetNodeByType(ctx context.Context, t string) (*CrasNode, error)
- func (c *Cras) GetNodes(ctx context.Context) ([]CrasNode, error)
- func (c *Cras) GetVolumeState(ctx context.Context) (*VolumeState, error)
- func (c *Cras) SelectedOutputDevice(ctx context.Context) (deviceName, deviceType string, err error)
- func (c *Cras) SetActiveNode(ctx context.Context, node CrasNode) error
- func (c *Cras) SetActiveNodeByType(ctx context.Context, nodeType string) error
- func (c *Cras) SetOutputNodeVolume(ctx context.Context, node CrasNode, volume int) error
- func (c *Cras) WaitForDeviceUntil(ctx context.Context, condition func(*CrasNode) bool, timeout time.Duration) error
- type CrasNode
- type Helper
- type StreamType
- type TestRawData
- type VolumeState
Constants ¶
const AloopCrasNodeType = "ALSA_LOOPBACK"
AloopCrasNodeType defines CrasNode type for ALSA loopback.
Variables ¶
This section is empty.
Functions ¶
func CheckRecordingQuality ¶
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 ¶
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 ¶
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 Card ¶
Card is a card listed in /proc/asound/cards as: ## [ID ]: Driver - ShortName
LongName
snd_iprintf(buffer, "%2i [%-15s]: %s - %s\n",
idx, card->id, card->driver, card->shortname);
snd_iprintf(buffer, " %s\n",
card->longname);
func GetSoundCards ¶
GetSoundCards returns Cards from /proc/asound/cards
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 (*Cras) GetNodeByType ¶
GetNodeByType returns the first node with given type.
func (*Cras) GetVolumeState ¶
func (c *Cras) GetVolumeState(ctx context.Context) (*VolumeState, error)
GetVolumeState calls cras.Control.GetVolumeState over D-Bus.
func (*Cras) SelectedOutputDevice ¶
SelectedOutputDevice returns the active output device name and type.
func (*Cras) SetActiveNode ¶
SetActiveNode calls cras.Control.SetActiveInput(Output)Node over D-Bus.
func (*Cras) SetActiveNodeByType ¶
SetActiveNodeByType sets node with specified type active.
func (*Cras) SetOutputNodeVolume ¶
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 ¶
NewVolumeHelper returns a new volume Helper instance.
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 ¶
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 |