## ALSA ALSA — Library with ALSA helpers |

## Functions

struct alsa * | alsa_init ()
int | alsa_open_output ()
int | alsa_open_input ()
void | alsa_close_output ()
void | alsa_close_input ()
bool | alsa_test_output_configuration ()
bool | alsa_test_input_configuration ()
void | alsa_configure_output ()
void | alsa_configure_input ()
void | alsa_register_output_callback ()
void | alsa_register_input_callback ()
int | alsa_run ()

## Types and Values

struct | alsa

## Includes

    #include <igt_alsa.h>

## Description

This library contains helpers for ALSA playback and capture.

## Functions

### 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_open_input ()

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

Open the ALSA input device whose name matches the provided name prefix.

#### Parameters

alsa | The target alsa structure |
device_name | The name of the input device 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 the open ALSA input.

#### Parameters

alsa | The target alsa structure |

### alsa_close_input ()

    void
    alsa_close_input (struct alsa *alsa);

### alsa_test_output_configuration ()

    bool
    alsa_test_output_configuration (struct alsa *alsa,
                                    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 |
channels | The number of channels to test |
sampling_rate | The sampling rate to test |

#### Returns

A boolean indicating whether the test succeeded

### alsa_test_input_configuration ()

    bool
    alsa_test_input_configuration (struct alsa *alsa,
                                   int channels,
                                   int sampling_rate);

Test the input configuration specified by `channels` and `sampling_rate` for the input device.

#### Parameters

alsa | The target alsa structure |
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,
                           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_configure_input ()

    void
    alsa_configure_input (struct alsa *alsa,
                          int channels,
                          int sampling_rate);

Configure the input device 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, short *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_register_input_callback ()

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

Register a callback function to be called when input data is available during a run. The callback is called when `samples_trigger` samples are available.

The callback should return an integer equal to zero for success, negative for failure and positive to indicate that the run should stop.

#### Parameters

alsa | The target alsa structure |
callback | The callback function to call when input data is available |
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 |

#### 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;