ALSA

ALSA — Library with ALSA helpers

Functions

Types and Values

struct alsa

Includes

#include <igt_alsa.h>

Description

This library contains helpers for ALSA playback and capture.

Functions

alsa_has_exclusive_access ()

bool
alsa_has_exclusive_access (void);

alsa_init ()

struct alsa *
alsa_init (void);

Returns

A newly-allocated alsa structure


alsa_open_output ()

int
alsa_open_output (struct alsa *alsa,
                  const char *device_name);

Open ALSA output devices whose name prefixes match the provided name prefix.

Parameters

alsa

The target alsa structure

 

device_name

The name prefix of the output device(s) to open

 

Returns

An integer equal to zero for success and negative for failure


alsa_close_output ()

void
alsa_close_output (struct alsa *alsa);

Close all the open ALSA outputs.

Parameters

alsa

The target alsa structure

 

alsa_test_output_configuration ()

bool
alsa_test_output_configuration (struct alsa *alsa,
                                snd_pcm_format_t dmt,
                                int channels,
                                int sampling_rate);

Test the output configuration specified by channels and sampling_rate for the output devices.

Parameters

alsa

The target alsa structure

 

fmt

The format to test

 

channels

The number of channels to test

 

sampling_rate

The sampling rate to test

 

Returns

A boolean indicating whether the test succeeded


alsa_configure_output ()

void
alsa_configure_output (struct alsa *alsa,
                       snd_pcm_format_t fmt,
                       int channels,
                       int sampling_rate);

Configure the output devices with the configuration specified by channels and sampling_rate .

Parameters

alsa

The target alsa structure

 

channels

The number of channels to test

 

sampling_rate

The sampling rate to test

 

alsa_register_output_callback ()

void
alsa_register_output_callback (struct alsa *alsa,
                               int (*callback) (void *data, void *buffer, int samples),
                               void *callback_data,
                               int samples_trigger);

Register a callback function to be called to fill output data during a run. The callback is called when samples_trigger samples are required.

The callback should return an integer equal to zero for success and negative for failure.

Parameters

alsa

The target alsa structure

 

callback

The callback function to call to fill output data

 

callback_data

The data pointer to pass to the callback function

 

samples_trigger

The required number of samples to trigger the callback

 

alsa_run ()

int
alsa_run (struct alsa *alsa,
          int duration_ms);

Run ALSA playback and capture on the input and output devices for at most duration_ms milliseconds, calling the registered callbacks when needed.

Parameters

alsa

The target alsa structure

 

duration_ms

The maximum duration of the run in milliseconds, or -1 for an infinite duration.

 

Returns

An integer equal to zero for success, positive for a stop caused by the input callback and negative for failure

Types and Values

struct alsa

struct alsa;