CM ALSA Source

The cmAlsaSource is used to get data from the microphone by the ALSA Interface. It supports the input data format setting and multi-link for output. The ALSA device only supports one connection at a time, but the cmAlsaSource can output data to multi-pipeline.


API Instructions

create/destroy

/* @device Alsa device, default hw:0,0*/ gpointer cm_audio_alsa_source_create(gchar* device); void cm_audio_alsa_source_destroy(gpointer hd);

start/stop

void cm_audio_alsa_source_start(gpointer hd); void cm_audio_alsa_source_stop(gpointer hd);

parameters

Set caps string to choose the data format if the device supports more than one.

/* @caps_str0 Mic format, "audio/x-raw,rate=44100,channels=1,..." */ void cm_audio_alsa_source_set_caps_str0(gpointer hd, const gchar* caps_str0); /* @return Actual data format from device, "video/x-raw,..." */ const char* cm_audio_alsa_source_get_caps_str(gpointer had);

Wait until the data media info is ready, and the source can be linked.

data

other


Demo and Test

PCM demo

Structure

Get audio data from the microphone then send it to the data callback.

image-20240520-071226.png

Main codes

For more details please refer to the demo file.

Test result

image-20240520-071242.png

The audio data can be saved to the file and displayed on the PC.