libasound dies on snd_pcm_open
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi!
Hope, this isn't a too stupid question...
I've got a problem whilst trying to port my application to the ALSA API.
Following piece of code gives me an error when executed:
- ----------
if ((rc = snd_pcm_open (&capture_handle, sDevice.ascii(),
SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK)) < 0) {
std::cerr << "cannot open audio device" << sDevice << snd_strerror (rc);
return rc;
}Definitions:
QString sDevice;snd_pcm_t *capture_handle;
- ----------
Stopped due to library event.
The stack trace gives me the following:
=========================================================0x4000a760 in _dl_debug_state () from /lib/ld-linux.so.2 0x4099deb2 in _dl_open_worker () from /lib/libc.so.60x40009f96 in _dl_catch_error () from /lib/ld-linux.so.2 0x40e9elf5 in _dl_open () from /llb/lilic.so.6
0x404a4et9 in dlopen_doit () from /lib/libdl.so.2
0x4000ffl6 in _dl_catch_error () from /iib/Id-linux,so.2 0x404a52f4 in _dlerror_run () from /lib/libdl.so.20x404a4f44 in dlopen@@GLIBC_2.1 () from /lib/libdl.so.2 0x400496cd in snd_dlopen () from /usr/lib/libasound.so.2 0x40043764 in snd_config_hooks_call () from /usr/lib/libasound.so.2 0x400439d6 in snd_contig_hooks () from lusr/lib/libasound.so.2 0x40044387 in snd_config_update_r () from /usr/lib/libasound.so.2 0x40044918 in snd_config_update () from /usr/lib/libasound.so.2 0x4005d16d in snd_pcm_open() from /usr/lib/libasound.so.2 0x08056505 in KCorrView::openALSADevice() (this=Ox80e5f1 0) at kconview.cpp:5790x0805585c in KCorrView::openDevice () (this=Ox6095f1 0) at kcorrview.cpp:334 0x080564c9 in KCoaView::resume () (thls=Ox80e5f1 0) at kcorrview.cpp:571 0x0805a301 in KCorrMeter (this=Ox80d1328, parent=Ox0, name--0x0) at kcorrmeter.cpp:390x0805abec in main (argc=l, argv=Oxbfff1414) at main.cpp:49 0x40dbf4a2 in __libc_start_main () from /lib/libc.so.6
=========================================================
(SuSE 8.1, kernel 2.4.19, alsa 0.9 rc7)
I don't really know where to start looking.
Even more strange, it was working but failed later with a broken pipe
- --------------------------------------------------------- long rc = snd_pcm_readi (capture_handle, sBuf, 128);
- --------------------------------------------------------- And I havn't touched the openALSADevice(), honestly!
Any pointers welcome.
Cheers,
Meinhard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE+SWFpv2LRaMHePXMRAgRiAKCAbxpz4QjHBIpxboreEgddJhR/qACg6cPX GjMDuYFio5VXtgkQKB/jMF8=
=ALyd
-----END PGP SIGNATURE-----
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld =Something 2 See!
http://www.vasoftware.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi again,
Quoted 2 lines · M. Ritscher
Stopped due to shared library event.
I've now compiled a version of libasound with debug enabled and found out that it dies on me on line 61 of dlmisc.c
Stopped due to shared library event.
===========================
void *snd_dlopen(const char *name, int mode)
{
<cut>
###>>> return dlopen(name, mode);
}
============================
name: "/usr/lib/libasound.so.2 (which correctly links to libasound.so.2.0.0)
mode: 2
I've played around with my code a bit and have tried to reduce it to a minimum, still, no luck.
============================================
int KCorrView::openNewALSADev(){
snd_pcm_t *capture_hd;
int err = 0;
if ((err = snd_pcm_open(&capture_hd,
"hwplug:0,0", SND_PCM_STREAM_CAPTURE, 0)) < 0) { return err;
}
return err;
}
============================================
Am I missing the obvious?
Any help really appreciated.
Thanks,
Meinhard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE+Sojjv2LRaMHePXMRAmGiAJ99ACyZBFcUXIJogUObV2ZxJkH2/gCeMqIu MuESBrYRINM20GAoMx2CMH0=
=XHOX
-----END PGP SIGNATURE-----
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld =Something 2 See!
http://www.vasoftware.com
At Wed, 12 Feb 2003 18:48:12 +0100,
Quoted 31 lines · M. Ritscher
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Hi again,
Quoted 2 lines · M. Ritscher
Stopped due to shared library event.
I've now compiled a version of libasound with debug enabled and found out that it dies on me on line 61 of
dlmisc.c
Stopped due to shared library event.===========================
void *snd_dlopen(const char *name, int mode)
{
<cut>
###>>> returndlopen(name, mode);
}
============================name: "
/usr/lib/libasound.so.2(which correctly links to libasound.so.2.0.0)
mode: 2I've played around with my code a bit and have tried to reduce it to a minimum, still, no luck.
============================================
int KCorrView::openNewALSADev(){
snd_pcm_t*capture_hd;
int err = 0;
Quoted 2 lines
if ((err = snd_pcm_open(&capture_hd,
"hwplug:0,0", SND_PCM_STREAM_CAPTURE, 0)) < 0) {
^^^^^^
is this correct? not "plughw:0,0" ?
Takashi
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
Quoted 5 lines · Takashi Iwai
Quoted 2 lines
if ((err = snd_pcm_open(&capture_hd,
"hwplug:0,0", SND_PCM_STREAM_CAPTURE, 0)) < 0) {^^^^^^is this correct? not "plughw:0,0" ?
Well, sorry, "plughw:0,0" of course. Doesn't change anything though.
Meinhard
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Hi again,
seems I was following a red herring. My debugger mislead me. The function 'snd_pcm_open()' isn't the culprit, it really dies here:
==========================
int rc = 0;
int exactRate
= snd_pcm_hw_params_set_rate_near (capture_handle, hw_params,
&uSampleRate, &rc);
if(rc != 0) {==========================
With the following definitions, declarations:
unsigned int uSampleRate - value 16100;snd_pcm_t *capture_handle;snd_pcm_hw_params_t *hw_params;
//ALSA library
#define ALSA_PCM_NEW_HW_PARAMS_API
#include <alsa/asoundlib.h>
It never returns from the call to "snd_pcm_hw_params_set_rate_near" and the cpu is maxing out.
What I'm doing wrong? I'm really clueless now.
You can see from the attached text file what I've been trying...
Any help really appreciated.
Thanks,
Meinhard
Quoted 1 line
int KCorrView::openALSADevice(){
int rc = 0;
snd_pcm_hw_params_t *hw_params;
const char *cTemp = 0;
//snd_pcm_access_t access = ;
cTemp = sDevice.ascii();
std::cerr << sDevice << std::endl;
if ((rc = snd_pcm_open (&capture_handle, sDevice.ascii(),
SND_PCM_STREAM_CAPTURE, 0)) < 0) {
std::cerr << "cannot open audio device" << sDevice << snd_strerror (rc);
return rc;
}
/* if ((rc = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
std::cerr << "cannot allocate hardware parameter structure" << snd_strerror (rc);
return rc;
} */
snd_pcm_hw_params_alloca (&hw_params);
if ((rc = snd_pcm_hw_params_any (capture_handle, hw_params)) < 0) {
std::cerr << "cannot initialize hardware parameter structure" << snd_strerror (rc);
return rc;
}
if ((rc = snd_pcm_hw_params_set_access (capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
// cerr << "cannot set access type" << snd_strerror (rc);
return rc;
}
if ((rc = snd_pcm_hw_params_set_format (capture_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
std::cerr << "cannot set sample format " << snd_strerror (rc);
return rc;
}
if ((rc = snd_pcm_hw_params_set_channels(capture_handle, hw_params, 2)) < 0) {
std::cerr << "Could not set to stereo" << snd_strerror(rc) << std::endl;
return rc;
}/* int exactRate
= snd_pcm_hw_params_set_rate_near (capture_handle, hw_params, &uSampleRate, &rc);
if(rc != 0) {
std::cerr << "Sample rate " << uSampleRate << "is'nt supported by your hardware. Using "
<< exactRate << "Hz instaed. " << std::endl;
}
std::cout << "snd_pcm_hw_params_set_rate_near returned with: " << exactRate << std::endl;
*/
unsigned int rrate = uSampleRate;
if((rc = snd_pcm_hw_params_set_rate_near (capture_handle, hw_params, &rrate, 0)) < 0){
std::cerr << "Failed to set sample rate: "<< uSampleRate << snd_strerror (rc);
}
if(rrate != uSampleRate) {
std::cerr << "Sample rate " << uSampleRate << "is'nt supported by your hardware. Using "
<< rrate << "Hz instaed. " << std::endl;
}
std::cout << "snd_pcm_hw_params_set_rate_near returned with: " << rc << std::endl;
if ((rc = snd_pcm_hw_params_set_channels (capture_handle, hw_params, 2)) < 0) {
std::cerr << "cannot set channel count " << snd_strerror (rc);
return rc;
}
if ((rc = snd_pcm_hw_params (capture_handle, hw_params)) < 0) {
std::cerr << "cannot set parameters " << snd_strerror (rc);
return rc;
}
snd_pcm_hw_params_free (hw_params);
if ((rc = snd_pcm_prepare (capture_handle)) < 0) {
std::cerr << "cannot prepare audio interface for use " << snd_strerror (rc);
return rc;
} std::cout << "successfully set up ALSA 0.9 device" << std::endl;
char buf[512]; long a;
if ((a = snd_pcm_readi (capture_handle, buf, 128)) < 0) {
std::cerr << "read from audio interface failed: " << snd_strerror (a) << std::endl;
return -1;
}
/*
for(int i=0; i <128; i++){
std::cout << buf[i];
}
std::cout << " " << std::endl;
*/
return rc;
}Quoted 4 lines · M. Ritscher
Hi again,
seems I was following a red herring. My debugger mislead me. The function '
snd_pcm_open()' isn't the culprit, it really dies here:
Before we start any debugging - are you using the alsa-lib from CVS? I've fixed some problems which may relate to your report a few days ago.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
This SF.NET email is sponsored by: FREE SSL Guide from Thawte are you planning your Web Server Security? Click here to get a FREE Thawte SSL guide and find the answers to all your SSL security issues.
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en
Hi Jaroslav,
Quoted 3 lines
Before we start any debugging - are you using the alsa-lib from CVS? I've fixed some problems which may relate to your report a few days ago.
No, I'm using 0.9rc7. Seems I have to make myself familiar with using the CVS version than.
Cheer,
Meinhard
Signature · 10 lines
+++ GMX - Mail, Messaging & more http://www.gmx.net +++ Bitte lächeln! Fotogalerie online mit GMX ohne eigene Homepage! ------------------------------------------------------- This SF.NET email is sponsored by: FREE SSL Guide from Thawte are you planning your Web Server Security? Click here to get a FREE Thawte SSL guide and find the answers to all your SSL security issues. http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en
Quoted 1 line · Jaroslav Kysela
are you using the alsa-lib from CVS?
Thanks Jaroslav, that fixed the problem. At least the one with the library. Now I can start debugging my own code...
Cheers,
Meinhard
-------------------------------------------------------
This SF.NET email is sponsored by: FREE SSL Guide from Thawte are you planning your Web Server Security? Click here to get a FREE Thawte SSL guide and find the answers to all your SSL security issues.
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en