Skip to contentSkip to conversation

snd_pcm_set_params() bug?

DISCUSSION Christian Morales Vega 2 participants 3 messages Jun 2, 2008 – Jan 26, 2009

lore
Share & tools
lore
#0 lore raw

This code:

#include <alsa/asoundlib.h>

int main(){
    snd_pcm_t *handle;
    if(snd_pcm_open(&handle, "default:1", SND_PCM_STREAM_PLAYBACK, 0) < 0) {
      exit(1);
    }

    if(snd_pcm_set_params(handle, SND_PCM_FORMAT_S16_LE,
SND_PCM_ACCESS_RW_INTERLEAVED,
       2, 24000, 1, 100000) < 0) {
      exit(2);
    }
}

fails with error "ALSA lib pcm.c:7193:(snd_pcm_set_params) Unable to get period size for PLAYBACK: Invalid argument"
Disable resampling and you get "ALSA lib pcm.c:7142:(snd_pcm_set_params) Rate doesn't match (requested 24000Hz, get 0Hz)" (normal, I suppose). With other samplerates works fine.

I'm using alsa-driver-kmp-default-1.0.16.20080602 and alsa-1.0.16.hg20080510 RPM packages from multimedia:audio openSUSE Build Service repository (from Takashi Iwai) and an AD1988 (hda-intel) codec. A XUbuntu user also has the same problem with an hda-intel codec (that I suppose uses stable 1.0.16).
With a SB Live! in the same computer there are no problems.

This was discovered with bsnes ( http://byuu.cinnamonpirate.com/bsnes/
- http://board.zsnes.com/phpBB2/viewtopic.php?t=11584 ) that can use openal, libao or alsa directly. The problem just happens when using 24KHz with alsa. So I suppose the problem is in the snd_pcm_set_params() itself, since openal and libao have not the problem but they set parameters "manually", not with snd_pcm_set_params().

#1 lore raw

2008/6/2 Christian Morales Vega <[email protected]>:

Quoted 31 lines

This code:

#include <alsa/asoundlib.h>

int main(){
   snd_pcm_t *handle;
   if(snd_pcm_open(&handle, "default:1", SND_PCM_STREAM_PLAYBACK, 0) < 0) {
     exit(1);
   }

   if(snd_pcm_set_params(handle, SND_PCM_FORMAT_S16_LE,
SND_PCM_ACCESS_RW_INTERLEAVED,
      2, 24000, 1, 100000) < 0) {
     exit(2);

}
}

fails with error "ALSA lib pcm.c:7193:(snd_pcm_set_params) Unable to get period size for PLAYBACK: Invalid argument"
Disable resampling and you get "ALSA lib pcm.c:7142:(snd_pcm_set_params) Rate doesn't match (requested 24000Hz, get 0Hz)" (normal, I suppose). With other samplerates works fine.

I'm using alsa-driver-kmp-default-1.0.16.20080602 and alsa-1.0.16.hg20080510 RPM packages from multimedia:audio openSUSE Build Service repository (from Takashi Iwai) and an AD1988 (hda-intel) codec. A XUbuntu user also has the same problem with an hda-intel codec (that I suppose uses stable 1.0.16).
With a SB Live! in the same computer there are no problems.

Quoted 8 lines

This was discovered with bsnes ( http://byuu.cinnamonpirate.com/bsnes/
- http://board.zsnes.com/phpBB2/viewtopic.php?t=11584 ) that can use openal, libao or alsa directly. The problem just happens when using 24KHz with alsa. So I suppose the problem is in the snd_pcm_set_params() itself, since openal and libao have not the problem but they set parameters "manually", not with snd_pcm_set_params().

The problem persists with alsa-1.0.19.git20090122-1.1 and alsa-driver-kmp-default-1.0.19.20090124_2.6.27.7_9.1-1.1 from openSUSE 11.1 multimedia:audio(:kmp) Build Service repository.

Note that the problem only happens with snd_pcm_set_params(). Using snd_pcm_hw_params_set_* functions works fine (and I really get 24KHz):
http://board.zsnes.com/phpBB2/viewtopic.php?p=170478#170478

The problem happens with default, plughw and hw.

#2 lore raw

At Sat, 24 Jan 2009 11:53:14 +0100,

Quoted 42 lines · Cristian Morales Vega

2008/6/2 Christian Morales Vega <[email protected]>:

Quoted 31 lines

This code:

#include <alsa/asoundlib.h>

int main(){
   snd_pcm_t *handle;
   if(snd_pcm_open(&handle, "default:1", SND_PCM_STREAM_PLAYBACK, 0) < 0) {
     exit(1);
   }

   if(snd_pcm_set_params(handle, SND_PCM_FORMAT_S16_LE,
SND_PCM_ACCESS_RW_INTERLEAVED,
      2, 24000, 1, 100000) < 0) {
     exit(2);

}
}

fails with error "ALSA lib pcm.c:7193:(snd_pcm_set_params) Unable to get period size for PLAYBACK: Invalid argument"
Disable resampling and you get "ALSA lib pcm.c:7142:(snd_pcm_set_params) Rate doesn't match (requested 24000Hz, get 0Hz)" (normal, I suppose). With other samplerates works fine.

I'm using alsa-driver-kmp-default-1.0.16.20080602 and alsa-1.0.16.hg20080510 RPM packages from multimedia:audio openSUSE Build Service repository (from Takashi Iwai) and an AD1988 (hda-intel) codec. A XUbuntu user also has the same problem with an hda-intel codec (that I suppose uses stable 1.0.16).
With a SB Live! in the same computer there are no problems.

Quoted 8 lines

This was discovered with bsnes ( http://byuu.cinnamonpirate.com/bsnes/
- http://board.zsnes.com/phpBB2/viewtopic.php?t=11584 ) that can use openal, libao or alsa directly. The problem just happens when using 24KHz with alsa. So I suppose the problem is in the snd_pcm_set_params() itself, since openal and libao have not the problem but they set parameters "manually", not with snd_pcm_set_params().

Quoted 7 lines

The problem persists with alsa-1.0.19.git20090122-1.1 and alsa-driver-kmp-default-1.0.19.20090124_2.6.27.7_9.1-1.1 from openSUSE 11.1 multimedia:audio(:kmp) Build Service repository.

Note that the problem only happens with snd_pcm_set_params(). Using snd_pcm_hw_params_set_* functions works fine (and I really get 24KHz):
http://board.zsnes.com/phpBB2/viewtopic.php?p=170478#170478

Hm, snd_pcm_set_params() is basically nothing but the command sequences of snd_pcm_hw_params_*(). So, some call of them is broken...

Takashi