Thread
:
/dev/mixer on N900 ?
View Single Post
dannym
2010-08-29 , 17:35
Posts: 56 | Thanked: 31 times | Joined on Jul 2008 @ Austria
#
8
verrnum, Yes, "/dev/mixer" is the device the rest of the world uses for OpenSoundSystem audio on UNIX and UNIX-like systems.
However, because of licensing problems in the past (OSS went closed source for a time), Linux has developed its own audio subsystem called "Advanced Linux Sound Architecture" to replace it.
Nowadays, there's also a daemon called "pulseaudio" which does software mixing and per-application mixing etc.
Note that ALSA exposes some rather un-UNIXish API which everyone is supposed to use. One is not supposed to even open the device files (there are device files for ALSA, foo).
To understand the ALSA API, forget everything you thought you knew about UNIX device access and rather think about something like DirectSound or WinMM (I'm not a fan, but that's just how it is).
I think PulseAudio has an ALSA-lib interface, so when you use the ALSA libs to set something, you actually talk to PulseAudio.
Confused yet?
I've extracted the relevant bits of the Xfce4 mixer I wrote 7 years ago:
#include <alsa/asoundlib.h>
#include <alsa/mixer.h>
#include <alsa/control.h>
static char const* master_ids[MAX_MASTERS] = {
"Master",
"PCM",
"Analog Front",
"Speaker",
NULL,
};
static snd_mixer_t *handle = NULL;
static snd_mixer_elem_t *elem = NULL;
static char card[64] = "default";
snd_mixer_selem_id_t* master_selectors[MAX_MASTERS] = { NULL };
if ((err = snd_mixer_open(&handle, 0)) < 0 || !handle) {
printf("alsa: Mixer %s open error: %s\n", card, snd_strerror(err));
return;
}
if ((err = snd_mixer_attach(handle, card)) < 0) {
snd_mixer_close(handle);
return;
}
if ((err = snd_mixer_selem_register(handle, NULL, NULL)) < 0) {
printf("alsa: Mixer register error: %s\n", snd_strerror(err));
snd_mixer_close(handle);
return;
}
err = snd_mixer_load(handle);
if (err < 0) {
printf("alsa: Mixer load error: %s: %s\n", card, snd_strerror(err));
snd_mixer_close(handle);
handle = NULL;
return;
}
for (i = 0; elem == NULL && i < MAX_MASTERS && master_ids[i] != NULL; i++) {
snd_mixer_selem_id_alloca(&master_selectors[i]);
snd_mixer_selem_id_set_index(master_selectors[i], 0);
snd_mixer_selem_id_set_name(master_selectors[i], master_ids[i]);
elem = snd_mixer_find_selem(handle, master_selectors[i]);
if (elem != NULL) {
if (!snd_mixer_selem_has_common_volume(elem)
&& !snd_mixer_selem_has_playback_volume(elem)
) { /* no playback device */
elem = NULL;
}
}
snd_mixer_selem_set_playback_volume_all (elem, lval);
See for yourself at
http://archive.ubuntu.com/ubuntu/poo...97.orig.tar.gz
in file "lib/vc_alsa.c".
The platform part one is supposed to use on Maemo (I think) is http://www.gstreamer.net/data/doc/gstreamer/head/pwg/html/section-iface-mixer.html and it's used like this: https://launchpad.net/gmixer
P.S.: can someone please fix indentation in talk.maemo.org posts? Code samples are almost unreadable like this.
Last edited by dannym; 2010-08-29 at
17:46
.
Quote & Reply
|
dannym
View Public Profile
Send a private message to dannym
Find all posts by dannym