Registered User mNo edit summary |
Registered User mNo edit summary Tag: 2017 source edit |
||
(34 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
<noinclude> | <noinclude>{{ApplicableFor | ||
{{ | |MPUs list=STM32MP13x, STM32MP15x, STM32MP25x | ||
|MPUs checklist=STM32MP13x, STM32MP15x, STM32MP25x | |||
}} | |||
</noinclude> | </noinclude> | ||
== Article purpose == | == Article purpose == | ||
This article explains how to play audio through the [[ALSA overview|ALSA]] audio framework in '''Linux<sup>®</sup> OS''' context. | This article explains how to play audio through the [[ALSA overview|ALSA]] audio framework in '''Linux<sup>®</sup> OS''' context. | ||
Line 12: | Line 10: | ||
== Audio playback overview == | == Audio playback overview == | ||
The [[ALSA overview|ALSA]] framework exposes audio devices associated to the board audio hardware interfaces. | The [[ALSA overview|ALSA]] framework exposes audio devices associated to the board audio hardware interfaces. | ||
{{Warning|The support of audio output interfaces is board dependent. Please, check available outputs with "''aplay -l''" command.}} | |||
The application audio streams are routed by default through the Pipewire<ref>[https://docs.pipewire.org/ Pipewire documentation]</ref> sound server. Pipewire exposes audio profiles, which are mapped on the ALSA sound card audio devices. The Pipewire server provides a command line interface to list audio profiles and to select one, in order to record from a specific audio interface. | |||
{{info | In this article, the PulseAudio 'pactl' command is used in the examples. This is possible because the PipeWire sound server maintains backward compatibility with the former PulseAudio sound server through the pipewire-pulse package.}} | |||
The | {{Warning|The applications interacting with Weston framework have to be launched as "Weston" user instead of "root" user. The Pulseaudio commands can, for instance, be launched as follows: | ||
su -l "weston" -c "pactl info" | |||
}} | |||
The audio playback examples in following sections are given for [[ALSA_overview#How_to_use|ALSA utilities]]. However, the audio playbacks can be launched by other applications, such as [[Gst-play|gstreamer]] multimedia framework. | The audio playback examples in following sections are given for [[ALSA_overview#How_to_use|ALSA utilities]]. However, the audio playbacks can be launched by other applications, such as [[Gst-play|gstreamer]] multimedia framework. | ||
Line 21: | Line 26: | ||
=== Audio playback on headset output === | === Audio playback on headset output === | ||
==== Playback on ALSA device ==== | |||
Run audio playback on 'playback_codec' ALSA device: | Run audio playback on 'playback_codec' ALSA device: | ||
{{Info|'playback_codec' is an alias defined in /etc/asound.conf, for headset output device.}} | {{Info|'playback_codec' is an alias defined in /etc/asound.conf, for headset output device.}} | ||
{{Board$}} aplay -D playback_codec /usr/share/sounds/alsa/Front_Left.wav | {{Board$}} aplay -D playback_codec /usr/share/sounds/alsa/Front_Left.wav | ||
* ''' | ==== Playback via Pipewire ==== | ||
* '''Configure Pipewire''' | |||
Change the Pulseaudio active profile of the sound card, to 'analog-stereo' profile: | Change the Pulseaudio active profile of the sound card, to 'analog-stereo' profile: | ||
{{Info|The Pulseaudio analog-stereo profile is the default profile. So next command is not required after boot.}} | {{Info|The Pulseaudio analog-stereo profile is the default profile. So next command is not required after boot.}} | ||
{{Info|Example below is given for | {{Info|Example below is given for 'alsa_card.platform-sound' soundcard. Check available sound cards and associated output profiles with "''pactl list cards''" command.}} | ||
{{Board$}} | {{Board$}} pactl set-card-profile alsa_card.platform-sound output:analog-stereo | ||
Run audio playback: | * '''Run audio playback:''' | ||
{{Info|The Pipewire device is the default one, so "-D pipewire" option can be omitted in the playback command.}} | |||
{{Board$}} aplay /usr/share/sounds/alsa/Front_Left.wav | {{Board$}} aplay /usr/share/sounds/alsa/Front_Left.wav | ||
Line 38: | Line 46: | ||
{{Warning|The support of HDMI output is board dependent. Please, check available outputs with "''aplay -l''" command.}} | {{Warning|The support of HDMI output is board dependent. Please, check available outputs with "''aplay -l''" command.}} | ||
==== Playback on ALSA device ==== | |||
Run audio playback on 'playback_hdmi' ALSA device: | Run audio playback on 'playback_hdmi' ALSA device: | ||
{{Info|'playback_hdmi' is an alias defined in /etc/asound.conf, for hdmi output device.}} | {{Info|'playback_hdmi' is an alias defined in /etc/asound.conf, for hdmi output device.}} | ||
{{Board$}} aplay -D playback_hdmi /usr/share/sounds/alsa/Front_Left.wav | {{Board$}} aplay -D playback_hdmi /usr/share/sounds/alsa/Front_Left.wav | ||
* ''' | ==== Playback via Pipewire ==== | ||
* '''Configure Pipewire''' | |||
Change the Pulseaudio active profile of the sound card, to 'hdmi-stereo' profile: | Change the Pulseaudio active profile of the sound card, to 'hdmi-stereo' profile: | ||
{{Info|Example below is given for | {{Info|Example below is given for 'alsa_card.platform-sound' soundcard. Check available sound cards and associated output profiles with "''pactl list cards''" command.}} | ||
{{Board$}} | {{Board$}} pactl set-card-profile alsa_card.platform-sound output:hdmi-stereo | ||
Run audio playback: | * '''Run audio playback:''' | ||
{{Board$}} aplay /usr/share/sounds/alsa/Front_Left.wav | {{Board$}} aplay /usr/share/sounds/alsa/Front_Left.wav | ||
=== Audio playback on S/PDIF output === | === Audio playback on S/PDIF output === | ||
{{Info|S/PDIF ALSA device supports only {{highlight|32-bit audio streams}}. As 32-bit wave files are not provided in sample sound files, speaker-test is used instead of aplay, for convenience, here. Speaker-test generates a 440Hz sine wave in following examples.}} | {{Info|S/PDIF ALSA device supports only {{highlight|32-bit audio streams}}. As 32-bit wave files are not provided in sample sound files, speaker-test is used instead of aplay, for convenience, here. Speaker-test generates a 440Hz sine wave in following examples.}} | ||
==== Set IEC958 status bits ==== | |||
{{Info|Example below is given for {{highlight|sound card index 0}}. Check sound card index with "''aplay -l''" command.}} | |||
Example: set IEC958 mode bit. | |||
{{Board$}} iecset -c 0 -n device=0 pro on | |||
==== Playback on ALSA device ==== | |||
Run audio playback on 'playback_spdif' ALSA device: | Run audio playback on 'playback_spdif' ALSA device: | ||
{{Info|'playback_spdif' is an alias defined in /etc/asound.conf, for S/PDIF output device.}} | {{Info|'playback_spdif' is an alias defined in /etc/asound.conf, for S/PDIF output device.}} | ||
{{Board$}} speaker-test -D playback_spdif - | {{Board$}} speaker-test -D playback_spdif --channels 2 --format S32_LE -f 440 -t sine -l 1 | ||
==== Playback via Pipewire ==== | |||
* ''' | * '''Configure Pipewire''' | ||
Change the sound card active profile, to S/PDIF 'iec958-stereo' profile. | Change the sound card active profile, to S/PDIF 'iec958-stereo' profile. | ||
{{Info|Example below is given for | {{Info|Example below is given for 'alsa_card.platform-sound' soundcard. Check available sound cards and associated output profiles with "''pactl list cards''" command.}} | ||
{{Board$}} | {{Board$}} pactl set-card-profile alsa_card.platform-sound output:iec958-stereo | ||
* '''Run audio playback:''' | |||
{{Board$}} speaker-test --channels 2 --format S32_LE -f 440 -t sine -l 1 | |||
<noinclude> | |||
{{PublicationRequestId | 10391 | 2019-01-21}} | |||
[[Category:How to run use cases]] | |||
[[Category:ALSA]] | |||
</noinclude> |
Revision as of 12:58, 13 June 2024
1. Article purpose[edit | edit source]
This article explains how to play audio through the ALSA audio framework in Linux® OS context. The examples below, show how to play audio on the different audio hardware interfaces of the STM32MPU boards.
2. Audio playback overview[edit | edit source]
The ALSA framework exposes audio devices associated to the board audio hardware interfaces.
The application audio streams are routed by default through the Pipewire[1] sound server. Pipewire exposes audio profiles, which are mapped on the ALSA sound card audio devices. The Pipewire server provides a command line interface to list audio profiles and to select one, in order to record from a specific audio interface.
Information |
In this article, the PulseAudio 'pactl' command is used in the examples. This is possible because the PipeWire sound server maintains backward compatibility with the former PulseAudio sound server through the pipewire-pulse package. |
The audio playback examples in following sections are given for ALSA utilities. However, the audio playbacks can be launched by other applications, such as gstreamer multimedia framework.
3. Examples[edit | edit source]
3.1. Audio playback on headset output[edit | edit source]
3.1.1. Playback on ALSA device[edit | edit source]
Run audio playback on 'playback_codec' ALSA device:
Information |
'playback_codec' is an alias defined in /etc/asound.conf, for headset output device. |
aplay -D playback_codec /usr/share/sounds/alsa/Front_Left.wav
3.1.2. Playback via Pipewire[edit | edit source]
- Configure Pipewire
Change the Pulseaudio active profile of the sound card, to 'analog-stereo' profile:
Information |
The Pulseaudio analog-stereo profile is the default profile. So next command is not required after boot. |
Information |
Example below is given for 'alsa_card.platform-sound' soundcard. Check available sound cards and associated output profiles with "pactl list cards" command. |
pactl set-card-profile alsa_card.platform-sound output:analog-stereo
- Run audio playback:
Information |
The Pipewire device is the default one, so "-D pipewire" option can be omitted in the playback command. |
aplay /usr/share/sounds/alsa/Front_Left.wav
3.2. Audio playback on HDMI output[edit | edit source]
3.2.1. Playback on ALSA device[edit | edit source]
Run audio playback on 'playback_hdmi' ALSA device:
Information |
'playback_hdmi' is an alias defined in /etc/asound.conf, for hdmi output device. |
aplay -D playback_hdmi /usr/share/sounds/alsa/Front_Left.wav
3.2.2. Playback via Pipewire[edit | edit source]
- Configure Pipewire
Change the Pulseaudio active profile of the sound card, to 'hdmi-stereo' profile:
Information |
Example below is given for 'alsa_card.platform-sound' soundcard. Check available sound cards and associated output profiles with "pactl list cards" command. |
pactl set-card-profile alsa_card.platform-sound output:hdmi-stereo
- Run audio playback:
aplay /usr/share/sounds/alsa/Front_Left.wav
3.3. Audio playback on S/PDIF output[edit | edit source]
Information |
S/PDIF ALSA device supports only 32-bit audio streams. As 32-bit wave files are not provided in sample sound files, speaker-test is used instead of aplay, for convenience, here. Speaker-test generates a 440Hz sine wave in following examples. |
3.3.1. Set IEC958 status bits[edit | edit source]
Information |
Example below is given for sound card index 0. Check sound card index with "aplay -l" command. |
Example: set IEC958 mode bit.
iecset -c 0 -n device=0 pro on
3.3.2. Playback on ALSA device[edit | edit source]
Run audio playback on 'playback_spdif' ALSA device:
Information |
'playback_spdif' is an alias defined in /etc/asound.conf, for S/PDIF output device. |
speaker-test -D playback_spdif --channels 2 --format S32_LE -f 440 -t sine -l 1
3.3.3. Playback via Pipewire[edit | edit source]
- Configure Pipewire
Change the sound card active profile, to S/PDIF 'iec958-stereo' profile.
Information |
Example below is given for 'alsa_card.platform-sound' soundcard. Check available sound cards and associated output profiles with "pactl list cards" command. |
pactl set-card-profile alsa_card.platform-sound output:iec958-stereo
- Run audio playback:
speaker-test --channels 2 --format S32_LE -f 440 -t sine -l 1