[pulseaudio-discuss] pcm_params.c:2351: sndrv_pcm_hw_params: Assertion `err >= 0' failed. when Pulse (via ALSA) called from C

Nick Thompson rextanka at comcast.net
Thu Apr 24 12:09:46 PDT 2008


Hi all,

This is my first post here, and I'm new to Pulse and ALSA and  
linux :)  So I hope this is not a total noob question.

I'm having some issues interfacing interfacing an C based alsa program  
through pulse.  I'm using a multi output device setup with an HDA  
based RealTek ALC 883 audio codec on my MLB (an Asus P5K) and a USB  
Audio Device 1.0 spec compliant USB device (a Lexicon Alpha).

I can stream directly to either the USB device or to the HDA device  
via ALSA, same with my pulse config.  But when I try to open the deive  
programatically, it fails.

My assertion that the pulse/ALSA setup is "good" in that aplay will  
play fine through my pulse/ALSA pcms, but when I  open the device in a  
C program, I get a failure which causes my program to coredump.

nick at nick-desktop:~/src/simple-alsa$ !.
./a.out
a.out: pcm_params.c:2351: sndrv_pcm_hw_params: Assertion `err >= 0'  
failed.
Aborted (core dumped)

Here are both the ALSA and Pulse config files:

~/.pulse/config.pa

--- cut here ---
# configuration file for PulseAudio.
#
# We want to use multiple hardware output devices with pulse so
# define how the connections will be made in the library

# define sinks, this is effectively an output device.

load-module module-alsa-sink device=usbLexiconAlpha sink_name=usbAudio
load-module module-alsa-sink device=intelHDA  sink_name=hdaAudio


load-module module-alsa-source device=hw:0
#load-module module-alsa-sink device=hw:0
load-module module-native-protocol-unix
--- end cut here ---

~/.asoundrc

--- cut here ---
# ALSA config file to use pulse

# set up definitions for pulse (tells ALSA that if -D pulse is used,
# then use the pulse plug in)

pcm.pulse {
    type pulse
}

ctl.pulse {
    type pulse
}

# tell ALSA to use pulse.  If you do this you have to make sure that
# the pulse daemon is started before unsing any applications, other
# wise attemps to use audia via ALSA will fail.

pcm.!default {
    type pulse
}

ctl.!default {
    type pulse
}



pcm.intelHDA {
        type hw
        card 0
        device 0
}

pcm.usbLexiconAlpha {
        type hw
        card 1
        device 0
}

ctl.intelHDA {
        card 0
        device 0
}

ctl.usbLexiconAlpha {
        card 1
        device 0
}

# set up multiple pulse device definitions, in this case one per
# device to allow simultanious streaming to multiple devices

pcm.pulseHDA {
        type pulse
        device hdaAudio
}

pcm.pulseUSB {
        type pulse
        device usbAudio
}

# control for the devices described above
#
ctl.pulseHDA {
        type pulse
        device hdaAudio
}

ctl.pulseUSB {
        type pulse
        device usbAudio
}
--- end cut here ---

to play through pulse to either of the devices I use

nick at nick-desktop:~$ aplay -D pulseHDA ~/1KHz.wav
Playing WAVE '/home/nick/1KHz.wav' : Signed 16 bit Little Endian, Rate  
44100 Hz, Stereo

And this will play the 1k tone.  Similarly using pulseHDA works great  
too.

But... if I (in a c program) try to open either of these then I get  
the coredump failure.  Here's the code I'm using:

    snd_pcm_hw_params_t *hwparams ;     // hardware info
    char                *pcm_name ;     // name of the pcm device
    snd_pcm_stream_t    stream = SND_PCM_STREAM_PLAYBACK ;      //  
playback stream

    pcm_name = strdup("pulseUSB");

    snd_pcm_hw_params_alloca(&hwparams);

    if (snd_pcm_open(&pcm_handle, pcm_name, stream, 0) < 0) {
        fprintf(stderr, "Error opening PCM device %s\n", pcm_name);
        return(-1) ;
    }

The same block of code using plughw:1,0 for the usb device in the  
strdup, or plughw:0,0, or intelHDA, or usbLexiconAlpha (when  
pulseaudio daemon is not started) works.

Can anyone see what is wrong with my config to cause this error to  
happen?

Thanks!!

Nick



More information about the pulseaudio-discuss mailing list