Audio

Audio — Library for audio-related tests

Functions

Types and Values

struct audio_signal

Includes

#include <igt_audio.h>

Description

This library contains helpers for audio-related tests. More specifically, it allows generating additions of sine signals as well as detecting them.

Functions

audio_signal_init ()

struct audio_signal *
audio_signal_init (int channels,
                   int sampling_rate);

Allocate and initialize an audio signal structure with the given parameters.

Parameters

channels

The number of channels to use for the signal

 

sampling_rate

The sampling rate to use for the signal

 

Returns

A newly-allocated audio signal structure


audio_signal_fini ()

void
audio_signal_fini (struct audio_signal *signal);

Release the signal.


audio_signal_add_frequency ()

int
audio_signal_add_frequency (struct audio_signal *signal,
                            int frequency,
                            int channel);

Add a frequency to the signal.

Parameters

signal

The target signal structure

 

frequency

The frequency to add to the signal

 

channel

The channel to add this frequency to, or -1 to add it to all channels

 

Returns

An integer equal to zero for success and negative for failure


audio_signal_synthesize ()

void
audio_signal_synthesize (struct audio_signal *signal);

Synthesize the data tables for the audio signal, that can later be used to fill audio buffers. The resources allocated by this function must be freed with a call to audio_signal_clean when the signal is no longer used.

Parameters

signal

The target signal structure

 

audio_signal_reset ()

void
audio_signal_reset (struct audio_signal *signal);

Free the resources allocated by audio_signal_synthesize and remove the previously-added frequencies.

Parameters

signal

The target signal structure

 

audio_signal_fill ()

void
audio_signal_fill (struct audio_signal *signal,
                   double *buffer,
                   size_t samples);

Fill the requested number of samples to the target buffer with the audio signal data (in interleaved double format), at the requested sampling rate and number of channels.

Each sample is normalized (ie. between 0 and 1).

Parameters

signal

The target signal structure

 

buffer

The target buffer to fill

 

samples

The number of samples to fill

 

audio_signal_detect ()

bool
audio_signal_detect (struct audio_signal *signal,
                     int sampling_rate,
                     int channel,
                     const double *samples,
                     size_t samples_len);

audio_extract_channel_s32_le ()

size_t
audio_extract_channel_s32_le (double *dst,
                              size_t dst_cap,
                              int32_t *src,
                              size_t src_len,
                              int n_channels,
                              int channel);

audio_convert_to ()

void
audio_convert_to (void *dst,
                  double *src,
                  size_t len,
                  snd_pcm_format_t format);

audio_create_wav_file_s32_le ()

int
audio_create_wav_file_s32_le (const char *qualifier,
                              uint32_t sample_rate,
                              uint16_t channels,
                              char **path);

Creates a new WAV file.

After calling this function, the caller is expected to write S32_LE PCM data to the returned file descriptor.

See http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html for a WAV file format specification.

Parameters

qualifier

the basename of the file (the test name will be prepended, and the file extension will be appended)

 

sample_rate

the sample rate in Hz

 

channels

the number of channels

 

path

if non-NULL, will be set to a pointer to the new file path (the caller is responsible for free-ing it)

 

Returns

a file descriptor to the newly created file, or -1 on error.

Types and Values

struct audio_signal

struct audio_signal;