Skip to contentSkip to conversation

snd_pcm_wait strangeness when resampling

DISCUSSION Måns Rullgård 2 participants 4 messages Mar 11, 2004 – Mar 12, 2004

lore
Share & tools
lore
#0 lore raw

I've noticed some strange things with snd_pcm_wait. My application opens the sound device in non-blocking mode and uses snd_pcm_wait whenever snd_pcm_writei return EAGAIN. This works fine as long as ALSA isn't doing any resampling. However, when resampling (e.g. from 44.1 kHz to 48 kHz) snd_pcm_wait returns immediately, insisting that there is room in the buffer, after which snd_pcm_writei obviously returns EAGAIN once more. The same thing happens if I use OSS emulation and select() or poll(). Replacing the snd_pcm_wait call with usleep(10000) makes the CPU load look normal again, while the application still works.

I am using Linux 2.6.4, ALSA driver 1.0.3 and library 1.0.3a with a SIS7012 chip. It behaves the same way with kernel 2.6.3 and driver 1.0.2c. I'm not quite sure when it started.

This application used to work properly. Has something changed so I need to modify my application?

Signature · 9 lines
Måns Rullgård
[email protected]


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
#1 lore raw
Quoted 11 lines · M?ns Rullg?rd

I've noticed some strange things with snd_pcm_wait. My application opens the sound device in non-blocking mode and uses snd_pcm_wait whenever snd_pcm_writei return EAGAIN. This works fine as long as ALSA isn't doing any resampling. However, when resampling (e.g. from 44.1 kHz to 48 kHz) snd_pcm_wait returns immediately, insisting that there is room in the buffer, after which snd_pcm_writei obviously returns EAGAIN once more. The same thing happens if I use OSS emulation and select() or poll(). Replacing the snd_pcm_wait call with usleep(10000) makes the CPU load look normal again, while the application still works.

Quoted 6 lines

I am using Linux 2.6.4, ALSA driver 1.0.3 and library 1.0.3a with a SIS7012 chip. It behaves the same way with kernel 2.6.3 and driver 1.0.2c. I'm not quite sure when it started.

This application used to work properly. Has something changed so I need to modify my application?

Could you give me your code to analyze the problem?

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click

#2 lore raw
Quoted 13 lines · Jaroslav Kysela
Quoted 11 lines · M?ns Rullg?rd

I've noticed some strange things with snd_pcm_wait. My application opens the sound device in non-blocking mode and uses snd_pcm_wait whenever snd_pcm_writei return EAGAIN. This works fine as long as ALSA isn't doing any resampling. However, when resampling (e.g. from 44.1 kHz to 48 kHz) snd_pcm_wait returns immediately, insisting that there is room in the buffer, after which snd_pcm_writei obviously returns EAGAIN once more. The same thing happens if I use OSS emulation and select() or poll(). Replacing the snd_pcm_wait call with usleep(10000) makes the CPU load look normal again, while the application still works.

Quoted 8 lines
Quoted 6 lines

I am using Linux 2.6.4, ALSA driver 1.0.3 and library 1.0.3a with a SIS7012 chip. It behaves the same way with kernel 2.6.3 and driver 1.0.2c. I'm not quite sure when it started.

This application used to work properly. Has something changed so I need to modify my application?

Could you give me your code to analyze the problem?

The full code is in http://tcvp.sf.net/tcvp-snapshot.tar.gz, if you feel like digging through 20k lines of code.

The ALSA part is in here:
http://tcvp.bkbits.net:8080/tcvp/anno/src/output/drivers/alsa/alsa.c%401.9

It is called from here:
http://tcvp.bkbits.net:8080/tcvp/anno/src/output/audio/audio.c%401.13
in the audio_play function

Signature · 9 lines
Måns Rullgård
[email protected]


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
#3 lore raw
In reply to Jaroslav Kysela
Quoted 13 lines · Jaroslav Kysela
Quoted 11 lines · M?ns Rullg?rd

I've noticed some strange things with snd_pcm_wait. My application opens the sound device in non-blocking mode and uses snd_pcm_wait whenever snd_pcm_writei return EAGAIN. This works fine as long as ALSA isn't doing any resampling. However, when resampling (e.g. from 44.1 kHz to 48 kHz) snd_pcm_wait returns immediately, insisting that there is room in the buffer, after which snd_pcm_writei obviously returns EAGAIN once more. The same thing happens if I use OSS emulation and select() or poll(). Replacing the snd_pcm_wait call with usleep(10000) makes the CPU load look normal again, while the application still works.

Quoted 8 lines
Quoted 6 lines

I am using Linux 2.6.4, ALSA driver 1.0.3 and library 1.0.3a with a SIS7012 chip. It behaves the same way with kernel 2.6.3 and driver 1.0.2c. I'm not quite sure when it started.

This application used to work properly. Has something changed so I need to modify my application?

Could you give me your code to analyze the problem?

I've noticed that it works properly using alsa-lib 1.0.0rc2. That's what I happened to have compiled, it might work with later versions too.

Did you manage to build the thing yet?

Signature · 9 lines
Måns Rullgård
[email protected]


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click