Skip to contentSkip to conversation

How to open a device using ALSA API

DISCUSSION Guild Jackson 3 participants 3 messages Jul 2, 2004

lore
Share & tools
lore
#0 lore raw

Hi all

I am quite new using the ALSA sound API and have been trying to open the sound card with the following function:
#define AUDIO_DEVICE "/dev/dsp"

if ((err = snd_pcm_open (&capture_handle,
AUDIO_DEVICE, SND_PCM_STREAM_CAPTURE, 0)) < 0) {
fprintf (stderr, "cannot open audio device %s
(%s)\n",

				 argv[1],
				 snd_strerror (err));
			exit (1);
		}

But I´ve got the following problem when running it:

$ ./captureAlsa
ALSA lib pcm.c:1972:(snd_pcm_open_noupdate) Unknown
PCM /dev/dsp
cannot open audio device (null) (No such file or
directory)

I think I am not configuring correctly the audio device
card.
Does anyone know how to configure properly the parameters to open correctly the sound card? I´ve seen something about it in ecasound-2.3.3 aplication that uses the ALSA driver but all I have found was:

err = snd_pcm_open(&audio_fd_repp,

			 (char*)device_name.c_str(),
			 pcm_stream_rep,
			 SND_PCM_NONBLOCK);

I tried to figure out what is the device_name.c_str() but I can´t find this function in the ecasound cpp files.
Does anyone have a simple example that shows how to open the sound card with ALSA?

Thanks in advance and best regards

Guild

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#1 lore raw
Quoted 6 lines · Guild Jackson

Hi all

I am quite new using the ALSA sound API and have been trying to open the sound card with the following function:
#define AUDIO_DEVICE "/dev/dsp"

Use:

#define AUDIO_DEVICE "default"

Jaroslav

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

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#2 lore raw
In reply to Guild Jackson
Quoted 1 line

#define AUDIO_DEVICE "/dev/dsp"

/dev/dsp and friends belong to the old OSS device drivers. try to forget about them.

Quoted 6 lines

err = snd_pcm_open(&audio_fd_repp,

			 (char*)device_name.c_str(),
			 pcm_stream_rep,
			 SND_PCM_NONBLOCK);

I tried to figure out what is the device_name.c_str()

its the name of an ALSA device defined in either a system-wide or per-user configuration file. typical system wide names:

hw:0 = the first audio interface, accessed with only
the hw-supported capabilities of the device
plughw:0 = the first audio interface, accessible with
more or less any parameters you request

hw:1 = the second audio interface

there are many others. see asound.conf (use locate(1) to find it on your system) and/or ~/.asoundrc.

btw: your program should *never* code the device name to be used. it should always be left to the user to specify, and use "default" if they do not specify anything.

--p

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com