Audio pcm error

Hi All,

I have created an application using audioService.le_audio in Legato to play audio from a file. However, sometimes after waking up from system suspend mode, I encounter the following error:

Legato: =ERR= | audioDaemon[2958]/alsa_intf T=main | pa_pcm_alsa.c InitPcmPlaybackCapture() 471 | PCM is not ready (pcm error: )
Legato: =ERR= | audioDaemon[2958]/audio T=main | le_media.c le_media_PlaySamples() 1919 | PCM cannot be open
Legato: =ERR= | audioDaemon[2958] | cannot open device '/dev/snd/pcmC0D0p', errno 16

When I get this error, the sound file does not play. When I check with ‘fuser’ for ‘/dev/snd/pcmC0D0p’, I see that it is in use. Manually restarting the app with ‘audioService’ resolves the issue. Why is this happening, and how can I fix it in source code?

then which program is using the device ‘/dev/snd/pcmC0D0p’?

Do you see problem when using aplay to play the audio file?

I can hear the audio after typing the following commands in WP76 FW R16.0.1:

amix 'PRI_RX Audio Mixer MultiMedia1' 1
amix 'Sys Clock Enable Switch' 1
amix 'Capture PGA Mute Switch' 1
amix 'Digital Playback Mute Switch' 1
amix 'Digital Playback Volume' 192
amix 'Speaker Playback Volume' 57
amix 'Speaker Playback Mute Switch' 1
amix 'SPKOUTP VDD Enable Switch' 1
amix 'SPKOUTN VDD Enable Switch' 1
amix 'SPKOUTP Mute Switch' 1
amix 'SPKOUTN Mute Switch' 1
amix 'SPKOUTP Enable Switch' 1
amix 'SPKOUTN Enable Switch' 1
amix 'ADC Mute All Switch' 1
amix 'Speaker Function' 1
amix 'SPKOUTP Mixer Speak PGA to Speaker P Switch' 1
amix 'SPKOUTN Mixer Speak PGA to Speaker N Switch' 1
amix 'Speaker Mixer DAC to Speak PGA Switch' 1
amix 'MultiMedia1 Mixer PRI_TX' 1
amix 'Input PGA Enable Switch' 1
amix 'Left ADC Enable Switch' 1
amix 'Input PGA AUX to Invert InPGA Switch' 1
amix 'Input PGA IN1 to InPGA Switch' 1
amix 'PRI_MI2S_RX Audio Mixer MultiMedia1' 1
aplay 0-to-9_8k.wav

It is being used by audioDaemon. I am able to play the audio file. However, sometimes I encounter this error. If I don’t fix it, the audio file won’t play.

Legato: =ERR= | audioDaemon[2958]/alsa_intf T=main | pa_pcm_alsa.c InitPcmPlaybackCapture() 471 | PCM is not ready (pcm error: )
Legato: =ERR= | audioDaemon[2958]/audio T=main | le_media.c le_media_PlaySamples() 1919 | PCM cannot be open
Legato: =ERR= | audioDaemon[2958] | cannot open device '/dev/snd/pcmC0D0p', errno 16

This error repeats every time I play an audio file because the /dev/snd/pcmC0D0p is busy or already opened.

Before device suspends, are you playing the audio file?

Btw, how do you perform the system suspend mode?

I am not yet familiar with how the system goes into suspend. However, I believe it does not enter suspend mode before the audio file finishes. I think this situation occurs when the system wakes up.

to double confirm if this is related to suspend mode, you can enter the following to keep module waking up
echo NO_SLEEP > /sys/power/wake_lock

Okay, I will try this. In the meantime, I am leaving a log for the entire process. The error repeats after this point. The starting point is ‘Cannot set hw params’.

root@swi-mdm9x28-wp:~# logread -f | grep pcm
Nov 29 08:46:25  user.info Legato:  INFO | AppExe[2907] | The device /dev/snd/pcmC0D0p is not in use.
Nov 29 08:56:25  user.info Legato:  INFO | AppExe[2907] | The device /dev/snd/pcmC0D0p is not in use.
Nov 29 08:56:25  user.err Legato: =ERR= | audioDaemon[2935]/alsa_intf T=main | pa_pcm_alsa.c SetPcmParamsPlayback() 162 | Cannot set hw params
Nov 29 08:56:25  user.err Legato: =ERR= | audioDaemon[2935]/alsa_intf T=main | pa_pcm_alsa.c InitPcmPlaybackCapture() 464 | Failed in set_params
Nov 29 08:57:25  user.info Legato:  INFO | AppExe[2907] | The device /dev/snd/pcmC0D0p is in use. PID: 2935 
Nov 29 08:57:26  user.err Legato: =ERR= | audioDaemon[2935]/alsa_intf T=main | pa_pcm_alsa.c InitPcmPlaybackCapture() 471 | PCM is not ready (pcm error: )
Nov 29 08:57:26  user.err Legato: =ERR= | audioDaemon[2935] | cannot open device '/dev/snd/pcmC0D0p', errno 16
Nov 29 08:57:42  user.info Legato:  INFO | AppExe[2907] | The device /dev/snd/pcmC0D0p is in use. PID: 2935 
Nov 29 08:57:43  user.err Legato: =ERR= | audioDaemon[2935]/alsa_intf T=main | pa_pcm_alsa.c InitPcmPlaybackCapture() 471 | PCM is not ready (pcm error: )
Nov 29 08:57:43  user.err Legato: =ERR= | audioDaemon[2935] | cannot open device '/dev/snd/pcmC0D0p', errno 16

and

root@swi-mdm9x28-wp:~# fuser /dev/snd/pcmC0D0p
2935 
root@swi-mdm9x28-wp:~# ps aux | grep 2935
root      2935  0.0  1.7  69384  2828 ?        Sl   Nov28   0:18 audioDaemon
root     11015  0.0  0.3   2388   576 pts/2    S+   09:06   0:00 grep 2935

The audio will not play from now on.

how to reproduce the issue on WP76 module?

Audio connections (le_audio_CreateConnector, le_audio_OpenPlayer and le_audio_OpenSpeaker) are established, and then the file starts playing. After the audio playback is finished, all audio connections are closed, and it goes into suspend mode. When i want to play again, these connections are re-established, the file plays, connections are closed again, and it goes into suspend mode. This process repeats.

i think you need to first confirm whether this is related to suspend mode and whether this is related to legato application

This situation is most likely related to the suspend mode. In this case, what should I do?

you can try “app restart audioService” before you run the application to play audio

If I do this within the code, the application stops. The application uses the le_audio API, and stopping it because of using it. How can I release this pcm? Also, The main reason is ‘Cannot set hw params’. I need to solve this issue without stop App.

i guess probably this is because some audio close routine has not been run completely.
You might need to keep module wake up before closing audio routine.

Another workaround is that you can start a new unsandboxed application to specifically do audio play.
Then there is no problem to restart this standalone application.
When you need to play audio, you can “app restart audioService”, and then use script to call this standalone application to play audio

Thanks for the suggestions. How can I ensure that the audio close routine has completed?

You might need to diff legato trace in ok case and nok case

In my opinion, using dedicated application to play audio file is easier for you as you can restart audioservice before playing audio