# Enable TinyALSA-based applications TinyALSA is a library that wraps the ALSA kernel interface into APIs that clients can invoke. It also gives a plug-in interface to emulate ALSA APIs. Find TinyALSA source code at: `build-qcom-wayland/workspace/sources/tinyalsa` and `build-qcom-wayland/workspace/sources/tinycompress`. The following figure shows the TinyALSA plug-in architecture. VBackground-1 Solid Page-1 Sheet.42 Sheet.13 TinyALSA TinyALSA Sheet.14 Tiny compress Tiny compress Sheet.1 Client Client Sheet.2 ALSA/ASoC kernel framework ALSA/ASoC kernel framework Sheet.3 Compress plugin Compress plugin Sheet.4 PCM plugin PCM plugin Sheet.5 Mixer plugin Mixer plugin Sheet.6 PCM PCM Sheet.7 Libaudioroute Libaudioroute Sheet.8 Mixer Mixer Sheet.9 Compress Compress Sheet.10 Sheet.11 Sheet.12 ASoC drivers ASoC drivers Dynamic connector Dynamic connector.16 Dynamic connector.19 Dynamic connector.20 Dynamic connector.21 Dynamic connector.22 Dynamic connector.24 Dynamic connector.27 Dynamic connector.28 Dynamic connector.30 Dynamic connector.31 Dynamic connector.32 Sheet.34 Sheet.40 Open source/Framework Open source/Framework Sheet.41 Legend Legend TinyALSA plug-in architecture The ALSA framework in the kernel exposes card and device nodes for PCM, compress, and mixer. PCM, mixer, and compress plug-ins are TinyALSA plug-ins. They route all PCM, mixer, and compress calls from the application to plug-in specific implementation. The plug-ins create a virtual sound card with PCM, compress, and mixer nodes. Virtual nodes map to on-device `.so` files (dynamically loadable shared objects). The virtual sound card configuration is in the `card-defs.xml` file. This file is in the `/etc/` folder on the device. ## TinyALSA APIs The following are common TinyALSA APIs. See the [open source TinyALSA documentation](https://github.com/tinyalsa/tinyalsa/blob/master/include/tinyalsa/pcm.h) for a complete description of all APIs. ### pcm\_open Opens a PCM audio device for input and output operations. Initializes a PCM device for communication, allowing read/write operations in audio data. struct pcm *pcm_open( unsigned int card, unsigned int device, unsigned int flags, struct pcm_config *config) Copy to clipboard **Parameters** | card | Card number. | | --- | --- | | device | Device number in the chosen card. | | flags | Flags to configure the PCM device. | | config | Structure variable that specifies audio stream parameters. | **Return value** `pcm* handle` ### pcm\_is\_ready Checks if the PCM device is ready for input and output operations. int pcm_is_ready(struct pcm *pcm) Copy to clipboard **Parameters** | pcm | Pointer to the open PCM device. | | --- | --- | **Return value** - Non-zero if the PCM device is ready - 0 if the PCM device isn’t ready ### pcm\_prepare Prepares audio device input and output operations. int pcm_prepare( struct pcm *pcm) Copy to clipboard **Parameters** | pcm | Pointer to the open PCM device. | | --- | --- | **Return value** - 0 on success - Error code on failure ### pcm\_start Starts the PCM audio device for input and output operations. int pcm_start( struct pcm *pcm) Copy to clipboard **Parameters** | pcm | Pointer to the open PCM device. | | --- | --- | **Return value** - 0 on success - Error code on failure ### pcm\_write Writes audio data to the audio PCM device. Takes audio data as input and sends it to the PCM device for playback or processing. int pcm_write( struct pcm *pcm, const void *data, unsigned int count) Copy to clipboard **Parameters** | pcm | Pointer to the open PCM device. | | --- | --- | | data | Audio data to write. | | count | Number of audio frames to write. | **Return value** - 0 on success - Error code on failure ### pcm\_read Gets audio data from the PCM device, which allows the application to capture audio data from a microphone. int pcm_read( struct pcm *pcm, void *data, unsigned int count) Copy to clipboard **Parameters** | pcm | Pointer to the open PCM device. | | --- | --- | | data | Audio data to read. | | count | Number of audio frames to read. | **Return value** - 0 on success - Error code on failure ### pcm\_stop Stops the PCM audio device from further input and output operations. int pcm_stop( struct pcm *pcm) Copy to clipboard **Parameters** | pcm | Pointer to the open PCM device. | | --- | --- | **Return value** - 0 on success - Error code on failure ### pcm\_close Closes the PCM audio device. This releases the resources associated with the PCM device and releases the memory. int pcm_close( struct pcm *pcm) Copy to clipboard **Parameters** | pcm | Pointer to the open PCM device. | | --- | --- | **Return value** - 0 on success - Error code on failure ## Configure TinyALSA For audio use cases from TinyALSA, configure the virtual mixer controls. These controls, created by the mixer plug-in, set up audio use case graphs and modules. Most are byte array-based and are configured using the `mixer_ctl_set_array` API. Metadata (referred to as ‘PCM100 metadata’) is set using key-value (KV) pairs. For implementation details, see the `set_agm_audio_intf_metadata` API in `build-qcom-wayland/workspace/sources/qcom-agm/opensource/agm/plugins/tinyalsa/test/agmmixer.c`. /** * Key Vector pair */ struct agm_key_value { uint32_t key; /**< key */ uint32_t value; /**< value */ }; /*Sample allocation for the key value pair*/ gkv = calloc(num_gkv, sizeof(struct agm_key_value)); ckv = calloc(num_ckv, sizeof(struct agm_key_value)); Copy to clipboard Sample code for the TinyALSA-based agmplay and agmcap utilities can be found at: `build-qcom-wayland/workspace/sources/qcom-agm/opensource/agm/plugins/tinyalsa/test`. To enable and execute audio use cases from TinyALSA: 1. Set the audio interface (backend) device configuration, including sample rate, channels, format, and data format. 'CODEC_DMA-LPAIF_WSA-RX-0 rate ch fmt' 48000 2 2(PCM_16) Copy to clipboard 2. Set the metadata, including graph keys, cal keys for the device, and DevicePP. 'CODEC_DMA-LPAIF_WSA-RX-0 metadata' bytes Copy to clipboard 3. Set the control to indicate that follow-on mixer configurations will set the metadata for the stream and StreamPP subgraphs. Zero indicates that subsequent commands are for the stream. 'PCM100 control' Zero 'PCM100 metadata' bytes Copy to clipboard 4. Set the control to indicate that follow on mixer configurations will set the metadata for the DevicePP and stream-device subgraphs. `CODEC_DMA-LPAIF_WSA-RX-0` indicates that the subsequent commands are for stream-device. `CODEC_DMA-LPAIF_WSA-RX-0` is one of the audio interfaces registered with the ALSA ASOC framework. A list of all audio interfaces can be found at `/proc/asound/pcm`. 'PCM100 control' CODEC_DMA-LPAIF_WSA-RX-0 'PCM100 metadata' bytes Copy to clipboard 5. Retrieve all tags, module ID, and instance IDs associated with a given session between the stream and audio interface. 'PCM100 getTaggedInfo' bytes Copy to clipboard 6. Set the control to indicate that follow on mixer configurations will set the parameters for modules on the stream subgraph. 'PCM100 control' Zero 'PCM100 setParam' bytes Copy to clipboard 7. Set the control to indicate that follow on mixer configurations will set the parameters for modules on the StreamDevice and DevicePP subgraphs. 'PCM100 control' CODEC_DMA-LPAIF_WSA-RX-0 'PCM100 setParam' bytes Copy to clipboard 8. Connect the frontend (stream) with the backend (codec/audio interface). 'PCM100 connect'CODEC_DMA-LPAIF_WSA-RX-0 Copy to clipboard 9. Open the PCM device. pcm_open Copy to clipboard 10. Prepare the audio device for input and output operations. pcm_prepare Copy to clipboard 11. Start the PCM audio device for input and output operations. pcm_start Copy to clipboard 12. Write and read audio data from the audio PCM device. pcm_write/pcm_read Copy to clipboard 13. Stop the PCM device. pcm_stop Copy to clipboard 14. Close the PCM audio device. pcm_close Copy to clipboard All mixer controls for a virtual device can be fetched using: ssh root@ip-addr Copy to clipboard systemctl stop pipewire Copy to clipboard tinymix set -D 100 Copy to clipboard Last Published: Jun 17, 2026 [Previous Topic Customize at PAL level](https://docs.qualcomm.com/bundle/publicresource/80-70030-16/topics/pal.md) [Next Topic Customize audio graph](https://docs.qualcomm.com/bundle/publicresource/80-70030-16/topics/agm.md)