├── po ├── LINGUAS ├── POTFILES.in └── Makevars ├── m4 └── Makefile.am ├── seq ├── Makefile.am ├── aseqdump │ ├── Makefile.am │ └── aseqdump.1 ├── aplaymidi │ ├── Makefile.am │ ├── aplaymidi.1 │ └── arecordmidi.1 ├── aconnect │ ├── Makefile.am │ ├── README.aconnect │ └── aconnect.1 └── aseqnet │ ├── Makefile.am │ ├── README.aseqnet │ └── aseqnet.1 ├── include ├── gettext_curses.h ├── gettext.h └── Makefile.am ├── alsaconf ├── alsaconf.fr.8 ├── Makefile.am ├── po │ └── Makefile.in └── alsaconf.8 ├── alsactl ├── .gitignore ├── init │ ├── Makefile.am │ ├── help │ ├── info │ ├── ca0106 │ ├── hda │ └── 00main ├── 90-alsa-restore.rules.in ├── alsa-state.service.in ├── alsa-restore.service.in ├── init_sysdeps.c ├── Makefile.am ├── alsactl.h ├── lock.c ├── monitor.c ├── init_utils_string.c ├── utils.c ├── init_sysfs.c └── alsactl.1 ├── speaker-test ├── samples │ ├── Noise.wav │ ├── Front_Left.wav │ ├── Rear_Left.wav │ ├── Rear_Right.wav │ ├── Side_Left.wav │ ├── Side_Right.wav │ ├── Front_Center.wav │ ├── Front_Right.wav │ ├── Rear_Center.wav │ ├── sample_map.csv │ └── Makefile.am ├── Makefile.am ├── readme.txt ├── pink.h ├── pink.c └── speaker-test.1 ├── utils ├── Makefile.am ├── buildrpm └── alsa-utils.spec.in ├── alsa-info ├── Makefile.am └── alsa-info.sh.1 ├── amidi ├── Makefile.am └── amidi.1 ├── alsamixer ├── proc_files.h ├── device_name.h ├── card_select.h ├── die.h ├── mainloop.h ├── mixer_display.h ├── mem.h ├── utils.h ├── textbox.h ├── go ├── volume_mapping.h ├── Makefile.am ├── widget.h ├── colors.h ├── mixer_widget.h ├── mixer_controls.h ├── die.c ├── mem.c ├── utils.c ├── widget.c ├── mainloop.c ├── colors.c ├── cli.c ├── proc_files.c ├── device_name.c ├── volume_mapping.c └── card_select.c ├── alsaucm ├── go.sh └── Makefile.am ├── TODO ├── topology ├── Makefile.am └── topology.c ├── iecset ├── Makefile.am └── iecset.1 ├── amixer ├── Makefile.am ├── go ├── amixer.h └── amixer.1 ├── alsaloop ├── Makefile.am ├── test.sh ├── effect-sweep.c └── alsaloop.1 ├── acinclude.m4 ├── README.md ├── bat ├── analyze.h ├── Makefile.am ├── alsa.h ├── latencytest.h ├── tinyalsa.h ├── convert.h ├── bat-signal.h ├── convert.c ├── alsabat-test.sh ├── signal.c └── alsabat.1 ├── aplay ├── Makefile.am └── formats.h ├── gitcompile ├── README ├── .gitignore ├── ChangeLog ├── Makefile.am └── INSTALL /po/LINGUAS: -------------------------------------------------------------------------------- 1 | de fr ja 2 | -------------------------------------------------------------------------------- /m4/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = gettext.m4 2 | -------------------------------------------------------------------------------- /seq/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS=aconnect aplaymidi aseqdump aseqnet 2 | -------------------------------------------------------------------------------- /include/gettext_curses.h: -------------------------------------------------------------------------------- 1 | #define USES_CURSES 2 | #include "gettext.h" 3 | -------------------------------------------------------------------------------- /alsaconf/alsaconf.fr.8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/bat/master/alsaconf/alsaconf.fr.8 -------------------------------------------------------------------------------- /alsactl/.gitignore: -------------------------------------------------------------------------------- 1 | alsa-store.service 2 | alsa-restore.service 3 | 90-alsa-restore.rules 4 | -------------------------------------------------------------------------------- /speaker-test/samples/Noise.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/bat/master/speaker-test/samples/Noise.wav -------------------------------------------------------------------------------- /speaker-test/samples/Front_Left.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/bat/master/speaker-test/samples/Front_Left.wav -------------------------------------------------------------------------------- /speaker-test/samples/Rear_Left.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/bat/master/speaker-test/samples/Rear_Left.wav -------------------------------------------------------------------------------- /speaker-test/samples/Rear_Right.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/bat/master/speaker-test/samples/Rear_Right.wav -------------------------------------------------------------------------------- /speaker-test/samples/Side_Left.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/bat/master/speaker-test/samples/Side_Left.wav -------------------------------------------------------------------------------- /speaker-test/samples/Side_Right.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/bat/master/speaker-test/samples/Side_Right.wav -------------------------------------------------------------------------------- /speaker-test/samples/Front_Center.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/bat/master/speaker-test/samples/Front_Center.wav -------------------------------------------------------------------------------- /speaker-test/samples/Front_Right.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/bat/master/speaker-test/samples/Front_Right.wav -------------------------------------------------------------------------------- /speaker-test/samples/Rear_Center.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/bat/master/speaker-test/samples/Rear_Center.wav -------------------------------------------------------------------------------- /utils/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = buildrpm 2 | 3 | rpm: buildrpm alsa-lib.spec 4 | VERSION=$(VERSION) $(srcdir)/buildrpm 5 | -------------------------------------------------------------------------------- /alsa-info/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = alsa-info.sh alsa-info.sh.1 2 | sbin_SCRIPTS = alsa-info.sh 3 | man_MANS = alsa-info.sh.1 4 | -------------------------------------------------------------------------------- /amidi/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/include 2 | EXTRA_DIST = amidi.1 3 | 4 | bin_PROGRAMS = amidi 5 | man_MANS = amidi.1 6 | -------------------------------------------------------------------------------- /alsamixer/proc_files.h: -------------------------------------------------------------------------------- 1 | #ifndef PROC_FILES_H_INCLUDED 2 | #define PROC_FILES_H_INCLUDED 3 | 4 | void create_proc_files_list(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /seq/aseqdump/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/include 2 | EXTRA_DIST = aseqdump.1 3 | 4 | bin_PROGRAMS = aseqdump 5 | man_MANS = aseqdump.1 6 | -------------------------------------------------------------------------------- /speaker-test/samples/sample_map.csv: -------------------------------------------------------------------------------- 1 | 0, "Front Left", "/usr/share/alsa/samples/Front_Left.wav" 2 | 1, "Front Right", "/usr/share/alsa/samples/Front_Right.wav" 3 | -------------------------------------------------------------------------------- /alsamixer/device_name.h: -------------------------------------------------------------------------------- 1 | #ifndef DEVICE_NAME_FORM_H_INCLUDED 2 | #define DEVICE_NAME_FORM_H_INCLUDED 3 | 4 | void create_device_name_form(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /alsamixer/card_select.h: -------------------------------------------------------------------------------- 1 | #ifndef CARD_SELECT_H_INCLUDED 2 | #define CARD_SELECT_H_INCLUDED 3 | 4 | void create_card_select_list(void); 5 | void close_card_select_list(void); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /seq/aplaymidi/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/include 2 | EXTRA_DIST = aplaymidi.1 arecordmidi.1 3 | 4 | bin_PROGRAMS = aplaymidi arecordmidi 5 | man_MANS = aplaymidi.1 arecordmidi.1 6 | -------------------------------------------------------------------------------- /alsaucm/go.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #GDB="gdb --args" 4 | 5 | ALSA_CONFIG_UCM="$HOME/alsa/alsa-lib/test/ucm" \ 6 | LD_PRELOAD="$HOME/alsa/alsa-lib/src/.libs/libasound.so" \ 7 | $GDB ./alsaucm "$@" 8 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | H add options to aplay to avoid xrun using arecord | aplay 2 | M Rewrite aplay/arecord tool and separate the experimental stuff 3 | M Write a *good* mixer 4 | L Add support for OSS setups to alsactl 5 | -------------------------------------------------------------------------------- /alsactl/init/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | init_files = \ 3 | 00main default help info test \ 4 | hda ca0106 5 | EXTRA_DIST = $(init_files) 6 | alsainitdir = $(datadir)/alsa/init 7 | alsainit_DATA = $(init_files) 8 | -------------------------------------------------------------------------------- /alsaucm/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = \ 2 | alsaucm 3 | 4 | alsaucm_SOURCES = usecase.c 5 | 6 | AM_CPPFLAGS = \ 7 | -Wall -I$(top_srcdir)/include 8 | 9 | alsaucm_LDADD = -lasound 10 | -------------------------------------------------------------------------------- /topology/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = \ 2 | alsatplg 3 | 4 | alsatplg_SOURCES = topology.c 5 | 6 | AM_CPPFLAGS = \ 7 | -Wall -I$(top_srcdir)/include 8 | 9 | alsatplg_LDADD = -lasound 10 | 11 | -------------------------------------------------------------------------------- /seq/aconnect/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/include 2 | EXTRA_DIST = README.aconnect aconnect.1 3 | LDADD = $(LIBINTL) 4 | 5 | bin_PROGRAMS = aconnect 6 | aconnect_SOURCES = aconnect.c 7 | man_MANS = aconnect.1 8 | -------------------------------------------------------------------------------- /seq/aseqnet/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/include 2 | EXTRA_DIST = README.aseqnet aseqnet.1 3 | 4 | bin_PROGRAMS = aseqnet 5 | aseqnet_SOURCES = aseqnet.c 6 | aseqnet_LDADD = $(INTLLIBS) 7 | man_MANS = aseqnet.1 8 | -------------------------------------------------------------------------------- /alsamixer/die.h: -------------------------------------------------------------------------------- 1 | #ifndef DIE_H_INCLUDED 2 | #define DIE_H_INCLUDED 3 | 4 | void fatal_error(const char *msg) __attribute__((__noreturn__)); 5 | void fatal_alsa_error(const char *msg, int err) __attribute__((__noreturn__)); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /alsamixer/mainloop.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINLOOP_H_INCLUDED 2 | #define MAINLOOP_H_INCLUDED 3 | 4 | #include CURSESINC 5 | 6 | void initialize_curses(bool use_color); 7 | void mainloop(void); 8 | void app_shutdown(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /iecset/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/include 2 | LDADD = -lm 3 | # LDFLAGS = -static 4 | # CFLAGS += -g -Wall 5 | 6 | bin_PROGRAMS = iecset 7 | iecset_SOURCES = iecset.c iecbits.c 8 | man_MANS = iecset.1 9 | EXTRA_DIST = iecset.1 10 | -------------------------------------------------------------------------------- /speaker-test/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/include 2 | SUBDIRS= samples 3 | LDADD = $(LIBINTL) -lm 4 | 5 | bin_PROGRAMS = speaker-test 6 | speaker_test_SOURCES = speaker-test.c pink.c 7 | man_MANS = speaker-test.1 8 | EXTRA_DIST = readme.txt speaker-test.1 pink.h 9 | 10 | -------------------------------------------------------------------------------- /alsamixer/mixer_display.h: -------------------------------------------------------------------------------- 1 | #ifndef MIXER_DISPLAY_H_INCLUDED 2 | #define MIXER_DISPLAY_H_INCLUDED 3 | 4 | void init_mixer_layout(void); 5 | void display_card_info(void); 6 | void display_view_mode(void); 7 | void display_controls(void); 8 | void compute_controls_layout(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /amixer/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/include 2 | LDADD = -lm 3 | # LDFLAGS = -static 4 | # CFLAGS += -g -Wall 5 | 6 | bin_PROGRAMS = amixer 7 | amixer_SOURCES = amixer.c ../alsamixer/volume_mapping.c 8 | noinst_HEADERS = amixer.h 9 | man_MANS = amixer.1 10 | EXTRA_DIST = amixer.1 11 | -------------------------------------------------------------------------------- /po/POTFILES.in: -------------------------------------------------------------------------------- 1 | alsamixer/card_select.c 2 | alsamixer/cli.c 3 | alsamixer/device_name.c 4 | alsamixer/die.c 5 | alsamixer/mixer_display.c 6 | alsamixer/mixer_widget.c 7 | alsamixer/proc_files.c 8 | alsamixer/textbox.c 9 | aplay/aplay.c 10 | seq/aconnect/aconnect.c 11 | seq/aseqnet/aseqnet.c 12 | speaker-test/speaker-test.c 13 | -------------------------------------------------------------------------------- /alsamixer/mem.h: -------------------------------------------------------------------------------- 1 | #ifndef MEM_H_INCLUDED 2 | #define MEM_H_INCLUDED 3 | 4 | #include 5 | 6 | void *ccalloc(size_t n, size_t size); 7 | void *crealloc(void *ptr, size_t new_size); 8 | char *cstrdup(const char *s); 9 | char *casprintf(const char *fmt, ...) __attribute__((__format__(printf, 1, 2))); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /alsamixer/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_H_INCLUDED 2 | #define UTILS_H_INCLUDED 3 | 4 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof *(a)) 5 | 6 | unsigned int get_mbs_width(const char *s); 7 | unsigned int get_max_mbs_width(const char *const *s, unsigned int count); 8 | const char *mbs_at_width(const char *s, int *width, int dir); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /alsamixer/textbox.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTBOX_H_INCLUDED 2 | #define TEXTBOX_H_INCLUDED 3 | 4 | void show_error(const char *msg, int err); 5 | void show_alsa_error(const char *msg, int err); 6 | void show_text(const char *const *text_lines, unsigned int count, 7 | const char *title); 8 | void show_textfile(const char *file_name); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /speaker-test/readme.txt: -------------------------------------------------------------------------------- 1 | To make or build just type 2 | 3 | make 4 | 5 | To test: - 6 | 1) Just stereo sound from one stereo jack: - 7 | ./speaker-test -Dplug:front -c2 8 | 2) A 4 speaker setup from two stereo jacks: - 9 | ./speaker-test -Dplug:surround40 -c4 10 | 3) A 5.1 speaker setup from three stereo jacks: - 11 | ./speaker-test -Dplug:surround51 -c6 12 | 13 | -------------------------------------------------------------------------------- /amixer/go: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #GDB="gdb --args" 4 | GDB="" 5 | 6 | ALSA_MIXER_SIMPLE_MODULES="$HOME/hg/alsa-lib/modules/mixer/simple/.libs" \ 7 | ALSA_MIXER_SIMPLE="$HOME/hg/alsa-lib/src/conf/smixer.conf" \ 8 | ALSA_MIXER_SIMPLE_MPYTHON="$HOME/hg/alsa-lib/modules/mixer/simple/python/main.py" \ 9 | LD_PRELOAD="$HOME/hg/alsa-lib/src/.libs/libasound.so" \ 10 | $GDB ./amixer "$@" 11 | -------------------------------------------------------------------------------- /alsaloop/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/include 2 | LDADD = -lm 3 | AM_CFLAGS = -D_GNU_SOURCE 4 | if HAVE_SAMPLERATE 5 | LDADD += -lsamplerate 6 | endif 7 | # LDFLAGS = -static 8 | # CFLAGS += -g -Wall 9 | 10 | bin_PROGRAMS = alsaloop 11 | alsaloop_SOURCES = alsaloop.c pcmjob.c control.c 12 | noinst_HEADERS = alsaloop.h 13 | man_MANS = alsaloop.1 14 | EXTRA_DIST = alsaloop.1 15 | -------------------------------------------------------------------------------- /alsamixer/go: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #GDB="gdb --args" 4 | GDB="" 5 | 6 | ALSA_MIXER_SIMPLE_MODULES="$HOME/hg/alsa-lib/modules/mixer/simple/.libs" \ 7 | ALSA_MIXER_SIMPLE="$HOME/hg/alsa-lib/src/conf/smixer.conf" \ 8 | ALSA_MIXER_SIMPLE_MPYTHON="$HOME/hg/alsa-lib/modules/mixer/simple/python/main.py" \ 9 | LD_PRELOAD="$HOME/hg/alsa-lib/src/.libs/libasound.so" \ 10 | $GDB ./alsamixer "$@" 11 | -------------------------------------------------------------------------------- /alsactl/90-alsa-restore.rules.in: -------------------------------------------------------------------------------- 1 | ACTION=="add", SUBSYSTEM=="sound", KERNEL=="controlC*", KERNELS!="card*", TEST=="@sbindir@", TEST=="@mydatadir@", GOTO="alsa_restore_go" 2 | GOTO="alsa_restore_end" 3 | 4 | LABEL="alsa_restore_go" 5 | TEST!="@daemonswitch@", RUN+="@sbindir@/alsactl restore $attr{device/number}" 6 | TEST=="@daemonswitch@", RUN+="@sbindir@/alsactl nrestore $attr{device/number}" 7 | 8 | LABEL="alsa_restore_end" 9 | -------------------------------------------------------------------------------- /alsactl/init/help: -------------------------------------------------------------------------------- 1 | # help page 2 | 3 | PRINT="Available commands (identified by the environment variable CMD):\n\n" 4 | PRINT=" (not set) Do a soundcard initialization\n" 5 | PRINT=" default Do a default (guess method) initialization\n" 6 | PRINT=" help Show this information\n" 7 | PRINT=" info Print all available hardware identification\n" 8 | PRINT=" test Do alsactl utility parser tests\n" 9 | -------------------------------------------------------------------------------- /alsactl/alsa-state.service.in: -------------------------------------------------------------------------------- 1 | # 2 | # Note that two different ALSA card state management schemes exist and they 3 | # can be switched using a file exist check - /etc/alsa/state-daemon.conf . 4 | # 5 | 6 | [Unit] 7 | Description=Manage Sound Card State (restore and store) 8 | ConditionPathExists=@daemonswitch@ 9 | After=sysinit.target 10 | 11 | [Service] 12 | Type=simple 13 | ExecStart=-@sbindir@/alsactl -s -n 19 -c rdaemon 14 | ExecStop=-@sbindir@/alsactl -s kill save_and_quit 15 | -------------------------------------------------------------------------------- /speaker-test/samples/Makefile.am: -------------------------------------------------------------------------------- 1 | sounddir = $(datadir)/sounds/alsa 2 | wav_files = Front_Left.wav \ 3 | Rear_Center.wav \ 4 | Rear_Right.wav \ 5 | Side_Right.wav \ 6 | Front_Center.wav \ 7 | Front_Right.wav \ 8 | Noise.wav \ 9 | Rear_Left.wav \ 10 | Side_Left.wav 11 | sound_DATA = $(wav_files) 12 | 13 | alsadir = $(datadir)/alsa/speaker-test 14 | cfg_files = sample_map.csv 15 | 16 | alsa_DATA = $(cfg_files) 17 | 18 | EXTRA_DIST = \ 19 | $(wav_files) \ 20 | $(cfg_files) 21 | -------------------------------------------------------------------------------- /acinclude.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([SAVE_UTIL_VERSION], [ 2 | SND_UTIL_VERSION=$VERSION 3 | echo $VERSION > $srcdir/version 4 | AC_DEFINE_UNQUOTED(VERSION, "$SND_UTIL_VERSION", [ALSA util version]) 5 | AC_SUBST(SND_UTIL_VERSION) 6 | SND_UTIL_MAJOR=`echo $VERSION | cut -d . -f 1` 7 | AC_SUBST(SND_UTIL_MAJOR) 8 | SND_UTIL_MINOR=`echo $VERSION | cut -d . -f 2` 9 | AC_SUBST(SND_UTIL_MINOR) 10 | SND_UTIL_SUBMINOR=`echo $VERSION | cut -d . -f 3 | sed -e 's/pre[[0-9]]*//g'` 11 | AC_SUBST(SND_UTIL_SUBMINOR) 12 | ]) 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DISCONTINUATION OF PROJECT. 2 | 3 | This project will no longer be maintained by Intel. 4 | 5 | Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project. 6 | 7 | Intel no longer accepts patches to this project. 8 | 9 | If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project. 10 | -------------------------------------------------------------------------------- /alsactl/alsa-restore.service.in: -------------------------------------------------------------------------------- 1 | # 2 | # Note that two different ALSA card state management schemes exist and they 3 | # can be switched using a file exist check - /etc/alsa/state-daemon.conf . 4 | # 5 | 6 | [Unit] 7 | Description=Save/Restore Sound Card State 8 | ConditionPathExists=!@daemonswitch@ 9 | ConditionPathExistsGlob=/dev/snd/control* 10 | After=alsa-state.service 11 | 12 | [Service] 13 | Type=oneshot 14 | RemainAfterExit=true 15 | ExecStart=-@sbindir@/alsactl restore 16 | ExecStop=-@sbindir@/alsactl store 17 | StandardOutput=syslog 18 | -------------------------------------------------------------------------------- /include/gettext.h: -------------------------------------------------------------------------------- 1 | #ifndef __MY_GETTEXT_H 2 | #define __MY_GETTEXT_H 3 | 4 | #ifdef USES_CURSES 5 | #define ENABLE_NLS_TEST ENABLE_NLS_IN_CURSES 6 | #else 7 | #define ENABLE_NLS_TEST ENABLE_NLS 8 | #endif 9 | 10 | #if ENABLE_NLS_TEST 11 | # include 12 | #else 13 | # define gettext(msgid) (msgid) 14 | # define textdomain(domain) 15 | # define bindtextdomain(domain, dir) 16 | #endif 17 | 18 | #define _(msgid) gettext (msgid) 19 | #define gettext_noop(msgid) msgid 20 | #define N_(msgid) gettext_noop (msgid) 21 | 22 | #endif /* __MY_GETTEXT_H */ 23 | -------------------------------------------------------------------------------- /bat/analyze.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2015 Intel Corporation 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | */ 15 | 16 | int analyze_capture(struct bat *); 17 | -------------------------------------------------------------------------------- /alsamixer/volume_mapping.h: -------------------------------------------------------------------------------- 1 | #ifndef VOLUME_MAPPING_H_INCLUDED 2 | #define VOLUME_MAPPING_H_INCLUDED 3 | 4 | #include 5 | 6 | double get_normalized_playback_volume(snd_mixer_elem_t *elem, 7 | snd_mixer_selem_channel_id_t channel); 8 | double get_normalized_capture_volume(snd_mixer_elem_t *elem, 9 | snd_mixer_selem_channel_id_t channel); 10 | int set_normalized_playback_volume(snd_mixer_elem_t *elem, 11 | snd_mixer_selem_channel_id_t channel, 12 | double volume, 13 | int dir); 14 | int set_normalized_capture_volume(snd_mixer_elem_t *elem, 15 | snd_mixer_selem_channel_id_t channel, 16 | double volume, 17 | int dir); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /speaker-test/pink.h: -------------------------------------------------------------------------------- 1 | #define PINK_MAX_RANDOM_ROWS (30) 2 | #define PINK_RANDOM_BITS (24) 3 | #define PINK_RANDOM_SHIFT ((sizeof(long)*8)-PINK_RANDOM_BITS) 4 | 5 | typedef struct 6 | { 7 | long pink_rows[PINK_MAX_RANDOM_ROWS]; 8 | long pink_running_sum; /* Used to optimize summing of generators. */ 9 | int pink_index; /* Incremented each sample. */ 10 | int pink_index_mask; /* Index wrapped by ANDing with this mask. */ 11 | float pink_scalar; /* Used to scale within range of -1.0 to +1.0 */ 12 | } pink_noise_t; 13 | 14 | void initialize_pink_noise( pink_noise_t *pink, int num_rows ); 15 | float generate_pink_noise_sample( pink_noise_t *pink ); 16 | -------------------------------------------------------------------------------- /bat/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = alsabat 2 | man_MANS = alsabat.1 3 | EXTRA_DIST = alsabat.1 alsabat-test.sh 4 | sbin_SCRIPTS = alsabat-test.sh 5 | 6 | alsabat_SOURCES = \ 7 | bat.c \ 8 | common.c \ 9 | signal.c \ 10 | latencytest.c \ 11 | convert.c 12 | 13 | noinst_HEADERS = \ 14 | common.h \ 15 | bat-signal.h \ 16 | latencytest.h \ 17 | convert.h 18 | 19 | if HAVE_LIBFFTW3 20 | alsabat_SOURCES += analyze.c 21 | noinst_HEADERS += analyze.h 22 | endif 23 | 24 | if HAVE_LIBTINYALSA 25 | alsabat_SOURCES += tinyalsa.c 26 | noinst_HEADERS += tinyalsa.h 27 | else 28 | alsabat_SOURCES += alsa.c 29 | noinst_HEADERS += alsa.h 30 | endif 31 | 32 | AM_CPPFLAGS = \ 33 | -Wall -I$(top_srcdir)/include 34 | 35 | alsabat_LDADD = @FFTW_LIB@ 36 | -------------------------------------------------------------------------------- /aplay/Makefile.am: -------------------------------------------------------------------------------- 1 | LIBRT = @LIBRT@ 2 | 3 | AM_CPPFLAGS = -I$(top_srcdir)/include 4 | LDADD = $(LIBINTL) $(LIBRT) 5 | 6 | # debug flags 7 | #LDFLAGS = -static 8 | #LDADD += -ldl 9 | 10 | bin_PROGRAMS = aplay 11 | man_MANS = aplay.1 arecord.1 12 | noinst_HEADERS = formats.h 13 | 14 | EXTRA_DIST = aplay.1 arecord.1 15 | EXTRA_CLEAN = arecord 16 | 17 | arecord: aplay 18 | rm -f arecord 19 | $(LN_S) $< $@ 20 | 21 | arecord.1: aplay.1 22 | rm -f arecord.1 23 | $(LN_S) $< $@ 24 | 25 | install-exec-hook: arecord 26 | rm -f $(DESTDIR)$(bindir)/arecord 27 | (cd $(DESTDIR)$(bindir) && $(LN_S) aplay arecord) 28 | 29 | install-data-hook: 30 | rm -f $(DESTDIR)$(mandir)/man1/arecord.1 31 | (cd $(DESTDIR)$(mandir)/man1 && $(LN_S) aplay.1 arecord.1) 32 | -------------------------------------------------------------------------------- /alsamixer/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS = @CURSES_CFLAGS@ -DCURSESINC="@CURSESINC@" 2 | LDADD = @CURSESLIB@ 3 | 4 | bin_PROGRAMS = alsamixer 5 | alsamixer_SOURCES = card_select.c card_select.h \ 6 | cli.c \ 7 | colors.c colors.h \ 8 | device_name.c device_name.h \ 9 | die.c die.h \ 10 | mainloop.c mainloop.h \ 11 | mem.c mem.h \ 12 | mixer_controls.c mixer_controls.h \ 13 | mixer_display.c mixer_display.h \ 14 | mixer_widget.c mixer_widget.h \ 15 | proc_files.c proc_files.h \ 16 | textbox.c textbox.h \ 17 | utils.c utils.h \ 18 | volume_mapping.c volume_mapping.h \ 19 | widget.c widget.h 20 | man_MANS = alsamixer.1 21 | EXTRA_DIST = alsamixer.1 22 | alsamixer_CPPFLAGS = -I$(top_srcdir)/include 23 | 24 | #LDFLAGS = -static 25 | #CFLAGS += -g -Wall 26 | -------------------------------------------------------------------------------- /bat/alsa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2015 Intel Corporation 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | */ 15 | 16 | extern int retval_play; 17 | extern int retval_record; 18 | 19 | void *playback_alsa(struct bat *); 20 | void *record_alsa(struct bat *); 21 | -------------------------------------------------------------------------------- /bat/latencytest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2015 Intel Corporation 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | */ 15 | void roundtrip_latency_init(struct bat *); 16 | int handleinput(struct bat *, void *, int); 17 | int handleoutput(struct bat *, void *, int, int); 18 | -------------------------------------------------------------------------------- /bat/tinyalsa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2015 Intel Corporation 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | */ 15 | 16 | extern int retval_play; 17 | extern int retval_record; 18 | 19 | void *playback_tinyalsa(struct bat *); 20 | void *record_tinyalsa(struct bat *); 21 | -------------------------------------------------------------------------------- /gitcompile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if test -d ../alsa-lib/utils && ! test -r `aclocal --print-ac-dir`/alsa.m4; then 4 | alsa_m4_flags="-I ../alsa-lib/utils" 5 | fi 6 | aclocal $alsa_m4_flags $ACLOCAL_FLAGS 7 | # save original files to avoid stupid modifications by gettextize 8 | cp Makefile.am Makefile.am.ok 9 | cp configure.ac configure.ac.ok 10 | gettextize -c -f --no-changelog 11 | echo "EXTRA_DIST = gettext.m4" > m4/Makefile.am 12 | cp Makefile.am.ok Makefile.am 13 | cp configure.ac.ok configure.ac 14 | autoheader 15 | automake --foreign --copy --add-missing 16 | touch depcomp # for older automake 17 | autoconf 18 | export CFLAGS='-O2 -Wall -pipe -g' 19 | echo "CFLAGS=$CFLAGS" 20 | echo "./configure $@" 21 | ./configure $@ || exit 1 22 | unset CFLAGS 23 | if [ -z "$GITCOMPILE_NO_MAKE" ]; then 24 | make 25 | fi 26 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | Advanced Linux Sound Architecture - Utilities 3 | ============================================= 4 | 5 | This package contains the command line utilities for the ALSA project. 6 | The package can be compiled only with the installed ALSA driver and 7 | the ALSA C library. 8 | 9 | alsaconf - the ALSA driver configurator script 10 | alsactl - an utility for soundcard settings management 11 | aplay/arecord - an utility for the playback / capture of .wav,.voc,.au files 12 | amixer - a command line mixer 13 | alsamixer - a ncurses mixer 14 | amidi - a utility to send/receive sysex dumps or other MIDI data 15 | iecset - a utility to show/set the IEC958 status bits 16 | 17 | You may give a look for more information about the ALSA project to URL 18 | http://www.alsa-project.org. 19 | 20 | Jaroslav Kysela 21 | -------------------------------------------------------------------------------- /alsamixer/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H_INCLUDED 2 | #define WIDGET_H_INCLUDED 3 | 4 | #include 5 | 6 | #define WIDGET_BORDER 0x1 7 | #define WIDGET_SUBWINDOW 0x2 8 | #define WIDGET_CURSOR_VISIBLE 0x4 9 | 10 | #define SCREEN_CENTER -1 11 | 12 | struct widget { 13 | WINDOW *window; 14 | WINDOW *subwindow; /* optional: contents without border */ 15 | PANEL *panel; 16 | int cursor_visibility; 17 | 18 | void (*handle_key)(int key); 19 | void (*window_size_changed)(void); 20 | void (*close)(void); 21 | }; 22 | 23 | extern int screen_lines; 24 | extern int screen_cols; 25 | 26 | void widget_init(struct widget *widget, 27 | int lines_, int cols, int y, int x, 28 | chtype bkgd, unsigned int flags); 29 | void widget_free(struct widget *widget); 30 | struct widget *get_active_widget(void); 31 | void window_size_changed(void); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /alsamixer/colors.h: -------------------------------------------------------------------------------- 1 | #ifndef COLORS_H_INCLUDED 2 | #define COLORS_H_INCLUDED 3 | 4 | #define TRICOLOR_VOLUME_BAR 5 | 6 | extern int attr_mixer_frame; 7 | extern int attr_mixer_text; 8 | extern int attr_mixer_active; 9 | extern int attr_ctl_frame; 10 | extern int attr_ctl_mute; 11 | extern int attr_ctl_nomute; 12 | extern int attr_ctl_capture; 13 | extern int attr_ctl_nocapture; 14 | extern int attr_ctl_label; 15 | extern int attr_ctl_label_focus; 16 | extern int attr_ctl_mark_focus; 17 | extern int attr_ctl_bar_lo; 18 | #ifdef TRICOLOR_VOLUME_BAR 19 | extern int attr_ctl_bar_mi; 20 | extern int attr_ctl_bar_hi; 21 | #endif 22 | extern int attr_ctl_inactive; 23 | extern int attr_ctl_label_inactive; 24 | extern int attr_errormsg; 25 | extern int attr_infomsg; 26 | extern int attr_textbox; 27 | extern int attr_textfield; 28 | extern int attr_menu; 29 | extern int attr_menu_selected; 30 | 31 | void init_colors(int use_color); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /amixer/amixer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ALSA command line mixer utility 3 | * Copyright (c) 1999 by Jaroslav Kysela 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | */ 20 | 21 | #include "../include/version.h" 22 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_HEADERS=version.h gettext.h gettext_curses.h 2 | 3 | version.h: stamp-vh 4 | @: 5 | 6 | stamp-vh: $(top_builddir)/configure.ac 7 | @echo "/*" > ver.tmp 8 | @echo " * version.h" >> ver.tmp 9 | @echo " */" >> ver.tmp 10 | @echo "" >> ver.tmp 11 | @echo "#define SND_UTIL_MAJOR $(SND_UTIL_MAJOR)" >> ver.tmp 12 | @echo "#define SND_UTIL_MINOR $(SND_UTIL_MINOR)" >> ver.tmp 13 | @echo "#define SND_UTIL_SUBMINOR $(SND_UTIL_SUBMINOR)" >> ver.tmp 14 | @echo "#define SND_UTIL_VERSION ((SND_UTIL_MAJOR<<16)|\\" >> ver.tmp 15 | @echo " (SND_UTIL_MINOR<<8)|\\" >> ver.tmp 16 | @echo " SND_UTIL_SUBMINOR)" >> ver.tmp 17 | @echo "#define SND_UTIL_VERSION_STR \"$(SND_UTIL_VERSION)\"" >> ver.tmp 18 | @echo >> ver.tmp 19 | @cmp -s version.h ver.tmp \ 20 | || (echo "Updating version.h"; \ 21 | cp ver.tmp version.h; \ 22 | echo timestamp > stamp-vh) 23 | -@rm -f ver.tmp 24 | 25 | AM_CPPFLAGS=-I$(top_srcdir)/include 26 | -------------------------------------------------------------------------------- /seq/aseqdump/aseqdump.1: -------------------------------------------------------------------------------- 1 | .TH ASEQDUMP 1 "19 Feb 2005" 2 | 3 | .SH NAME 4 | aseqdump \- show the events received at an ALSA sequencer port 5 | 6 | .SH SYNOPSIS 7 | .B aseqdump 8 | [\fI\-p client:port,...\fP] 9 | 10 | .SH DESCRIPTION 11 | .B aseqdump 12 | is a command-line utility that prints the sequencer events it receives as text. 13 | 14 | To stop receiving, press Ctrl+C. 15 | 16 | .SH OPTIONS 17 | 18 | .TP 19 | .I \-h,\-\-help 20 | Prints a list of options. 21 | 22 | .TP 23 | .I \-V,\-\-version 24 | Prints the current version. 25 | 26 | .TP 27 | .I \-l,\-\-list 28 | Prints a list of possible input ports. 29 | 30 | .TP 31 | .I \-p,\-\-port=client:port,... 32 | Sets the sequencer port(s) from which events are received. 33 | 34 | A client can be specified by its number, its name, or a prefix of its 35 | name. A port is specified by its number; for port 0 of a client, the 36 | ":0" part of the port specification can be omitted. 37 | 38 | .SH AUTHOR 39 | Clemens Ladisch 40 | -------------------------------------------------------------------------------- /alsamixer/mixer_widget.h: -------------------------------------------------------------------------------- 1 | #ifndef MIXER_WIDGET_H_INCLUDED 2 | #define MIXER_WIDGET_H_INCLUDED 3 | 4 | #include CURSESINC 5 | #include 6 | #include "widget.h" 7 | 8 | enum view_mode { 9 | VIEW_MODE_PLAYBACK, 10 | VIEW_MODE_CAPTURE, 11 | VIEW_MODE_ALL, 12 | VIEW_MODE_COUNT, 13 | }; 14 | 15 | extern snd_mixer_t *mixer; 16 | extern char *mixer_device_name; 17 | extern bool unplugged; 18 | 19 | extern struct widget mixer_widget; 20 | 21 | extern enum view_mode view_mode; 22 | 23 | extern int focus_control_index; 24 | extern snd_mixer_selem_id_t *current_selem_id; 25 | extern unsigned int current_control_flags; 26 | 27 | extern bool control_values_changed; 28 | extern bool controls_changed; 29 | 30 | void create_mixer_object(struct snd_mixer_selem_regopt *selem_regopt); 31 | void create_mixer_widget(void); 32 | void mixer_shutdown(void); 33 | void close_mixer_device(void); 34 | bool select_card_by_name(const char *device_name); 35 | void refocus_control(void); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /alsactl/init/info: -------------------------------------------------------------------------------- 1 | # show information about card 2 | 3 | PRINT="CARDINFO:\n" 4 | PRINT=" CARDINFO{id}=\"$CARDINFO{id}\"\n" 5 | PRINT=" CARDINFO{card}=\"$CARDINFO{card}\"\n" 6 | PRINT=" CARDINFO{driver}=\"$CARDINFO{driver}\"\n" 7 | PRINT=" CARDINFO{name}=\"$CARDINFO{name}\"\n" 8 | PRINT=" CARDINFO{longname}=\"$CARDINFO{longname}\"\n" 9 | PRINT=" CARDINFO{mixername}=\"$CARDINFO{mixername}\"\n" 10 | PRINT=" CARDINFO{components}=\"$CARDINFO{components}\"\n" 11 | 12 | # sysfs stuff 13 | PRINT="sysfs:\n" 14 | ATTR{bus}=="*", PRINT=" ATTR{bus}=\"$ATTR{bus}\"\n" 15 | ATTR{class}=="*", PRINT=" ATTR{class}=\"$ATTR{class}\"\n" 16 | ATTR{driver}=="*", PRINT=" ATTR{driver}=\"$ATTR{driver}\"\n" 17 | ATTR{vendor}=="*", PRINT=" ATTR{vendor}=\"$ATTR{vendor}\"\n" 18 | ATTR{device}=="*", PRINT=" ATTR{device}=\"$ATTR{device}\"\n" 19 | ATTR{subsystem_vendor}=="*", \ 20 | PRINT=" ATTR{subsystem_vendor}=\"$ATTR{subsystem_vendor}\"\n" 21 | ATTR{subsystem_device}=="*", \ 22 | PRINT=" ATTR{subsystem_device}=\"$ATTR{subsystem_device}\"\n" 23 | -------------------------------------------------------------------------------- /utils/buildrpm: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source=. 4 | version=`cat $source/../version` 5 | package=$source/../alsa-utils-$version.tar.bz2 6 | packagedir=/usr/src/redhat 7 | xrpmbuild=rpm 8 | rpmbuild --usage 2> /dev/null > /dev/null && xrpmbuild=rpmbuild 9 | 10 | # SuSE path 11 | if [ -d /usr/src/packages ]; then 12 | packagedir=/usr/src/packages 13 | fi 14 | 15 | make -C .. clean 16 | make -C .. dist 17 | 18 | if [ ! -r $package ]; then 19 | echo "Error: wrong package: $package" 20 | exit 1 21 | fi 22 | 23 | cp -fv $package ${packagedir}/SOURCES 24 | 25 | if [ ! -r $source/buildrpm ]; then 26 | echo "Error: invalid directory: $source" 27 | exit 1 28 | fi 29 | 30 | if [ ! -d ${packagedir} ]; then 31 | echo "Error: ${packagedir} directory not found" 32 | exit 1 33 | fi 34 | 35 | if [ ! -r $source/alsadriver.spec ]; then 36 | cd $source/.. 37 | ./configure 38 | cd utils 39 | fi 40 | 41 | cp -fv $source/alsa-utils.spec ${packagedir}/SPECS 42 | cd ${packagedir}/SPECS 43 | $xrpmbuild -ba alsa-utils.spec 44 | cd ${packagedir} 45 | -------------------------------------------------------------------------------- /bat/convert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2015 Intel Corporation 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | */ 15 | 16 | void convert_uint8_to_float(void *, float *, int); 17 | void convert_int16_to_float(void *, float *, int); 18 | void convert_int24_to_float(void *, float *, int); 19 | void convert_int32_to_float(void *, float *, int); 20 | void convert_float_to_uint8(float *, void *, int, int); 21 | void convert_float_to_int16(float *, void *, int, int); 22 | void convert_float_to_int24(float *, void *, int, int); 23 | void convert_float_to_int32(float *, void *, int, int); 24 | -------------------------------------------------------------------------------- /alsamixer/mixer_controls.h: -------------------------------------------------------------------------------- 1 | #ifndef MIXER_CONTROLS_H_INCLUDED 2 | #define MIXER_CONTROLS_H_INCLUDED 3 | 4 | #include 5 | 6 | struct control { 7 | snd_mixer_elem_t *elem; 8 | char *name; 9 | unsigned int flags; 10 | #define TYPE_PVOLUME (1u << 4) 11 | #define TYPE_CVOLUME (1u << 5) 12 | #define TYPE_PSWITCH (1u << 6) 13 | #define TYPE_CSWITCH (1u << 7) 14 | #define TYPE_ENUM (1u << 8) 15 | #define HAS_VOLUME_0 (1u << 9) 16 | #define HAS_VOLUME_1 (1u << 10) 17 | #define HAS_PSWITCH_0 (1u << 11) 18 | #define HAS_PSWITCH_1 (1u << 12) 19 | #define HAS_CSWITCH_0 (1u << 13) 20 | #define HAS_CSWITCH_1 (1u << 14) 21 | #define IS_MULTICH (1u << 15) 22 | #define IS_ACTIVE (1u << 16) 23 | #define MULTICH_MASK (0x0000f) 24 | snd_mixer_selem_channel_id_t volume_channels[2]; 25 | snd_mixer_selem_channel_id_t pswitch_channels[2]; 26 | snd_mixer_selem_channel_id_t cswitch_channels[2]; 27 | unsigned int enum_channel_bits; 28 | }; 29 | 30 | extern struct control *controls; 31 | extern unsigned int controls_count; 32 | 33 | bool are_there_any_controls(void); 34 | void create_controls(void); 35 | void free_controls(void); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | configure 2 | config.log 3 | config.cache 4 | config.status 5 | config.guess 6 | config.rpath 7 | config.sub 8 | Makefile.conf 9 | confdefs.h 10 | aclocal.m4 11 | Makefile 12 | Makefile.in 13 | version 14 | autom4te.cache 15 | compile 16 | depcomp 17 | missing 18 | install-sh 19 | mkinstalldirs 20 | ABOUT-NLS 21 | *.ok 22 | *.gmo 23 | *.o 24 | *~ 25 | .deps 26 | 27 | alsactl/alsactl 28 | alsactl/alsactl_init.7 29 | alsactl/alsa-state.service 30 | alsactl/alsa-restore.service 31 | alsactl/alsa-store.service 32 | alsaconf/alsaconf 33 | alsamixer/alsamixer 34 | amidi/amidi 35 | amixer/amixer 36 | aplay/aplay 37 | aplay/arecord 38 | aplay/arecord.1 39 | bat/alsabat 40 | iecset/iecset 41 | seq/aconnect/aconnect 42 | seq/aplaymidi/aplaymidi 43 | seq/aplaymidi/arecordmidi 44 | seq/aseqdump/aseqdump 45 | seq/aseqnet/aseqnet 46 | speaker-test/speaker-test 47 | alsaloop/alsaloop 48 | alsaucm/alsaucm 49 | topology/alsatplg 50 | 51 | include/aconfig.h* 52 | include/stamp-* 53 | include/version.h 54 | po/Makefile* 55 | po/POTFILES 56 | po/Rules-quot 57 | po/*.header 58 | po/*.sin 59 | po/*.sed 60 | po/*.gmo 61 | po/stamp-po 62 | po/alsa-utils.pot 63 | po/Makevars.template 64 | po/ChangeLog 65 | m4/* 66 | utils/*.spec 67 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2005-08-13 gettextize 2 | 3 | * Makefile.am (EXTRA_DIST): Add config.rpath, mkinstalldirs. 4 | * configure.in (AM_GNU_GETTEXT_VERSION): Bump to 0.14.4. 5 | 6 | 0.0.7 -> 0.2.0 7 | 8 | * removed error message from alsamixer 9 | * fixes in alsactl program 10 | * version is now compatible with driver 11 | 12 | 0.0.6 -> 0.0.7 13 | 14 | * added alsactl control program 15 | * updated alsamixer by Carl van Schaik 16 | - stereo record source select 17 | - left/right route support 18 | 19 | 0.0.5 -> 0.0.6 20 | 21 | * updates for new alsa-lib 22 | * fixed compilation problems with config.h header file 23 | * updated output 'aplay -l' 24 | 25 | 0.0.3 -> 0.0.4 26 | 27 | * added check for alsa-lib package 28 | * added spec file for RPM 29 | 30 | 0.0.2 -> 0.0.3 31 | 32 | * included great ncurses alsamixer from Tim Janik 33 | * enhanced Mixer from Andy Lo A Foe renamed to amixer 34 | 35 | 0.0.1 -> 0.0.2 36 | 37 | * fixed small bug in aplay in command line parsing 38 | * fixed fragment size allocation for low rate files in aplay 39 | * a little bit corrected output from Mixer 40 | 41 | 0.0.1 42 | 43 | * initial release (aplay, broken Mixer) 44 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS=-I$(top_srcdir)/include 2 | 3 | SUBDIRS = include alsactl utils m4 po alsa-info 4 | if ALSAMIXER 5 | SUBDIRS += alsamixer 6 | endif 7 | if HAVE_MIXER 8 | SUBDIRS += amixer 9 | endif 10 | if HAVE_RAWMIDI 11 | SUBDIRS += amidi 12 | endif 13 | if ALSACONF 14 | SUBDIRS += alsaconf 15 | endif 16 | if HAVE_PCM 17 | SUBDIRS += aplay iecset speaker-test 18 | if ALSALOOP 19 | SUBDIRS += alsaloop 20 | endif 21 | if BAT 22 | SUBDIRS += bat 23 | endif 24 | endif 25 | if HAVE_SEQ 26 | SUBDIRS += seq 27 | endif 28 | if HAVE_UCM 29 | SUBDIRS += alsaucm 30 | endif 31 | if HAVE_TOPOLOGY 32 | SUBDIRS += topology 33 | endif 34 | 35 | EXTRA_DIST= TODO gitcompile 36 | AUTOMAKE_OPTIONS=foreign 37 | ACLOCAL_AMFLAGS = -I m4 38 | 39 | rpm: dist 40 | $(MAKE) -C $@ 41 | 42 | dist-hook: 43 | -chmod -R a+r $(distdir) 44 | @if ! test -z "$(AMTAR)"; then \ 45 | $(AMTAR) --create --verbose --file=- $(distdir) | bzip2 -c -9 > $(distdir).tar.bz2 ; \ 46 | else \ 47 | $(TAR) --create --verbose --file=- $(distdir) | bzip2 -c -9 > $(distdir).tar.bz2 ; \ 48 | fi 49 | 50 | install-data-hook: 51 | $(MKDIR_P) -m 0755 $(DESTDIR)$(ASOUND_STATE_DIR) 52 | 53 | DISTCHECK_CONFIGURE_FLAGS = \ 54 | --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) 55 | -------------------------------------------------------------------------------- /alsaconf/Makefile.am: -------------------------------------------------------------------------------- 1 | sbin_SCRIPTS = alsaconf 2 | man_MANS = alsaconf.8 alsaconf.fr.8 3 | EXTRA_DIST = $(man_MANS) 4 | SUBDIRS = po 5 | 6 | install-man8: 7 | @for i in $(man_MANS); do \ 8 | ext=`echo $$i | $(SED) -e 's/^.*\\.//'`; \ 9 | inst=`echo $$i | $(SED) -e 's/\\.[^.]*$$//'`; \ 10 | case $$inst in \ 11 | *.[a-za-z]*)\ 12 | loc=`echo $$inst | $(SED) -e 's/^.*\\.//'`; \ 13 | loc="/$$loc"; \ 14 | inst=`echo $$inst | $(SED) -e 's/\\.[^.]*$$//'`;; \ 15 | *)\ 16 | loc="";; \ 17 | esac; \ 18 | $(mkinstalldirs) $(DESTDIR)$(mandir)$$loc/man$$ext; \ 19 | echo " $(INSTALL_DATA) $$i $(DESTDIR)$(mandir)$$loc/man$$ext/$$inst.$$ext"; \ 20 | $(INSTALL_DATA) $(srcdir)/$$i $(DESTDIR)$(mandir)$$loc/man$$ext/$$inst.$$ext; \ 21 | done 22 | 23 | uninstall-man8: 24 | @for i in $(man_MANS); do \ 25 | ext=`echo $$i | $(SED) -e 's/^.*\\.//'`; \ 26 | inst=`echo $$i | $(SED) -e 's/\\.[^.]*$$//'`; \ 27 | case $$inst in \ 28 | *.[a-za-z]*)\ 29 | loc=`echo $$inst | $(SED) -e 's/^.*\\.//'`; \ 30 | loc="/$$loc"; \ 31 | inst=`echo $$inst | $(SED) -e 's/\\.[^.]*$$//'`;; \ 32 | *)\ 33 | loc="";; \ 34 | esac; \ 35 | echo " rm -f $(DESTDIR)$(mandir)$$loc/man$$ext/$$inst.$$ext"; \ 36 | rm -f $(DESTDIR)$(mandir)$$loc/man$$ext/$$inst.$$ext; \ 37 | done 38 | -------------------------------------------------------------------------------- /alsamixer/die.c: -------------------------------------------------------------------------------- 1 | /* 2 | * die.c - error handlers 3 | * Copyright (c) Clemens Ladisch 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "aconfig.h" 20 | #include 21 | #include 22 | #include 23 | #include "gettext_curses.h" 24 | #include "mainloop.h" 25 | #include "die.h" 26 | 27 | void fatal_error(const char *msg) 28 | { 29 | app_shutdown(); 30 | fprintf(stderr, "%s\n", msg); 31 | exit(EXIT_FAILURE); 32 | } 33 | 34 | void fatal_alsa_error(const char *msg, int err) 35 | { 36 | app_shutdown(); 37 | fprintf(stderr, _("%s: %s\n"), msg, snd_strerror(err)); 38 | exit(EXIT_FAILURE); 39 | } 40 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | 2 | ALSA utils installation 3 | ======================= 4 | 5 | Requirements 6 | ------------ 7 | 8 | alsamixer requires the ncurses library. Some systems need to install 9 | the develop package additionally to link with this library. 10 | 11 | alsaconf requires dialog or whiptail program to run properly. 12 | 13 | Installation 14 | ------------ 15 | 16 | For installation you can use these commands: 17 | 18 | ./configure 19 | make install 20 | 21 | If ./configure command complain that alsa-lib package isn't installed, 22 | please, check if --prefix option is same for alsa-lib and alsa-utils 23 | package. The configure script from alsa-utils package probably cannot find 24 | header file asoundlib.h in $prefix/include/alsa directory (usually in 25 | /usr/include/alsa directory). 26 | 27 | Compilation from git sources 28 | --------------------------- 29 | 30 | You need also GNU packages autoconf and automake installed in your system 31 | to compile git sources of alsa-utils package. 32 | 33 | For compilation you can use these commands: 34 | 35 | aclocal 36 | gettextize 37 | autoheader 38 | automake --foreign --copy --add-missing 39 | autoconf 40 | ./configure 41 | make 42 | 43 | The included gitcompile script does this job for you. 44 | 45 | Note: Some automake packages have missing aclocal program. Use newer version 46 | in the case. 47 | -------------------------------------------------------------------------------- /bat/bat-signal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Caleb Crome 3 | * Copyright (C) 2013-2015 Intel Corporation 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | */ 16 | 17 | /* 18 | * Here's a generic sine wave generator that will work indefinitely 19 | * for any frequency. 20 | * 21 | * Note: the state & phasor are stored as doubles (and updated as 22 | * doubles) because after a million samples the magnitude drifts a 23 | * bit. If we really need floats, it can be done with periodic 24 | * renormalization of the state_real+state_imag magnitudes. 25 | */ 26 | 27 | int sin_generator_init(struct sin_generator *, float, float, float); 28 | float sin_generator_next_sample(struct sin_generator *); 29 | void sin_generator_vfill(struct sin_generator *, float *, int); 30 | int generate_sine_wave(struct bat *, int, void *); 31 | int generate_sine_wave_raw_mono(struct bat *, float *, float, int); 32 | -------------------------------------------------------------------------------- /alsactl/init/ca0106: -------------------------------------------------------------------------------- 1 | # Configuration for CA0106 driver 2 | 3 | CTL{reset}="mixer" 4 | CTL{name}="Master Playback Volume", CTL{values}="-20dB" 5 | CTL{name}="Master Playback Switch", CTL{values}="on" 6 | CTL{name}="Analog Front Playback Volume", CTL{values}="0dB" 7 | CTL{name}="Analog Front Playback Switch", CTL{values}="on" 8 | CTL{name}="Analog Rear Playback Volume", CTL{values}="0dB" 9 | CTL{name}="Analog Rear Playback Switch", CTL{values}="on" 10 | CTL{name}="Analog Center/LFE Playback Volume", CTL{values}="0dB" 11 | CTL{name}="Analog Center/LFE Playback Switch", CTL{values}="on" 12 | CTL{name}="Analog Side Playback Volume", CTL{values}="0dB" 13 | CTL{name}="Analog Side Playback Switch", CTL{values}="on" 14 | CTL{name}="IEC958 Front Playback Volume", CTL{values}="0dB" 15 | CTL{name}="IEC958 Rear Playback Volume", CTL{values}="0dB" 16 | CTL{name}="IEC958 Center/LFE Playback Volume", CTL{values}="0dB" 17 | # capture 18 | CTL{name}="Analog Source Capture Enum", CTL{value}="Mic" 19 | CTL{name}="Mic Capture Volume", CTL{values}="6dB" 20 | CTL{name}="Shared Mic/Line in Capture Switch", CTL{values}="Mic in" 21 | 22 | # some variants have also AC97 mixer 23 | 24 | CTL{reset}="mixer" 25 | CTL{name}="AC97 Line Capture Volume",PROGRAM!="__ctl_search",GOTO="ac97_end" 26 | CTL{name}="Analog Source Capture Enum", CTL{value}="AC97 in" 27 | CTL{name}="AC97 Mic Capture Switch", "on" 28 | CTL{name}="AC97 Mic Capture Value", "6dB" 29 | LABEL="ac97_end" 30 | 31 | RESULT="true", EXIT="return" 32 | -------------------------------------------------------------------------------- /seq/aconnect/README.aconnect: -------------------------------------------------------------------------------- 1 | ================================================================ 2 | aconnect - control subscriptions 3 | ver.0.1.3 4 | Copyright (C) 1999-2000 Takashi Iwai 5 | ================================================================ 6 | 7 | aconnect is a utility to control subscriptions of two ports as the 8 | third "manager" client. 9 | 10 | For example, the following connects two ports, from 64:0 to 65:0. 11 | 12 | % aconnect 64:0 65:0 13 | 14 | To disconnect the existing subscription, use -d option. 15 | 16 | % aconnect -d 64:0 65:0 17 | 18 | To see which port is available as input port, run the following 19 | command: 20 | 21 | % aconnect -i 22 | client 0: 'System' [type=kernel] 23 | 0 'Timer ' 24 | 1 'Announce ' 25 | client 64: '0: MIDI Synth' [type=kernel] 26 | 0 'card 0: synth-midi: 0' 27 | 28 | Similary, to see the output ports, use -o flag. 29 | 30 | % aconnect -o 31 | client 64: '0: MIDI Synth' [type=kernel] 32 | 0 'card 0: synth-midi: 0' 33 | client 65: 'AWE Wave Table Synth : 0' [type=kernel] 34 | 0 'Emu8000 port 0 ' 35 | 1 'Emu8000 port 1 ' 36 | 2 'Emu8000 port 2 ' 37 | 3 'Emu8000 port 3 ' 38 | 39 | The option -l together with -i or -o shows subscribers for each port. 40 | 41 | Ports are connected exclusively when the option -e is specified. 42 | 43 | For modifying time-stamp with a queue, use -r or -t option followed by 44 | a queue index which updates the time-stamp. Former uses real-time queue, 45 | while the latter uses tick queue. The queue must be used (not necessarily 46 | owned) by the receiver client. 47 | -------------------------------------------------------------------------------- /alsa-info/alsa-info.sh.1: -------------------------------------------------------------------------------- 1 | .TH ALSA-INFO.SH 1 "13 January 2016" 2 | .SH NAME 3 | alsa-info.sh \- command\-line utility to gather information about 4 | the ALSA subsystem 5 | .SH SYNOPSIS 6 | \fBalsa-info.sh\fP [\fIoptions\fP] 7 | 8 | .SH DESCRIPTION 9 | \fBalsa-info.sh\fP is a command\-line utility gathering information 10 | about the ALSA subsystem. It is used mostly for debugging purposes. 11 | 12 | .SH OPTIONS 13 | .TP 14 | \fI\-\-upload\fP 15 | Upload contents to the server (www.alsa-project.org or pastebin.ca). 16 | .TP 17 | \fI\-\-no-upload\fP 18 | Do not upload contents to the remote server. 19 | .TP 20 | \fI\-\-stdout\fP 21 | Print information to standard output. 22 | .TP 23 | \fI\-\-output FILE\fP 24 | Specify file for output in no-upload mode. 25 | .TP 26 | \fI\-\-debug\fP 27 | Run utility as normal, but will not delete file (usually 28 | /tmp/alsa-info.txt). 29 | .TP 30 | \fI\-\-with-aplay\fP 31 | Includes output from \fIaplay -l\fP. 32 | .TP 33 | \fI\-\-with-amixer\fP 34 | Includes output from \fIamixer\fP. 35 | .TP 36 | \fI\-\-with-alsactl\fP 37 | Includes output from \fIalsactl\fP. 38 | .TP 39 | \fI\-\-with-configs\fP 40 | Includes output from ~/.asoundrc and /etc/asound.conf if they exist. 41 | .TP 42 | \fI\-\-update\fP 43 | Check server for updates. 44 | .TP 45 | \fI\-\-about\fP 46 | Print information about authors. 47 | 48 | .SH EXAMPLES 49 | 50 | .TP 51 | \fBalsa-info.sh \-\-no-upload\fR 52 | Will gather all information and show the output file. 53 | 54 | .SH SEE ALSO 55 | \fB 56 | aplay(1) 57 | amixer(1) 58 | alsactl(1) 59 | \fP 60 | 61 | .SH AUTHOR 62 | \fBalsa-info.sh\fP was created by the ALSA team, see \fI\-\-about\fP . 63 | -------------------------------------------------------------------------------- /alsactl/init/hda: -------------------------------------------------------------------------------- 1 | # Configuration for HDA Intel driver (High Definition Audio - Azalia) 2 | 3 | CARDINFO{mixername}=="Realtek ALC880", \ 4 | ATTR{subsystem_vendor}=="0x1025", ATTR{subsystem_device}=="0x0070", \ 5 | GOTO="Acer Travelmate 8100" 6 | CARDINFO{mixername}=="Analog Devices AD1984", \ 7 | ATTR{subsystem_vendor}=="0x17aa", ATTR{subsystem_device}=="0x20ac", \ 8 | GOTO="Lenovo T61" 9 | RESULT="false", EXIT="return" 10 | 11 | LABEL="Acer Travelmate 8100" 12 | # playback 13 | CTL{reset}="mixer" 14 | CTL{name}="Master Playback Volume", CTL{values}="-21dB" 15 | CTL{name}="Master Playback Switch", CTL{values}="on" 16 | CTL{name}="Headphone Playback Switch", CTL{values}="on" 17 | CTL{name}="Front Playback Volume", CTL{values}="-29dB" 18 | CTL{name}="Front Playback Switch", CTL{values}="on" 19 | CTL{name}="PCM Playback Volume", CTL{values}="0dB" 20 | # capture 21 | CTL{name}="Input Source", CTL{value}="Mic" 22 | CTL{name}="Capture Volume", CTL{values}="20dB" 23 | CTL{name}="Capture Switch", CTL{values}="on" 24 | RESULT="true", EXIT="return" 25 | 26 | LABEL="Lenovo T61" 27 | # playback 28 | CTL{reset}="mixer" 29 | CTL{name}="Master Playback Volume", CTL{values}="-13.5dB" 30 | CTL{name}="Master Playback Switch", CTL{values}="on" 31 | CTL{name}="Headphone Playback Switch", CTL{values}="on" 32 | CTL{name}="Speaker Playback Switch", CTL{values}="on" 33 | CTL{name}="PCM Playback Volume", CTL{values}="0dB" 34 | # capture 35 | CTL{name}="Input Source", CTL{value}="Internal Mic" 36 | CTL{name}="Internal Mic Boost", CTL{values}="1" 37 | CTL{name}="Capture Volume", CTL{values}="9dB" 38 | CTL{name}="Capture Switch", CTL{values}="on" 39 | RESULT="true", EXIT="return" 40 | -------------------------------------------------------------------------------- /seq/aplaymidi/aplaymidi.1: -------------------------------------------------------------------------------- 1 | .TH APLAYMIDI 1 "2 Nov 2011" 2 | 3 | .SH NAME 4 | aplaymidi \- play Standard MIDI Files 5 | 6 | .SH SYNOPSIS 7 | .B aplaymidi 8 | \-p client:port[,...] [\-d delay] midifile ... 9 | 10 | .SH DESCRIPTION 11 | .B aplaymidi 12 | is a command-line utility that plays the specified MIDI file(s) to one 13 | or more ALSA sequencer ports. 14 | 15 | .SH OPTIONS 16 | 17 | .TP 18 | .I \-h, \-\-help 19 | Prints a list of options. 20 | 21 | .TP 22 | .I \-V, \-\-version 23 | Prints the current version. 24 | 25 | .TP 26 | .I \-l, \-\-list 27 | Prints a list of possible output ports. 28 | 29 | .TP 30 | .I \-p, \-\-port=client:port,... 31 | Sets the sequencer port(s) to which the events in the MIDI file(s) are 32 | sent. 33 | 34 | A client can be specified by its number, its name, or a prefix of its 35 | name. A port is specified by its number; for port 0 of a client, the 36 | ":0" part of the port specification can be omitted. 37 | 38 | Multiple ports can be specified to allow playback of MIDI file(s) that 39 | contain events for multiple devices (ports), as specified by "Port 40 | Number" meta events. 41 | 42 | For compatibility with 43 | .B pmidi(1), 44 | the port specification is taken from the 45 | .I ALSA_OUTPUT_PORTS 46 | environment variable if none is given on the command line. 47 | 48 | .TP 49 | .I \-d, \-\-delay=seconds 50 | Specifies how long to wait after the end of each MIDI file, 51 | to allow the last notes to die away. 52 | 53 | .SH BUGS 54 | .B aplaymidi 55 | handles "Port Number" meta events, but not "Port Name" meta events. 56 | 57 | .SH SEE ALSO 58 | pmidi(1) 59 | .br 60 | playmidi(1) 61 | 62 | .SH AUTHOR 63 | Clemens Ladisch 64 | -------------------------------------------------------------------------------- /alsamixer/mem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mem.c - memory allocation checkers 3 | * Copyright (c) Clemens Ladisch 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #define _GNU_SOURCE 20 | #include "aconfig.h" 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "die.h" 27 | #include "mem.h" 28 | 29 | static void check(void *p) 30 | { 31 | if (!p) 32 | fatal_error("out of memory"); 33 | } 34 | 35 | void *ccalloc(size_t n, size_t size) 36 | { 37 | void *mem = calloc(n, size); 38 | if (n && size) 39 | check(mem); 40 | return mem; 41 | } 42 | 43 | void *crealloc(void *ptr, size_t new_size) 44 | { 45 | ptr = realloc(ptr, new_size); 46 | if (new_size) 47 | check(ptr); 48 | return ptr; 49 | } 50 | 51 | char *cstrdup(const char *s) 52 | { 53 | char *str = strdup(s); 54 | check(str); 55 | return str; 56 | } 57 | 58 | char *casprintf(const char *fmt, ...) 59 | { 60 | va_list ap; 61 | char *str; 62 | 63 | va_start(ap, fmt); 64 | if (vasprintf(&str, fmt, ap) < 0) 65 | check(NULL); 66 | va_end(ap); 67 | return str; 68 | } 69 | -------------------------------------------------------------------------------- /alsactl/init_sysdeps.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2003 Greg Kroah-Hartman 3 | * Copyright (C) 2005-2006 Kay Sievers 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 of the License. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | * 18 | */ 19 | 20 | #if defined(__GLIBC__) && !(defined(__UCLIBC__) && defined(__USE_BSD)) 21 | static size_t strlcpy(char *dst, const char *src, size_t size) 22 | { 23 | size_t bytes = 0; 24 | char *q = dst; 25 | const char *p = src; 26 | char ch; 27 | 28 | while ((ch = *p++)) { 29 | if (bytes+1 < size) 30 | *q++ = ch; 31 | bytes++; 32 | } 33 | 34 | /* If size == 0 there is no space for a final null... */ 35 | if (size) 36 | *q = '\0'; 37 | return bytes; 38 | } 39 | 40 | static size_t strlcat(char *dst, const char *src, size_t size) 41 | { 42 | size_t bytes = 0; 43 | char *q = dst; 44 | const char *p = src; 45 | char ch; 46 | 47 | while (bytes < size && *q) { 48 | q++; 49 | bytes++; 50 | } 51 | if (bytes == size) 52 | return (bytes + strlen(src)); 53 | 54 | while ((ch = *p++)) { 55 | if (bytes+1 < size) 56 | *q++ = ch; 57 | bytes++; 58 | } 59 | 60 | *q = '\0'; 61 | return bytes; 62 | } 63 | #endif /* __GLIBC__ */ 64 | -------------------------------------------------------------------------------- /alsactl/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = init 2 | 3 | sbin_PROGRAMS=alsactl 4 | man_MANS=alsactl.1 5 | if USE_XMLTO 6 | man_MANS += alsactl_init.7 7 | endif 8 | EXTRA_DIST=alsactl.1 alsactl_init.xml 9 | 10 | alsactl_SOURCES=alsactl.c state.c lock.c utils.c init_parse.c daemon.c \ 11 | monitor.c 12 | 13 | alsactl_CFLAGS=$(AM_CFLAGS) -D__USE_GNU \ 14 | -DSYS_ASOUNDRC=\"$(ASOUND_STATE_DIR)/asound.state\" \ 15 | -DSYS_LOCKFILE=\"$(ASOUND_LOCK_DIR)/asound.state.lock\" \ 16 | -DSYS_PIDFILE=\"$(ALSACTL_PIDFILE_DIR)/alsactl.pid\" 17 | 18 | noinst_HEADERS=alsactl.h list.h init_sysdeps.c init_utils_string.c \ 19 | init_utils_run.c init_sysfs.c 20 | 21 | udevrules_DATA = \ 22 | 90-alsa-restore.rules 23 | 24 | if HAVE_SYSTEMD 25 | 26 | systemdsystemunit_DATA = \ 27 | alsa-state.service \ 28 | alsa-restore.service 29 | 30 | install-data-hook: 31 | $(MKDIR_P) -m 0755 \ 32 | $(DESTDIR)$(systemdsystemunitdir)/basic.target.wants 33 | ( cd $(DESTDIR)$(systemdsystemunitdir)/basic.target.wants && \ 34 | rm -f alsa-state.service alsa-restore.service && \ 35 | $(LN_S) ../alsa-state.service alsa-state.service && \ 36 | $(LN_S) ../alsa-restore.service alsa-restore.service) 37 | 38 | endif 39 | 40 | edit = \ 41 | $(SED) -r -e 's,@sbindir\@,$(sbindir),g' \ 42 | -e 's,@mydatadir\@,$(mydatadir),g' \ 43 | -e 's,@daemonswitch\@,$(ALSACTL_DAEMONSWITCH),g' \ 44 | < $< > $@ || rm $@ 45 | 46 | alsa-state.service: alsa-state.service.in 47 | $(edit) 48 | 49 | alsa-restore.service: alsa-restore.service.in 50 | $(edit) 51 | 52 | 90-alsa-restore.rules: 90-alsa-restore.rules.in 53 | $(edit) 54 | 55 | EXTRA_DIST += \ 56 | alsa-state.service.in \ 57 | alsa-restore.service.in \ 58 | 90-alsa-restore.rules.in 59 | 60 | CLEANFILES = \ 61 | alsa-state.service \ 62 | alsa-restore.service \ 63 | 90-alsa-restore.rules 64 | 65 | %.7: %.xml 66 | xmlto man $? 67 | -------------------------------------------------------------------------------- /alsactl/init/00main: -------------------------------------------------------------------------------- 1 | # This is toplevel configuration for for 'alsactl init'. 2 | # See 'man alsactl_init' for syntax. 3 | 4 | # set root device directory in sysfs for soundcard for ATTR{} command 5 | CONFIG{sysfs_device}="/class/sound/card$cardinfo{card}/device" 6 | ACCESS!="$sysfsroot$config{sysfs_device}", \ 7 | CONFIG{sysfs_device}="/class/sound/controlC$cardinfo{card}/device" 8 | 9 | # test for extra commands 10 | ENV{CMD}=="help", INCLUDE="help", GOTO="00main_end" 11 | ENV{CMD}=="info", INCLUDE="info", GOTO="00main_end" 12 | ENV{CMD}=="default", INCLUDE="default", GOTO="00main_end" 13 | ENV{CMD}=="test", INCLUDE="test", GOTO="00main_end" 14 | ENV{CMD}=="*", ERROR="Unknown command '$env{CMD}'\n", GOTO="00main_end" 15 | 16 | # include files with real configuration 17 | # 18 | # steps are: 19 | # 1) look for preinit subdirectory and parse all files in it 20 | # 2) if RESULT=="skip", skip ALSA standard configuration files 21 | # 3) do ALSA standard configuration 22 | # 4) look for postinit subdirectory and parse all files in it 23 | # 5) if RESULT!="true", initialize hardware using a guess method, 24 | # print an error message and return with exit code 99 25 | # 6) return with exit code 0 (success) 26 | # 27 | 28 | RESULT="unknown" 29 | ACCESS=="preinit", INCLUDE="preinit" 30 | RESULT=="skip", GOTO="init_end" 31 | 32 | # real ALSA configuration database 33 | CARDINFO{driver}=="HDA-Intel", INCLUDE="hda", GOTO="init_end" 34 | CARDINFO{driver}=="CA0106", INCLUDE="ca0106", GOTO="init_end" 35 | CARDINFO{driver}=="Test", INCLUDE="test", GOTO="init_end" 36 | 37 | LABEL="init_end" 38 | ACCESS=="postinit", INCLUDE="postinit" 39 | RESULT=="true", GOTO="00_mainend" 40 | ERROR="Found hardware: \"$cardinfo{driver}\" \"$cardinfo{mixername}\" \"$cardinfo{components}\" \"$attr{subsystem_vendor}\" \"$attr{subsystem_device}\"\n" 41 | ERROR="Hardware is initialized using a generic method\n" 42 | INCLUDE="default" 43 | EXIT="99" 44 | 45 | # 46 | # label identifying end of main file 47 | # 48 | 49 | LABEL="00main_end" 50 | -------------------------------------------------------------------------------- /seq/aseqnet/README.aseqnet: -------------------------------------------------------------------------------- 1 | ================================================================ 2 | ALSA sequencer connectors over network 3 | ver.0.1 4 | Copyright (C) 1999-2000 Takashi Iwai 5 | ================================================================ 6 | 7 | * ASEQNET 8 | 9 | aseqnet is a sequencer client which sends/receives events over 10 | network. Suppose two hosts (hostA and hostB) connected by network. 11 | You need to run ALSA system on both hosts. Then, start aseqnet as a 12 | server on hostA: 13 | 14 | hostA% aseqnet 15 | sequencer opened: 128:0 16 | 17 | A user client 128 with port 0 was opened. (The client number may 18 | vary.) At next, start client on hostB. The argument is the hostname 19 | where server is running. 20 | 21 | hostB% aseqnet hostA 22 | sequencer opened: 132:0 23 | 24 | Now events sent to hostA:128:0 is transferred to hostB:132:0, and vice 25 | versa. 26 | 27 | You can connect these ports arbitrary to other sequencer ports. 28 | For example, connect hostB:132:0 to a MIDI output device 65:0. The 29 | aconnect utility can be used for this: 30 | 31 | hostB% aconnect 132:0 65:0 32 | 33 | Events to hostA:128:0 will be delivered indirectly to hostB:65:0. 34 | You'll hear MIDI sounds as following: 35 | 36 | hostA% pmidi -p 128:0 foo.mid 37 | 38 | The multiple clients may exist simultaneously. If hostC is connected 39 | as a client to hostA, events from from hostA are sent to all connected 40 | network clients, hostB and hostC. However, only one connection is 41 | allowed from a client to a server. 42 | 43 | To disconnect network, stop all clients before server by ctrl-C or 44 | sending signal to them. The server will automatically quit. 45 | 46 | The available options are: 47 | 48 | -p port : specify the TCP port number or TCP service name. 49 | Default value is 40002. 50 | -s addr : explicit read-subscription to the given address 51 | (client:addr). 52 | -d addr : explicit write-subscription to the given address. 53 | -v : verbose mode. 54 | -------------------------------------------------------------------------------- /utils/alsa-utils.spec.in: -------------------------------------------------------------------------------- 1 | %define ver @VERSION@ 2 | %define rel 1 3 | 4 | Summary: Advanced Linux Sound Architecture (ALSA) - Utils 5 | Name: alsa-utils 6 | Version: %ver 7 | Release: %rel 8 | Copyright: GPL 9 | Group: System/Libraries 10 | Source: ftp://ftp.alsa-project.org/pub/utils/alsa-utils-%{ver}.tar.bz2 11 | BuildRoot: %{_tmppath}/%{name}-%{version}-root 12 | URL: http://www.alsa-project.org 13 | Requires: alsa-lib ncurses 14 | BuildRequires: alsa-lib-devel ncurses-devel gettext 15 | 16 | %description 17 | 18 | Advanced Linux Sound Architecture (ALSA) - Utils 19 | 20 | %changelog 21 | * Sun Oct 1 2006 Jaroslav Kysela 22 | - add gettext to BuildRequires 23 | - add more files (see alsa bug#2139) 24 | 25 | * Tue Nov 25 2003 Ronny V. Vindenes 26 | - include all manpages 27 | 28 | * Thu Mar 6 2003 Ronny V. Vindenes 29 | 30 | - removed wrongly included doc file 31 | - changed BuildRoot from /var/tmp to _tmppath 32 | - use standard rpm macros for build & install section 33 | - updated dependencies 34 | 35 | * Tue Nov 20 2001 Jaroslav Kysela 36 | 37 | - changed BuildRoot from /tmp to /var/tmp 38 | - _prefix and _mandir macros are used for configure and mkdir 39 | - DESTDIR is used for make install 40 | 41 | * Sun Nov 11 2001 Miroslav Benes 42 | 43 | - dangerous command "rpm -rf $RPM_BUILD_ROOT" checks $RPM_BUILD_ROOT variable 44 | - unset key "Docdir" - on some new systems are documentation in /usr/share/doc 45 | 46 | * Mon May 28 1998 Helge Jensen 47 | 48 | - Made SPEC file 49 | 50 | %prep 51 | %setup 52 | %build 53 | %configure 54 | make 55 | 56 | %install 57 | [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT 58 | %makeinstall 59 | 60 | %clean 61 | [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT 62 | 63 | %files 64 | %defattr(-, root, root) 65 | 66 | %doc ChangeLog COPYING README 67 | 68 | %{_prefix}/sbin/* 69 | %{_prefix}/bin/* 70 | %{_mandir}/man?/* 71 | %{_mandir}/fr/man?/* 72 | %{_prefix}/share/alsa/speaker-test/* 73 | %{_prefix}/share/locale/ja/LC_MESSAGES/* 74 | %{_prefix}/share/locale/ru/LC_MESSAGES/* 75 | %{_prefix}/share/man/fr/man8/alsaconf.8.gz 76 | %{_prefix}/share/sounds/alsa/* 77 | -------------------------------------------------------------------------------- /seq/aseqnet/aseqnet.1: -------------------------------------------------------------------------------- 1 | .TH aseqnet 1 "January 1, 2000" 2 | .SH NAME 3 | aseqnet \- ALSA sequencer connectors over network 4 | 5 | .SH SYNOPSIS 6 | .B aseqnet 7 | [remotehost] 8 | 9 | .SH DESCRIPTION 10 | .B aseqnet 11 | is an ALSA sequencer client which sends and receives event packets 12 | over network. 13 | Suppose two hosts connected by network, 14 | .I hostA 15 | as a server 16 | and 17 | .I hostB 18 | as a client. 19 | The ALSA sequencer system must be running on both hosts. 20 | For creating the server port, run the following on hostA: 21 | .IP "" 4 22 | hostA% aseqnet 23 | .br 24 | sequencer opened: 128:0 25 | .PP 26 | Then a user client 128 with port 0 was opened on hostA. 27 | (The client number may vary.) 28 | For creating the (network-)client port, run 29 | .B aseqnet 30 | with the hostname of the server: 31 | .IP "" 4 32 | hostB% aseqnet hostA 33 | .br 34 | sequencer opened: 132:0 35 | .PP 36 | Now all events sent to hostA:128:0 are transferred to hostB:132:0, and vice 37 | versa. 38 | .PP 39 | The ports created by 40 | .B aseqnet 41 | can be connected arbitrary to other sequencer ports via 42 | .B aconnect(1). 43 | For example, to connect hostB:132:0 to a MIDI output device 65:0: 44 | .IP "" 4 45 | hostB% aconnect 132:0 65:0 46 | .PP 47 | Then events to hostA:128:0 will be delivered to hostB:65:0. 48 | The following command plays MIDI on 49 | .I hostB. 50 | .IP "" 4 51 | hostA% pmidi \-p 128:0 foo.mid 52 | .PP 53 | The multiple clients may exist simultaneously. If 54 | .I hostC 55 | is connected as a client to hostA, events from from hostA are sent 56 | to all connected network clients, i.e. hostB and hostC. 57 | However, only one connection is allowed from a client to a server. 58 | .PP 59 | To disconnect network, stop all clients before server by ctrl-C or 60 | sending signal to them. The server will automatically quit. 61 | 62 | .SH OPTIONS 63 | .TP 64 | .B \-p port 65 | Specify the TCP port number or TCP service name. 66 | .TP 67 | .B \-s addr 68 | Subscribe to the given address for read automatically. 69 | .TP 70 | .B \-d addr 71 | Subscribe to the given address for write automatically. 72 | .TP 73 | .B \-v 74 | Verbose mode. 75 | 76 | .SH "SEE ALSO" 77 | aconnect(1), pmidi(1) 78 | 79 | .SH AUTHOR 80 | Takashi Iwai . 81 | -------------------------------------------------------------------------------- /alsaconf/po/Makefile.in: -------------------------------------------------------------------------------- 1 | POFILES = ja.po ru.po 2 | 3 | DOMAIN = alsaconf 4 | GETTEXT_SRC = ../alsaconf.in 5 | 6 | XGETTEXT_OPTIONS = -kxmsg -kxecho 7 | 8 | top_builddir = ../.. 9 | 10 | srcdir = @srcdir@ 11 | datadir = @datadir@ 12 | exec_prefix = @exec_prefix@ 13 | prefix = @prefix@ 14 | localedir = $(datadir)/locale 15 | 16 | USE_NLS = @USE_NLS@ 17 | INSTALL = @INSTALL@ 18 | INSTALL_DATA = @INSTALL_DATA@ 19 | # mkdir_p = @mkdir_p@ 20 | mkdir_p = mkdir -p -- 21 | XGETTEXT = @XGETTEXT@ 22 | MSGFMT = @MSGFMT@ 23 | GMSGFMT = @GMSGFMT@ 24 | MSGMERGE = @MSGMERGE@ 25 | MSGMERGE_UPDATE = @MSGMERGE@ --update 26 | 27 | DISTFILES = $(POFILES) Makefile.in 28 | CATALOGS = $(POFILES:.po=.gmo) 29 | 30 | all: all-@USE_NLS@ 31 | 32 | all-yes: $(CATALOGS) 33 | all-no: 34 | 35 | .SUFFIXES: .po .gmo .mo 36 | 37 | %.mo : $(srcdir)/%.po 38 | $(MSGFMT) -c -o t-$@ $< && mv t-$@ $@ 39 | 40 | %.gmo : $(srcdir)/%.po 41 | @lang=`echo $(srcdir)/$* | sed -e 's,.*/,,'`; \ 42 | rm -f $${lang}.gmo && $(GMSGFMT) -c --statistics -o t-$${lang}.gmo $(srcdir)/$${lang}.po && mv t-$${lang}.gmo $${lang}.gmo 43 | 44 | $(DOMAIN).pot: $(GETTEXT_SRC) 45 | $(XGETTEXT) -o$@ --default-domain=$(DOMAIN) \ 46 | --add-comments=TRANSLATORS: --language=Shell \ 47 | $(XGETTEXT_OPTIONS) $< 48 | 49 | check check_recursive: 50 | 51 | clean: 52 | rm -f $(CATALOGS) $(POFILES:.po=.mo) $(DOMAIN).pot 53 | 54 | update-po: $(DOMAIN).pot 55 | @for po in $(POFILES); do \ 56 | $(MSGMERGE_UPDATE) $(srcdir)/$$po $(DOMAIN).pot; \ 57 | done 58 | 59 | install-data-no: 60 | install-data-yes: all 61 | $(mkdir_p) $(DESTDIR)$(datadir) 62 | @catalogs='$(CATALOGS)'; \ 63 | for cat in $$catalogs; do \ 64 | lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \ 65 | dir=$(localedir)/$$lang/LC_MESSAGES; \ 66 | $(mkdir_p) $(DESTDIR)$$dir; \ 67 | $(INSTALL_DATA) $$cat $(DESTDIR)$$dir/$(DOMAIN).mo; \ 68 | done 69 | 70 | install-data: install-data-@USE_NLS@ 71 | install: install-data 72 | 73 | uninstall-data-no: 74 | uninstall-data-yes: 75 | @catalogs='$(CATALOGS)'; \ 76 | for cat in $$catalogs; do \ 77 | cat=`basename $$cat`; \ 78 | lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \ 79 | rm -f $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(DOMAIN).mo; \ 80 | done 81 | 82 | uninstall-data: uninstall-data-@USE_NLS@ 83 | uninstall: uninstall-data 84 | 85 | dist distdir: $(DISTFILES) 86 | @for file in $(DISTFILES); do \ 87 | cp -p $$file $(distdir); \ 88 | done 89 | 90 | distclean: clean 91 | rm -f Makefile *~ 92 | -------------------------------------------------------------------------------- /po/Makevars: -------------------------------------------------------------------------------- 1 | # Makefile variables for PO directory in any package using GNU gettext. 2 | 3 | # Usually the message domain is the same as the package name. 4 | DOMAIN = $(PACKAGE) 5 | 6 | # These two variables depend on the location of this directory. 7 | subdir = po 8 | top_builddir = .. 9 | 10 | # These options get passed to xgettext. 11 | XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ 12 | 13 | # This is the copyright holder that gets inserted into the header of the 14 | # $(DOMAIN).pot file. Set this to the copyright holder of the surrounding 15 | # package. (Note that the msgstr strings, extracted from the package's 16 | # sources, belong to the copyright holder of the package.) Translators are 17 | # expected to transfer the copyright for their translations to this person 18 | # or entity, or to disclaim their copyright. The empty string stands for 19 | # the public domain; in this case the translators are expected to disclaim 20 | # their copyright. 21 | COPYRIGHT_HOLDER = The ALSA Team 22 | 23 | # This is the email address or URL to which the translators shall report 24 | # bugs in the untranslated strings: 25 | # - Strings which are not entire sentences, see the maintainer guidelines 26 | # in the GNU gettext documentation, section 'Preparing Strings'. 27 | # - Strings which use unclear terms or require additional context to be 28 | # understood. 29 | # - Strings which make invalid assumptions about notation of date, time or 30 | # money. 31 | # - Pluralisation problems. 32 | # - Incorrect English spelling. 33 | # - Incorrect formatting. 34 | # It can be your email address, or a mailing list address where translators 35 | # can write to without being subscribed, or the URL of a web page through 36 | # which the translators can contact you. 37 | MSGID_BUGS_ADDRESS = 38 | 39 | # This is the list of locale categories, beyond LC_MESSAGES, for which the 40 | # message catalogs shall be used. It is usually empty. 41 | EXTRA_LOCALE_CATEGORIES = 42 | 43 | # This tells whether the $(DOMAIN).pot file contains messages with an 'msgctxt' 44 | # context. Possible values are "yes" and "no". Set this to yes if the 45 | # package uses functions taking also a message context, like pgettext(), or 46 | # if in $(XGETTEXT_OPTIONS) you define keywords with a context argument. 47 | USE_MSGCTXT = no 48 | 49 | # These options get passed to msgmerge. 50 | # Useful options are in particular: 51 | # --previous to keep previous msgids of translated messages, 52 | # --quiet to reduce the verbosity. 53 | MSGMERGE_OPTIONS = 54 | -------------------------------------------------------------------------------- /alsactl/alsactl.h: -------------------------------------------------------------------------------- 1 | extern int debugflag; 2 | extern int force_restore; 3 | extern int ignore_nocards; 4 | extern int do_lock; 5 | extern int use_syslog; 6 | extern char *command; 7 | extern char *statefile; 8 | extern char *lockfile; 9 | 10 | void info_(const char *fcn, long line, const char *fmt, ...); 11 | void error_(const char *fcn, long line, const char *fmt, ...); 12 | void cerror_(const char *fcn, long line, int cond, const char *fmt, ...); 13 | void dbg_(const char *fcn, long line, const char *fmt, ...); 14 | 15 | #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) 16 | #define info(...) do { info_(__FUNCTION__, __LINE__, __VA_ARGS__); } while (0) 17 | #define error(...) do { error_(__FUNCTION__, __LINE__, __VA_ARGS__); } while (0) 18 | #define cerror(cond, ...) do { cerror_(__FUNCTION__, __LINE__, (cond) != 0, __VA_ARGS__); } while (0) 19 | #define dbg(...) do { dbg_(__FUNCTION__, __LINE__, __VA_ARGS__); } while (0) 20 | #else 21 | #define info(args...) do { info_(__FUNCTION__, __LINE__, ##args); } while (0) 22 | #define error(args...) do { error_(__FUNCTION__, __LINE__, ##args); } while (0) 23 | #define cerror(cond, ...) do { error_(__FUNCTION__, __LINE__, (cond) != 0, ##args); } while (0) 24 | #define dbg(args...) do { dbg_(__FUNCTION__, __LINE__, ##args); } while (0) 25 | #endif 26 | 27 | int init(const char *file, const char *cardname); 28 | int state_lock(const char *file, int timeout); 29 | int state_unlock(int fd, const char *file); 30 | int save_state(const char *file, const char *cardname); 31 | int load_state(const char *file, const char *initfile, const char *cardname, 32 | int do_init); 33 | int power(const char *argv[], int argc); 34 | int monitor(const char *name); 35 | int state_daemon(const char *file, const char *cardname, int period, 36 | const char *pidfile); 37 | int state_daemon_kill(const char *pidfile, const char *cmd); 38 | 39 | /* utils */ 40 | 41 | int file_map(const char *filename, char **buf, size_t *bufsize); 42 | void file_unmap(void *buf, size_t bufsize); 43 | size_t line_width(const char *buf, size_t bufsize, size_t pos); 44 | void initfailed(int cardnumber, const char *reason, int exitcode); 45 | 46 | static inline int hextodigit(int c) 47 | { 48 | if (c >= '0' && c <= '9') 49 | c -= '0'; 50 | else if (c >= 'a' && c <= 'f') 51 | c = c - 'a' + 10; 52 | else if (c >= 'A' && c <= 'F') 53 | c = c - 'A' + 10; 54 | else 55 | return -1; 56 | return c; 57 | } 58 | 59 | #define ARRAY_SIZE(a) (sizeof (a) / sizeof (a)[0]) 60 | -------------------------------------------------------------------------------- /seq/aplaymidi/arecordmidi.1: -------------------------------------------------------------------------------- 1 | .TH ARECORDMIDI 1 "17 Sep 2007" 2 | 3 | .SH NAME 4 | arecordmidi \- record Standard MIDI Files 5 | 6 | .SH SYNOPSIS 7 | .B arecordmidi 8 | \-p client:port[,...] [options] midifile 9 | 10 | .SH DESCRIPTION 11 | .B arecordmidi 12 | is a command-line utility that records a Standard MIDI File from one or 13 | more ALSA sequencer ports. 14 | 15 | To stop recording, press Ctrl+C. 16 | 17 | .SH OPTIONS 18 | 19 | .TP 20 | .I \-h,\-\-help 21 | Prints a list of options. 22 | 23 | .TP 24 | .I \-V,\-\-version 25 | Prints the current version. 26 | 27 | .TP 28 | .I \-l,\-\-list 29 | Prints a list of possible input ports. 30 | 31 | .TP 32 | .I \-p,\-\-port=client:port,... 33 | Sets the sequencer port(s) from which events are recorded. 34 | 35 | A client can be specified by its number, its name, or a prefix of its 36 | name. A port is specified by its number; for port 0 of a client, the 37 | ":0" part of the port specification can be omitted. 38 | 39 | .TP 40 | .I \-b,\-\-bpm=beats 41 | Sets the musical tempo of the MIDI file, in beats per minute. 42 | The default value is 120 BPM. 43 | 44 | .TP 45 | .I \-f,\-\-fps=frames 46 | Sets the SMPTE resolution, in frames per second. 47 | Possible values are 24, 25, 29.97 (for 30 drop-frame), and 30. 48 | 49 | .TP 50 | .I \-t,\-\-ticks=ticks 51 | Sets the resolution of timestamps (ticks) in the MIDI file, 52 | in ticks per beat (when using musical tempo) or ticks per frame 53 | (when using SMPTE timing). 54 | The default value is 384 ticks/beat or 40 ticks/frame, respectively. 55 | 56 | .TP 57 | .I \-s,\-\-split\-channels 58 | Specifies that the data for each MIDI channel should be written to a 59 | separate track in the MIDI file. 60 | This will result in a "format 1" file. 61 | Otherwise, when there is only one track, 62 | .B arecordmidi 63 | will generate a "format 0" file. 64 | 65 | .TP 66 | .I \-m,\-\-metronome=client:port 67 | Plays a metronome signal on the specified sequencer port. 68 | 69 | Metronome sounds are played on channel 10, MIDI notes 33 & 34 (GM2/GS/XG 70 | metronome standard notes), with velocity 100 and duration 1. 71 | 72 | .TP 73 | .I \-i,\-\-timesig=numerator:denominator 74 | Sets the time signature for the MIDI file and metronome. 75 | 76 | The time signature is specified as usual with two numbers, representing 77 | the numerator and denominator of the time signature as it would be 78 | notated. The denominator must be a power of two. Both numbers should be 79 | separated by a colon. The time signature is 4:4 by default. 80 | 81 | .SH AUTHOR 82 | Clemens Ladisch 83 | -------------------------------------------------------------------------------- /bat/convert.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2015 Intel Corporation 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | void convert_uint8_to_float(void *buf, float *val, int samples) 22 | { 23 | int i; 24 | 25 | for (i = 0; i < samples; i++) 26 | val[i] = ((uint8_t *) buf)[i]; 27 | } 28 | 29 | void convert_int16_to_float(void *buf, float *val, int samples) 30 | { 31 | int i; 32 | 33 | for (i = 0; i < samples; i++) 34 | val[i] = ((int16_t *) buf)[i]; 35 | } 36 | 37 | void convert_int24_to_float(void *buf, float *val, int samples) 38 | { 39 | int i; 40 | int32_t tmp; 41 | 42 | for (i = 0; i < samples; i++) { 43 | tmp = ((uint8_t *) buf)[i * 3 + 2] << 24; 44 | tmp |= ((uint8_t *) buf)[i * 3 + 1] << 16; 45 | tmp |= ((uint8_t *) buf)[i * 3] << 8; 46 | tmp >>= 8; 47 | val[i] = tmp; 48 | } 49 | } 50 | 51 | void convert_int32_to_float(void *buf, float *val, int samples) 52 | { 53 | int i; 54 | 55 | for (i = 0; i < samples; i++) 56 | val[i] = ((int32_t *) buf)[i]; 57 | } 58 | 59 | void convert_float_to_uint8(float *val, void *buf, int samples, int channels) 60 | { 61 | int i, c, idx; 62 | 63 | for (i = 0; i < samples; i++) { 64 | for (c = 0; c < channels; c++) { 65 | idx = i * channels + c; 66 | ((uint8_t *) buf)[idx] = (uint8_t) val[idx]; 67 | } 68 | } 69 | } 70 | 71 | void convert_float_to_int16(float *val, void *buf, int samples, int channels) 72 | { 73 | int i, c, idx; 74 | 75 | for (i = 0; i < samples; i++) { 76 | for (c = 0; c < channels; c++) { 77 | idx = i * channels + c; 78 | ((int16_t *) buf)[idx] = (int16_t) val[idx]; 79 | } 80 | } 81 | } 82 | 83 | void convert_float_to_int24(float *val, void *buf, int samples, int channels) 84 | { 85 | int i, c, idx_f, idx_i; 86 | int32_t val_f_i; 87 | 88 | for (i = 0; i < samples; i++) { 89 | for (c = 0; c < channels; c++) { 90 | idx_f = i * channels + c; 91 | idx_i = 3 * idx_f; 92 | val_f_i = (int32_t) val[idx_f]; 93 | ((int8_t *) buf)[idx_i + 0] = 94 | (int8_t) (val_f_i & 0xff); 95 | ((int8_t *) buf)[idx_i + 1] = 96 | (int8_t) ((val_f_i >> 8) & 0xff); 97 | ((int8_t *) buf)[idx_i + 2] = 98 | (int8_t) ((val_f_i >> 16) & 0xff); 99 | } 100 | } 101 | } 102 | 103 | void convert_float_to_int32(float *val, void *buf, int samples, int channels) 104 | { 105 | int i, c, idx; 106 | 107 | for (i = 0; i < samples; i++) { 108 | for (c = 0; c < channels; c++) { 109 | idx = i * channels + c; 110 | ((int32_t *) buf)[idx] = (int32_t) val[idx]; 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /alsaloop/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #DBG="gdb --args " 4 | #DBG="strace" 5 | #DBG="valgrind --leak-check=full" 6 | ARGS= 7 | CFGFILE="/tmp/alsaloop.test.cfg" 8 | 9 | test1() { 10 | echo "TEST1" 11 | $DBG ./alsaloop -C hw:1,0 -P plughw:0,0 \ 12 | --tlatency 50000 \ 13 | --mixer "name='Master Playback Volume'@name='Master Playback Volume'" \ 14 | --mixer "name='Master Playback Switch'@name='Master Playback Switch'" \ 15 | --mixer "name='PCM Playback Volume'" \ 16 | --ossmixer "Master@VOLUME" \ 17 | --ossmixer "PCM@PCM" \ 18 | $ARGS 19 | } 20 | 21 | test2() { 22 | echo "TEST2" 23 | cat > $CFGFILE < $CFGFILE < $CFGFILE < 28 | #include 29 | #include "pink.h" 30 | 31 | /************************************************************/ 32 | /* Calculate pseudo-random 32 bit number based on linear congruential method. */ 33 | static unsigned long generate_random_number( void ) 34 | { 35 | static unsigned long rand_seed = 22222; /* Change this for different random sequences. */ 36 | rand_seed = (rand_seed * 196314165) + 907633515; 37 | return rand_seed; 38 | } 39 | 40 | /* Setup PinkNoise structure for N rows of generators. */ 41 | void initialize_pink_noise( pink_noise_t *pink, int num_rows ) 42 | { 43 | int i; 44 | long pmax; 45 | pink->pink_index = 0; 46 | pink->pink_index_mask = (1<pink_scalar = 1.0f / pmax; 50 | /* Initialize rows. */ 51 | for( i=0; ipink_rows[i] = 0; 52 | pink->pink_running_sum = 0; 53 | } 54 | 55 | /* generate Pink noise values between -1.0 and +1.0 */ 56 | float generate_pink_noise_sample( pink_noise_t *pink ) 57 | { 58 | long new_random; 59 | long sum; 60 | float output; 61 | 62 | /* Increment and mask index. */ 63 | pink->pink_index = (pink->pink_index + 1) & pink->pink_index_mask; 64 | 65 | /* If index is zero, don't update any random values. */ 66 | if( pink->pink_index != 0 ) 67 | { 68 | /* Determine how many trailing zeros in PinkIndex. */ 69 | /* This algorithm will hang if n==0 so test first. */ 70 | int num_zeros = 0; 71 | int n = pink->pink_index; 72 | while( (n & 1) == 0 ) 73 | { 74 | n = n >> 1; 75 | num_zeros++; 76 | } 77 | 78 | /* Replace the indexed ROWS random value. 79 | * Subtract and add back to Running_sum instead of adding all the random 80 | * values together. Only one changes each time. 81 | */ 82 | pink->pink_running_sum -= pink->pink_rows[num_zeros]; 83 | new_random = ((long)generate_random_number()) >> PINK_RANDOM_SHIFT; 84 | pink->pink_running_sum += new_random; 85 | pink->pink_rows[num_zeros] = new_random; 86 | } 87 | 88 | /* Add extra white noise value. */ 89 | new_random = ((long)generate_random_number()) >> PINK_RANDOM_SHIFT; 90 | sum = pink->pink_running_sum + new_random; 91 | 92 | /* Scale to range of -1.0 to 0.9999. */ 93 | output = pink->pink_scalar * sum; 94 | 95 | return output; 96 | } 97 | -------------------------------------------------------------------------------- /iecset/iecset.1: -------------------------------------------------------------------------------- 1 | .TH iecset 1 "23 Oct 2003" 2 | .SH NAME 3 | iecset \- Set or dump IEC958 status bits 4 | 5 | .SH SYNOPSIS 6 | \fBiecset\fP [\fIoptions\fP] [\fIcmd\fP \fIarg\fP...] 7 | 8 | .SH DESCRIPTION 9 | \fBiecset\fP is a small utility to set or dump the IEC958 (or so-called 10 | "S/PDIF") status bits of the specified sound card via ALSA control API. 11 | 12 | When \fBiecset\fP is started without arguments except for options, 13 | it will show the current IEC958 status in a human-readable form. 14 | When the commands are given in the arguments, they are parsed 15 | and the IEC958 status bits are updated. The resultant status is 16 | shown as well. 17 | 18 | The commands consist of the command directive and the argument. 19 | As the boolean argument, \fIyes\fP, \fIno\fP, \fItrue\fP, \fIfalse\fP, 20 | or a digit number is allowed. 21 | 22 | .SH EXAMPLES 23 | .TP 24 | .BI iecset\ \-Dhw:1 25 | Displays the current IEC958 status bits on the second card. 26 | This is equivalent with \fI\-c 1\fP. 27 | .TP 28 | .BI iecset\ \-x 29 | Displays the current IEC958 status bits in a style of the arguments 30 | for the PCM stream. The output string can be passed to the \fIiec958\fP 31 | (or \fIspdif\fP) PCM type as the optional argument. 32 | .TP 33 | .BI iecset\ pro\ off\ audio\ off 34 | Sets the current status to the consumer-mode and turns on the 35 | non-audio bit. The modified status will be shown, too. 36 | 37 | .SH OPTIONS 38 | .TP 39 | \fI\-D\fP device 40 | Specifies the device name of the control to open 41 | .TP 42 | \fI\-c\fP card 43 | Specifies the card index to open. Equivalent with \fI\-Dhw:x\fP. 44 | .TP 45 | \fI\-n\fP index 46 | Specifies the IEC958 control element index, in case you have multiple 47 | IEC958 devices and need to choose one of them. 48 | .TP 49 | \fI\-x\fP 50 | Dumps the status in the form of AESx bytes. 51 | .TP 52 | \fI\-i\fP 53 | Reads the command sequences from stdin. 54 | Each line has single command. 55 | 56 | .SH COMMANDS 57 | .TP 58 | \fIprofessional\fP 59 | The professional mode (true) or consumer mode (false). 60 | 61 | .TP 62 | \fIaudio\fP 63 | The audio mode (true) or non-audio mode (false). 64 | 65 | .TP 66 | \fIrate\fP 67 | The sample rate in Hz. 68 | 69 | .TP 70 | \fIemphasis\fP 71 | The emphasis: 0 = none, 1 = 50/15us, 2 = CCITT. 72 | 73 | .TP 74 | \fIlock\fP 75 | Rate lock: locked (true), unlocked (false). 76 | This command is for the professional mode only. 77 | 78 | .TP 79 | \fIsbits\fP 80 | Sample bits: 2 = 20bit, 4 = 24bit, 6 = undefined. 81 | This command is for the professional mode only. 82 | 83 | .TP 84 | \fIwordlength\fP 85 | Wordlength: 0 = No, 2 = 22-18 bit, 4 = 23-19 bit, 5 = 24-20 bit, 6 = 20-16 bit. 86 | This command is for the professional mode only. 87 | 88 | .TP 89 | \fIcategory\fP 90 | Category: the value is from 0 to 0x7f. 91 | This command is for the consumer mode only. 92 | 93 | .TP 94 | \fIcopyright\fP 95 | Copyright: copyrighted (true), non-copyrighted (false). 96 | This command is for the consumer mode only. 97 | 98 | .TP 99 | \fIoriginal\fP 100 | Original flag: original (true), 1st generation (false). 101 | This command is for the consumer mode only. 102 | 103 | .SH AUTHOR 104 | Takashi Iwai 105 | -------------------------------------------------------------------------------- /topology/topology.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright(c) 2014-2015 Intel Corporation 3 | Copyright(c) 2010-2011 Texas Instruments Incorporated, 4 | All rights reserved. 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of version 2 of the GNU General Public License as 8 | published by the Free Software Foundation. 9 | 10 | This program is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 18 | The full GNU General Public License is included in this distribution 19 | in the file called LICENSE.GPL. 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include "gettext.h" 37 | 38 | static snd_output_t *log; 39 | 40 | static void usage(char *name) 41 | { 42 | printf( 43 | _("Usage: %s [OPTIONS]...\n" 44 | "\n" 45 | "-h, --help help\n" 46 | "-c, --compile=FILE compile file\n" 47 | "-v, --verbose=LEVEL set verbosity level (0...1)\n" 48 | "-o, --output=FILE set output file\n" 49 | ), name); 50 | } 51 | 52 | int main(int argc, char *argv[]) 53 | { 54 | snd_tplg_t *snd_tplg; 55 | static const char short_options[] = "hc:v:o:"; 56 | static const struct option long_options[] = { 57 | {"help", 0, 0, 'h'}, 58 | {"verbose", 0, 0, 'v'}, 59 | {"compile", 0, 0, 'c'}, 60 | {"output", 0, 0, 'o'}, 61 | {0, 0, 0, 0}, 62 | }; 63 | char *source_file = NULL, *output_file = NULL; 64 | int c, err, verbose = 0, option_index; 65 | 66 | #ifdef ENABLE_NLS 67 | setlocale(LC_ALL, ""); 68 | textdomain(PACKAGE); 69 | #endif 70 | 71 | err = snd_output_stdio_attach(&log, stderr, 0); 72 | assert(err >= 0); 73 | 74 | while ((c = getopt_long(argc, argv, short_options, long_options, &option_index)) != -1) { 75 | switch (c) { 76 | case 'h': 77 | usage(argv[0]); 78 | return 0; 79 | case 'v': 80 | verbose = atoi(optarg); 81 | break; 82 | case 'c': 83 | source_file = optarg; 84 | break; 85 | case 'o': 86 | output_file = optarg; 87 | break; 88 | default: 89 | fprintf(stderr, _("Try `%s --help' for more information.\n"), argv[0]); 90 | return 1; 91 | } 92 | } 93 | 94 | if (source_file == NULL || output_file == NULL) { 95 | usage(argv[0]); 96 | return 1; 97 | } 98 | 99 | snd_tplg = snd_tplg_new(); 100 | if (snd_tplg == NULL) { 101 | fprintf(stderr, _("failed to create new topology context\n")); 102 | return 1; 103 | } 104 | 105 | snd_tplg_verbose(snd_tplg, verbose); 106 | 107 | err = snd_tplg_build_file(snd_tplg, source_file, output_file); 108 | if (err < 0) { 109 | fprintf(stderr, _("failed to compile context %s\n"), source_file); 110 | snd_tplg_free(snd_tplg); 111 | return 1; 112 | } 113 | 114 | snd_tplg_free(snd_tplg); 115 | return 0; 116 | } 117 | 118 | -------------------------------------------------------------------------------- /alsaconf/alsaconf.8: -------------------------------------------------------------------------------- 1 | .\" Hey, EMACS: -*- nroff -*- 2 | .\" alsaconf.8 is copyright 2003 by Jordi Mallach 3 | .\" 4 | .\" This is free documentation, see the latest version of the GNU 5 | .\" General Public License for copying conditions. There is NO warranty. 6 | .TH ALSACONF 8 "February 23, 2003" 7 | 8 | .SH NAME 9 | alsaconf \- configuration tool for the Advanced Linux Sound Architecture 10 | 11 | .SH SYNOPSIS 12 | .B alsaconf 13 | .RI [ options ] 14 | 15 | .SH DESCRIPTION 16 | This manual page documents briefly the 17 | .B alsaconf 18 | command. 19 | This manual page was written for the Debian distribution because the 20 | original program does not have a manual page. 21 | .PP 22 | \fBAlsaconf\fP is a simple shell script which tries to detect the sound cards 23 | on your system and writes a suitable configuration file for ALSA. It will try 24 | to guess what GNU/Linux distribution you're running, and will act accordingly 25 | to the standards of that distribution, if specific support is available. 26 | .PP 27 | Alsaconf will write a module-init-tools (or modutils) snippet which can be then used by module-init-tools (or modutils) 28 | to load the correct parameters for your sound card. 29 | 30 | .SH OPTIONS 31 | Alsaconf accepts the following options: 32 | .TP 33 | .B \-c, \-\-config file 34 | Specify the module config file. 35 | As default, 36 | .B alsaconf 37 | probes the available config file automatically. 38 | .TP 39 | .B \-d, \-\-devmode mode 40 | Set the device mode for the ALSA devices (default = 0666). 41 | This option is obsolete in the recent ALSA version. 42 | .TP 43 | .B \-g, \-\-gid gid 44 | Set the gid for the ALSA devices (default = 0). 45 | This option is obsolete in the recent ALSA version. 46 | .TP 47 | .B \-h, \-\-help 48 | Displays this help text. 49 | .TP 50 | .B \-L, \-\-log file 51 | Logging on the given file. The log is appended to the file. 52 | This option is for debugging purpose only. 53 | .TP 54 | .B \-l, \-\-legacy 55 | Check only for legacy non-isapnp cards. 56 | .TP 57 | .B \-m, \-\-modinfo 58 | Read module descriptions instead of reading a card database. 59 | .TP 60 | .B \-P, \-\-listprobe 61 | List the supported legacy card modules. 62 | .TP 63 | .B \-p, \-\-probe card-name 64 | Probe a legacy non-isapnp card and print module options. 65 | .TP 66 | .B \-r, \-\-strict 67 | Set strict device mode (equiv. with \-g 17 \-d 0660). 68 | This option is obsolete in the recent ALSA version. 69 | .TP 70 | .B \-s, \-\-sound\-wav\-file 71 | Use the specified wav file as a test sound. 72 | .TP 73 | .B \-u, \-\-uid uid 74 | Set the uid for the ALSA devices (default = 0). 75 | This option is obsolete in the recent ALSA version. 76 | 77 | .SH DEBIAN SPECIFIC 78 | In Debian, the default gid of the device files is 29 (corresponding to the 79 | audio group) and the default device mode is 0660. 80 | 81 | For the ALSA base package, see also 82 | .I /usr/share/doc/alsa\-base/ 83 | 84 | .SH SEE ALSO 85 | \fB 86 | alsamixer(1), 87 | amixer(1), 88 | aplay(1), 89 | arecord(1) 90 | \fP 91 | 92 | .SH HOMEPAGE 93 | http://www.alsa\-project.org/ 94 | 95 | .SH AUTHOR 96 | The alsaconf script was written by 97 | Takashi Iwai , 98 | Bernd Kaindl and 99 | Jan Ondrej (SAL) 100 | 101 | This manual page was written by Jordi Mallach , 102 | for the Debian system (but may be used by others). 103 | -------------------------------------------------------------------------------- /alsactl/lock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Linux Sound Architecture Control Program 3 | * Copyright (c) by Jaroslav Kysela 4 | * 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | */ 21 | 22 | #include "aconfig.h" 23 | #include "version.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include "alsactl.h" 32 | 33 | static int state_lock_(const char *file, int lock, int timeout, int _fd) 34 | { 35 | int fd = -1, err = 0; 36 | struct flock lck; 37 | struct stat st; 38 | char lcktxt[12]; 39 | char *nfile = lockfile; 40 | 41 | if (do_lock <= 0) 42 | return 0; 43 | 44 | lck.l_type = lock ? F_WRLCK : F_UNLCK; 45 | lck.l_whence = SEEK_SET; 46 | lck.l_start = 0; 47 | lck.l_len = 11; 48 | lck.l_pid = 0; 49 | if (lock) { 50 | snprintf(lcktxt, sizeof(lcktxt), "%10li\n", (long)getpid()); 51 | } else { 52 | snprintf(lcktxt, sizeof(lcktxt), "%10s\n", ""); 53 | fd = _fd; 54 | } 55 | while (fd < 0 && timeout-- > 0) { 56 | fd = open(nfile, O_RDWR); 57 | if (!lock && fd < 0) { 58 | err = -EIO; 59 | goto out; 60 | } 61 | if (fd < 0) { 62 | fd = open(nfile, O_RDWR|O_CREAT|O_EXCL, 0644); 63 | if (fd < 0) { 64 | if (errno == EBUSY || errno == EAGAIN) { 65 | sleep(1); 66 | timeout--; 67 | } else { 68 | err = -errno; 69 | goto out; 70 | } 71 | } 72 | } 73 | } 74 | if (fd < 0 && timeout <= 0) { 75 | err = -EBUSY; 76 | goto out; 77 | } 78 | if (fstat(fd, &st) < 0) { 79 | err = -errno; 80 | goto out; 81 | } 82 | if (st.st_size != 11 || !lock) { 83 | if (write(fd, lcktxt, 11) != 11) { 84 | err = -EIO; 85 | goto out; 86 | } 87 | if (lock && lseek(fd, 0, SEEK_SET)) { 88 | err = -errno; 89 | goto out; 90 | } 91 | } 92 | while (timeout > 0) { 93 | if (fcntl(fd, F_SETLK, &lck) < 0) { 94 | sleep(1); 95 | timeout--; 96 | } else { 97 | break; 98 | } 99 | } 100 | if (timeout <= 0) { 101 | err = -EBUSY; 102 | goto out; 103 | } 104 | if (lock) { 105 | if (write(fd, lcktxt, 11) != 11) { 106 | err = -EIO; 107 | goto out; 108 | } 109 | return fd; 110 | } 111 | err = 0; 112 | 113 | out: 114 | if (fd >= 0) 115 | close(fd); 116 | return err; 117 | } 118 | 119 | int state_lock(const char *file, int timeout) 120 | { 121 | int err; 122 | 123 | err = state_lock_(file, 1, timeout, -1); 124 | if (err < 0) 125 | error("file %s lock error: %s", file, strerror(-err)); 126 | return err; 127 | } 128 | 129 | int state_unlock(int _fd, const char *file) 130 | { 131 | int err; 132 | 133 | err = state_lock_(file, 0, 10, _fd); 134 | if (err < 0) 135 | error("file %s unlock error: %s", file, strerror(-err)); 136 | return err; 137 | } 138 | -------------------------------------------------------------------------------- /alsamixer/utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * utils.c - multibyte-string helpers 3 | * Copyright (c) Clemens Ladisch 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #define _XOPEN_SOURCE 20 | #include "aconfig.h" 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "utils.h" 26 | 27 | /* 28 | * mbs_at_width - compute screen position in a string 29 | * 30 | * For displaying strings on the screen, we have to know how many character 31 | * cells are occupied. This function calculates the position in a multibyte 32 | * string that is at a desired position. 33 | * 34 | * Parameters: 35 | * s: the string 36 | * width: on input, the desired number of character cells; on output, the actual 37 | * position, in character cells, of the return value 38 | * dir: -1 or 1; in which direction to round if a multi-column character goes 39 | * over the desired width 40 | * 41 | * Return value: 42 | * Pointer to the place in the string that is as near the desired width as 43 | * possible. If the string is too short, the return value points to the 44 | * terminating zero. If the last character is a multi-column character that 45 | * goes over the desired width, the return value may be one character cell 46 | * earlier or later than desired, depending on the dir parameter. 47 | * In any case, the return value points after any zero-width characters that 48 | * follow the last character. 49 | */ 50 | const char *mbs_at_width(const char *s, int *width, int dir) 51 | { 52 | size_t len; 53 | wchar_t wc; 54 | int bytes; 55 | int width_so_far, w; 56 | 57 | if (*width <= 0) 58 | return s; 59 | mbtowc(NULL, NULL, 0); /* reset shift state */ 60 | len = strlen(s); 61 | width_so_far = 0; 62 | while (len && (bytes = mbtowc(&wc, s, len)) > 0) { 63 | w = wcwidth(wc); 64 | if (width_so_far + w > *width && dir < 0) 65 | break; 66 | if (w >= 0) 67 | width_so_far += w; 68 | s += bytes; 69 | len -= bytes; 70 | if (width_so_far >= *width) { 71 | while (len && (bytes = mbtowc(&wc, s, len)) > 0) { 72 | w = wcwidth(wc); 73 | if (w != 0) 74 | break; 75 | s += bytes; 76 | len -= bytes; 77 | } 78 | break; 79 | } 80 | } 81 | *width = width_so_far; 82 | return s; 83 | } 84 | 85 | /* 86 | * get_mbs_width - compute screen width of a string 87 | */ 88 | unsigned int get_mbs_width(const char *s) 89 | { 90 | int width; 91 | 92 | width = INT_MAX; 93 | mbs_at_width(s, &width, 1); 94 | return width; 95 | } 96 | 97 | /* 98 | * get_max_mbs_width - get width of longest string in an array 99 | */ 100 | unsigned int get_max_mbs_width(const char *const *s, unsigned int count) 101 | { 102 | unsigned int max_width, i, len; 103 | 104 | max_width = 0; 105 | for (i = 0; i < count; ++i) { 106 | len = get_mbs_width(s[i]); 107 | if (len > max_width) 108 | max_width = len; 109 | } 110 | return max_width; 111 | } 112 | -------------------------------------------------------------------------------- /bat/alsabat-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # default devices 4 | dev_playback="default" 5 | dev_capture="default" 6 | 7 | bin="alsabat" 8 | commands="$bin -P $dev_playback -C $dev_capture" 9 | 10 | file_sin_mono="default_mono.wav" 11 | file_sin_dual="default_dual.wav" 12 | logdir="tmp" 13 | 14 | # frequency range of signal 15 | maxfreq=16547 16 | minfreq=17 17 | 18 | # features passes vs. features all 19 | feature_pass=0 20 | feature_cnt=0 21 | 22 | init_counter () { 23 | feature_pass=0 24 | feature_all=0 25 | } 26 | 27 | evaluate_result () { 28 | feature_cnt=$((feature_cnt+1)) 29 | if [ $1 -eq 0 ]; then 30 | feature_pass=$((feature_pass+1)) 31 | echo "pass" 32 | else 33 | echo "fail" 34 | fi 35 | } 36 | 37 | print_result () { 38 | echo "[$feature_pass/$feature_cnt] features passes." 39 | } 40 | 41 | feature_test () { 42 | echo "============================================" 43 | echo "$feature_cnt: ALSA $2" 44 | echo "-------------------------------------------" 45 | echo "$commands $1 --log=$logdir/$feature_cnt.log" 46 | $commands $1 --log=$logdir/$feature_cnt.log 47 | evaluate_result $? 48 | echo "$commands $1" >> $logdir/$((feature_cnt-1)).log 49 | } 50 | 51 | # test items 52 | feature_list_test () { 53 | init_counter 54 | 55 | commands="$bin" 56 | feature_test "-c1 --saveplay $file_sin_mono" \ 57 | "generate mono wav file with default params" 58 | feature_test "-c2 --saveplay $file_sin_dual" \ 59 | "generate dual wav file with default params" 60 | sleep 5 61 | feature_test "-P $dev_playback" "single line mode, playback" 62 | feature_test "-C $dev_capture --standalone" "single line mode, capture" 63 | 64 | commands="$bin -P $dev_playback -C $dev_capture" 65 | feature_test "--file $file_sin_mono" "play mono wav file and detect" 66 | feature_test "--file $file_sin_dual" "play dual wav file and detect" 67 | feature_test "-c1" "configurable channel number: 1" 68 | feature_test "-c2 -F $minfreq:$maxfreq" "configurable channel number: 2" 69 | feature_test "-r44100" "configurable sample rate: 44100" 70 | feature_test "-r48000" "configurable sample rate: 48000" 71 | feature_test "-n10000" "configurable duration: in samples" 72 | feature_test "-n2.5s" "configurable duration: in seconds" 73 | feature_test "-f U8" "configurable data format: U8" 74 | feature_test "-f S16_LE" "configurable data format: S16_LE" 75 | feature_test "-f S24_3LE" "configurable data format: S24_3LE" 76 | feature_test "-f S32_LE" "configurable data format: S32_LE" 77 | feature_test "-f cd" "configurable data format: cd" 78 | feature_test "-f dat" "configurable data format: dat" 79 | feature_test "-F $maxfreq --standalone" \ 80 | "standalone mode: play and capture" 81 | latestfile=`ls -t1 /tmp/bat.wav.* | head -n 1` 82 | feature_test "--local -F $maxfreq --file $latestfile" \ 83 | "local mode: analyze local file" 84 | feature_test "--roundtriplatency" \ 85 | "round trip latency test" 86 | feature_test "--snr-db 26" \ 87 | "noise detect threshold in SNR(dB)" 88 | feature_test "--snr-pc 5" \ 89 | "noise detect threshold in noise percentage(%)" 90 | 91 | print_result 92 | } 93 | 94 | echo "*******************************************" 95 | echo " BAT Test " 96 | echo "-------------------------------------------" 97 | 98 | # get device 99 | echo "usage:" 100 | echo " $0 " 101 | echo " $0 " 102 | 103 | if [ $# -eq 2 ]; then 104 | dev_playback=$1 105 | dev_capture=$2 106 | elif [ $# -eq 1 ]; then 107 | dev_playback=$1 108 | dev_capture=$1 109 | fi 110 | 111 | echo "current setting:" 112 | echo " $0 $dev_playback $dev_capture" 113 | 114 | # run 115 | mkdir -p $logdir 116 | feature_list_test 117 | 118 | echo "*******************************************" 119 | -------------------------------------------------------------------------------- /seq/aconnect/aconnect.1: -------------------------------------------------------------------------------- 1 | .TH aconnect 1 "August 31, 2000" 2 | .de EX 3 | .nf 4 | .ft CW 5 | .. 6 | .de EE 7 | .ft R 8 | .fi 9 | .. 10 | .SH NAME 11 | aconnect \- ALSA sequencer connection manager 12 | 13 | .SH SYNOPSIS 14 | .B aconnect 15 | [\-d] [\-options] sender receiver 16 | .br 17 | .B aconnect 18 | \-i|\-o [\-options] 19 | .br 20 | .B aconnect 21 | \-x 22 | 23 | .SH DESCRIPTION 24 | .B aconnect 25 | is a utility to connect and disconnect two existing ports on ALSA sequencer 26 | system. 27 | The ports with the arbitrary subscription permission, such as created 28 | by 29 | .B aseqview(1), 30 | can be connected to any (MIDI) device ports using 31 | .B aconnect. 32 | For example, to connect from port 64:0 to 65:0, run as follows: 33 | .IP "" 4 34 | % aconnect 64:0 65:0 35 | .PP 36 | The connection is one-way, and the whole data to the sender port (64:0) 37 | is redirected to the receiver port (65:0). When another port (e.g. 65:1) 38 | is attached to the same sender port, the data is sent to both receiver 39 | ports. 40 | For disconnection, use 41 | .B \-d 42 | option. 43 | .sp 44 | .EX 45 | % aconnect \-d 64:0 65:0 46 | .EE 47 | .PP 48 | The address can be given using the client's name. 49 | .sp 50 | .EX 51 | % aconnect External:0 Emu8000:1 52 | .EE 53 | .PP 54 | Then the port 0 of the client matching with the string "External" is 55 | connected to the port 1 of the client matching with the "Emu8000". 56 | .PP 57 | Another function of 58 | .B aconnect 59 | is to list the present ports 60 | on the given condition. 61 | The input ports, which may become 62 | .I sender 63 | ports, can be listed with 64 | .B \-i 65 | option. 66 | .sp 67 | .EX 68 | % aconnect \-i 69 | client 0: 'System' [type=kernel] 70 | 0 'Timer ' 71 | 1 'Announce ' 72 | client 64: 'External MIDI\-0' [type=kernel] 73 | 0 'MIDI 0\-0 ' 74 | .EE 75 | .PP 76 | Similarly, to see the output ports, use 77 | .B \-o 78 | flag. 79 | .PP 80 | You can remove all existing exported connections using 81 | .B \-x 82 | option. This function is useful for terminating the ALSA drivers, 83 | because the modules with sequencer connections cannot be unloaded 84 | unless their connections are removed. 85 | 86 | .SH OPTIONS 87 | .SS CONNECTION MANAGEMENT 88 | .TP 89 | .B \-d, \-\-disconnect 90 | Disconnect the given subscription. 91 | .TP 92 | .B \-e, \-\-exclusive 93 | Connect ports with exclusive mode. 94 | Both sender and receiver ports can be no longer connected by any other ports. 95 | .TP 96 | .B \-r, \-\-real queue 97 | Convert time-stamps of event packets to the current value of the given 98 | .I real-time 99 | queue. 100 | This is option is, however, not so useful, since 101 | the receiver port must use (not necessarily own) the specified queue. 102 | .TP 103 | .B \-t, \-\-tick queue 104 | Like 105 | .B \-r 106 | option, but 107 | time-stamps are converted to the current value of the given 108 | .I tick 109 | queue. 110 | 111 | .SS LIST PORTS 112 | .TP 113 | .B \-i, \-\-input 114 | List existing input (readable) ports. 115 | This option is exclusive to 116 | .B \-o. 117 | .TP 118 | .B \-o, \-\-output 119 | List existing output (writable) ports. 120 | This option is exclusive to 121 | .B \-i. 122 | .TP 123 | .B \-l, \-\-list 124 | List the current connection status. The connected and connecting ports 125 | from/to each port are listed together. 126 | The suffix flag 127 | .B [ex] 128 | means the connection is exclusive. 129 | The suffix flag 130 | .B [real:#] 131 | and 132 | .B [tick:#] 133 | mean the connection includes real-time and tick conversion on the listed 134 | queue, respectively. 135 | 136 | .SS REMOVE ALL CONNECTIONS 137 | .TP 138 | .B \-x, \-\-removeall 139 | Remove all exported connections. 140 | 141 | .SH "SEE ALSO" 142 | aseqnet(1), aseqview(1) 143 | 144 | .SH AUTHOR 145 | Takashi Iwai 146 | -------------------------------------------------------------------------------- /alsaloop/effect-sweep.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Bandpass filter sweep effect 3 | * Copyright (c) Maarten de Boer 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | struct effect_private { 25 | /* filter the sweep variables */ 26 | float lfo,dlfo,fs,fc,BW,C,D,a0,a1,a2,b1,b2,*x[3],*y[3]; 27 | float lfo_depth, lfo_center; 28 | unsigned int channels; 29 | }; 30 | 31 | static int effect_init(struct lookback *loopback, 32 | void *private_data, 33 | snd_pcm_access_t access, 34 | unsigned int channels, 35 | unsigned int rate, 36 | snd_pcm_format_t format) 37 | { 38 | struct effect_private *priv = private_data; 39 | int i; 40 | 41 | #if __BYTE_ORDER == __LITTLE_ENDIAN 42 | if (format != SND_PCM_FORMAT_S16_LE) 43 | return -EIO; 44 | #elif __BYTE_ORDER == __BIG_ENDIAN 45 | if (format != SND_PCM_FORMAT_S16_BE) 46 | return -EIO; 47 | #else 48 | return -EIO; 49 | #endif 50 | priv->fs = (float) rate; 51 | priv->channels = channels; 52 | for (i = 0; i < 3; i++) { 53 | priv->x[i] = calloc(channels * sizeof(float)); 54 | priv->y[i] = calloc(channels * sizeof(float)); 55 | } 56 | return 0; 57 | } 58 | 59 | static int effect_done(struct loopback *loopback, 60 | void *private_data) 61 | { 62 | struct effect_private *priv = private_data; 63 | int i; 64 | 65 | for (i = 0; i < 3; i++) { 66 | free(priv->x[i]); 67 | free(priv->y[i]); 68 | } 69 | return 0; 70 | } 71 | 72 | static int effect_apply(struct loopback *loopback, 73 | void *private_data, 74 | const snd_pcm_channel_area_t *areas, 75 | snd_uframes_t offset, 76 | snd_uframes_t frames) 77 | { 78 | struct effect_private *priv = private_data; 79 | short *samples = (short*)areas[0].addr + offset*priv->channels; 80 | snd_uframes_t i; 81 | 82 | for (i=0; i < frames; i++) { 83 | int chn; 84 | 85 | fc = sin(priv->lfo)*priv->lfo_depth+priv->lfo_center; 86 | priv->lfo += priv->dlfo; 87 | if (priv->lfo>2.*M_PI) priv->lfo -= 2.*M_PI; 88 | priv->C = 1./tan(M_PI*priv->BW/priv->fs); 89 | priv->D = 2.*cos(2*M_PI*fc/fs); 90 | priv->a0 = 1./(1.+priv->C); 91 | priv->a1 = 0; 92 | priv->a2 = -priv->a0; 93 | priv->b1 = -priv->C*priv->D*a0; 94 | priv->b2 = (priv->C-1)*priv->a0; 95 | 96 | for (chn=0; chn < priv->channels; chn++) 97 | { 98 | priv->x[chn][2] = priv->x[chn][1]; 99 | priv->x[chn][1] = priv->x[chn][0]; 100 | 101 | priv->y[chn][2] = priv->y[chn][1]; 102 | priv->y[chn][1] = priv->y[chn][0]; 103 | 104 | priv->x[chn][0] = samples[i*channels+chn]; 105 | priv->y[chn][0] = priv->a0*priv->x[0][chn] 106 | + priv->a1*priv->x[1][chn] + priv->a2*x[2][chn] 107 | - priv->b1*priv->y[1][chn] - priv->b2*y[2][chn]; 108 | samples[i*channels+chn] = priv->y[chn][0]; 109 | } 110 | } 111 | return 0; 112 | } 113 | 114 | void effect_init_sweep(void) 115 | { 116 | struct effect_private *priv; 117 | 118 | priv = register_effect(effect_init, 119 | effect_apply, 120 | effect_done, 121 | sizeof(struct effectprivate)); 122 | if (priv) { 123 | priv->lfo_center = 2000.; 124 | priv->lfo_depth = 1800.; 125 | priv->lfo_freq = 0.2; 126 | priv->BW = 50; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /amidi/amidi.1: -------------------------------------------------------------------------------- 1 | .TH AMIDI 1 "26 Jun 2006" 2 | 3 | .SH NAME 4 | amidi \- read from and write to ALSA RawMIDI ports 5 | 6 | .SH SYNOPSIS 7 | \fBamidi\fP [\fI\-p port\fP] [\fI\-s file\fP | \fI\-S data\fP] 8 | [\fI\-r file\fP] [\fI\-d\fP] [\fI\-t seconds\fP] [\fI\-a\fP] 9 | 10 | .SH DESCRIPTION 11 | .B amidi 12 | is a command-line utility which allows one to receive and send 13 | SysEx (system exclusive) data from/to external MIDI devices. 14 | It can also send any other MIDI commands. 15 | 16 | .B amidi 17 | handles only files containing raw MIDI commands, without timing 18 | information. 19 | .B amidi 20 | does not support Standard MIDI (.mid) files, but 21 | .B aplaymidi(1) 22 | and 23 | .B arecordmidi(1) 24 | do. 25 | 26 | .SH OPTIONS 27 | 28 | Use the 29 | .I \-h, 30 | .I \-V, 31 | .I \-l, 32 | or 33 | .I \-L 34 | options to display information; 35 | or use at least one of the 36 | .I \-s, 37 | .I \-r, 38 | .I \-S, 39 | or 40 | .I \-d 41 | options to specify what data to send or receive. 42 | 43 | .TP 44 | .I \-h, \-\-help 45 | Help: prints a list of options. 46 | 47 | .TP 48 | .I \-V, \-\-version 49 | Prints the current version. 50 | 51 | .TP 52 | .I \-l, \-\-list\-devices 53 | Prints a list of all hardware MIDI ports. 54 | 55 | .TP 56 | .I \-L, \-\-list\-rawmidis 57 | Prints all RawMIDI definitions. 58 | (used when debugging configuration files) 59 | 60 | .TP 61 | .I \-p, \-\-port=name 62 | Sets the name of the ALSA RawMIDI port to use. 63 | If this is not specified, 64 | .B amidi 65 | uses the default port defined in the configuration file 66 | (the default for this is port 0 on card 0, which may not exist). 67 | 68 | .TP 69 | .I \-s, \-\-send=filename 70 | Sends the contents of the specified file to the MIDI port. 71 | The file must contain raw MIDI commands (e.g. a .syx file); 72 | for Standard MIDI (.mid) files, use 73 | .B aplaymidi(1). 74 | 75 | .TP 76 | .I \-r, \-\-receive=filename 77 | Writes data received from the MIDI port into the specified file. 78 | The file will contain raw MIDI commands (such as in a .syx file); 79 | to record a Standard MIDI (.mid) file, use 80 | .B arecordmidi(1). 81 | 82 | .B amidi 83 | will filter out any Active Sensing bytes (FEh), unless the 84 | .I \-a 85 | option has been given. 86 | 87 | .TP 88 | .I \-S, \-\-send\-hex="..." 89 | Sends the bytes specified as hexadecimal numbers to the MIDI port. 90 | 91 | .TP 92 | .I \-d, \-\-dump 93 | Prints data received from the MIDI port as hexadecimal bytes. 94 | Active Sensing bytes (FEh) will not be shown, unless the 95 | .I \-a 96 | option has been given. 97 | 98 | This option is useful for debugging. 99 | 100 | .TP 101 | .I \-t, \-\-timeout=seconds 102 | Stops receiving data when no data has been received for the specified 103 | amount of time. 104 | 105 | If this option has not been given, you must press Ctrl+C (or kill 106 | .B amidi\fR) 107 | to stop receiving data. 108 | 109 | .TP 110 | .I \-a, \-\-active\-sensing 111 | Does not ignore Active Sensing bytes (FEh) when saving or printing 112 | received MIDI commands. 113 | 114 | .SH EXAMPLES 115 | 116 | .TP 117 | .B amidi \-p hw:0 \-s my_settings.syx 118 | will send the MIDI commands in 119 | .I my_settings.syx 120 | to port 121 | .I hw:0. 122 | 123 | .TP 124 | .B amidi \-S 'F0 43 10 4C 00 00 7E 00 F7' 125 | sends an XG Reset to the default port. 126 | 127 | .TP 128 | .B amidi \-p hw:1,2 \-S F0411042110C000000000074F7 \-r dump.syx \-t 1 129 | sends a \(lqParameter Dump Request\(rq to a GS device, saves the received 130 | parameter data to the file 131 | .I dump.syx, 132 | and stops after the device has finished sending data 133 | (when no data has been received for one second). 134 | 135 | .TP 136 | .B amidi \-p virtual \-d 137 | creates a virtual RawMIDI port and prints all data sent to this port. 138 | 139 | .SH FILES 140 | .I /usr/share/alsa/alsa.conf 141 | default rawmidi definitions 142 | .br 143 | .I /etc/asound.conf 144 | system\-wide rawmidi definitions 145 | .br 146 | .I ~/.asoundrc 147 | user specific rawmidi definitions 148 | 149 | .SH SEE ALSO 150 | aplaymidi(1) 151 | .br 152 | arecordmidi(1) 153 | 154 | .SH AUTHOR 155 | Clemens Ladisch 156 | -------------------------------------------------------------------------------- /alsamixer/widget.c: -------------------------------------------------------------------------------- 1 | /* 2 | * widget.c - handles widget objects and the widget stack 3 | * Copyright (c) Clemens Ladisch 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "aconfig.h" 20 | #include 21 | #include 22 | #include "die.h" 23 | #include "widget.h" 24 | 25 | int screen_lines; 26 | int screen_cols; 27 | 28 | static int cursor_visibility = -1; 29 | 30 | static void widget_handle_key(int key) 31 | { 32 | } 33 | 34 | static void update_cursor_visibility(void) 35 | { 36 | struct widget *active_widget; 37 | 38 | active_widget = get_active_widget(); 39 | if (active_widget && 40 | active_widget->cursor_visibility != cursor_visibility) { 41 | cursor_visibility = active_widget->cursor_visibility; 42 | curs_set(cursor_visibility); 43 | } 44 | } 45 | 46 | void widget_init(struct widget *widget, int lines_, int cols, int y, int x, 47 | chtype bkgd, unsigned int flags) 48 | { 49 | WINDOW *old_window; 50 | 51 | if (y == SCREEN_CENTER) 52 | y = (screen_lines - lines_) / 2; 53 | if (x == SCREEN_CENTER) 54 | x = (screen_cols - cols) / 2; 55 | 56 | old_window = widget->window; 57 | widget->window = newwin(lines_, cols, y, x); 58 | if (!widget->window) 59 | fatal_error("cannot create window"); 60 | keypad(widget->window, TRUE); 61 | nodelay(widget->window, TRUE); 62 | leaveok(widget->window, !(flags & WIDGET_CURSOR_VISIBLE)); 63 | wbkgdset(widget->window, bkgd); 64 | werase(widget->window); 65 | 66 | if (flags & WIDGET_BORDER) 67 | box(widget->window, 0, 0); 68 | if (flags & WIDGET_SUBWINDOW) { 69 | if (widget->subwindow) 70 | delwin(widget->subwindow); 71 | widget->subwindow = derwin(widget->window, 72 | lines_ - 2, cols - 2, 1, 1); 73 | if (!widget->subwindow) 74 | fatal_error("cannot create subwindow"); 75 | wbkgdset(widget->subwindow, bkgd); 76 | } 77 | widget->cursor_visibility = !!(flags & WIDGET_CURSOR_VISIBLE); 78 | 79 | if (widget->panel) { 80 | replace_panel(widget->panel, widget->window); 81 | } else { 82 | widget->panel = new_panel(widget->window); 83 | if (!widget->panel) 84 | fatal_error("cannot create panel"); 85 | set_panel_userptr(widget->panel, widget); 86 | } 87 | 88 | if (!widget->handle_key) 89 | widget->handle_key = widget_handle_key; 90 | 91 | if (old_window) 92 | delwin(old_window); 93 | 94 | update_cursor_visibility(); 95 | } 96 | 97 | void widget_free(struct widget *widget) 98 | { 99 | if (widget->panel) { 100 | del_panel(widget->panel); 101 | widget->panel = NULL; 102 | } 103 | if (widget->subwindow) { 104 | delwin(widget->subwindow); 105 | widget->subwindow = NULL; 106 | } 107 | if (widget->window) { 108 | delwin(widget->window); 109 | widget->window = NULL; 110 | } 111 | 112 | update_cursor_visibility(); 113 | } 114 | 115 | struct widget *get_active_widget(void) 116 | { 117 | PANEL *active_panel; 118 | 119 | active_panel = panel_below(NULL); 120 | if (active_panel) 121 | return panel_userptr(active_panel); 122 | else 123 | return NULL; 124 | } 125 | 126 | void window_size_changed(void) 127 | { 128 | PANEL *panel, *below; 129 | struct widget *widget; 130 | 131 | getmaxyx(stdscr, screen_lines, screen_cols); 132 | if (tigetflag("xenl") != 1 && tigetflag("am") != 1) 133 | --screen_lines; 134 | 135 | for (panel = panel_below(NULL); panel; panel = below) { 136 | below = panel_below(panel); 137 | widget = panel_userptr(panel); 138 | widget->window_size_changed(); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /alsamixer/mainloop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mainloop.c - main loop 3 | * Copyright (c) Clemens Ladisch 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "aconfig.h" 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "mem.h" 27 | #include "die.h" 28 | #include "colors.h" 29 | #include "widget.h" 30 | #include "mixer_widget.h" 31 | #include "mixer_display.h" 32 | #include "mixer_controls.h" 33 | #include "mainloop.h" 34 | 35 | static WINDOW *curses_initialized; 36 | 37 | static void black_hole_error_handler(const char *file, int line, 38 | const char *function, int err, 39 | const char *fmt, ...) 40 | { 41 | } 42 | 43 | void initialize_curses(bool use_color) 44 | { 45 | curses_initialized = initscr(); 46 | cbreak(); 47 | noecho(); 48 | #ifdef HAVE_CURSES_ESCDELAY 49 | set_escdelay(100); 50 | #endif 51 | window_size_changed(); /* update screen_lines/cols */ 52 | init_colors(use_color); 53 | snd_lib_error_set_handler(black_hole_error_handler); 54 | } 55 | 56 | void app_shutdown(void) 57 | { 58 | if (curses_initialized) { 59 | clear(); 60 | refresh(); 61 | curs_set(1); 62 | endwin(); 63 | } 64 | mixer_shutdown(); 65 | } 66 | 67 | void mainloop(void) 68 | { 69 | struct pollfd *pollfds = NULL; 70 | int nfds = 0, n; 71 | struct widget *active_widget; 72 | unsigned short revents; 73 | int key; 74 | int err; 75 | 76 | for (;;) { 77 | update_panels(); 78 | doupdate(); 79 | 80 | active_widget = get_active_widget(); 81 | if (!active_widget) 82 | break; 83 | 84 | n = 1 + snd_mixer_poll_descriptors_count(mixer); 85 | if (n != nfds) { 86 | free(pollfds); 87 | nfds = n; 88 | pollfds = ccalloc(nfds, sizeof *pollfds); 89 | pollfds[0].fd = fileno(stdin); 90 | pollfds[0].events = POLLIN; 91 | } 92 | err = snd_mixer_poll_descriptors(mixer, &pollfds[1], nfds - 1); 93 | if (err < 0) 94 | fatal_alsa_error("cannot get poll descriptors", err); 95 | n = poll(pollfds, nfds, -1); 96 | if (n < 0) { 97 | if (errno == EINTR) { 98 | pollfds[0].revents = 0; 99 | doupdate(); /* handle SIGWINCH */ 100 | } else { 101 | fatal_error("poll error"); 102 | } 103 | } 104 | if (pollfds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) 105 | break; 106 | if (pollfds[0].revents & POLLIN) 107 | --n; 108 | if (n > 0) { 109 | err = snd_mixer_poll_descriptors_revents(mixer, &pollfds[1], nfds - 1, &revents); 110 | if (err < 0) 111 | fatal_alsa_error("cannot get poll events", err); 112 | if (revents & (POLLERR | POLLNVAL)) 113 | close_mixer_device(); 114 | else if (revents & POLLIN) 115 | snd_mixer_handle_events(mixer); 116 | } 117 | key = wgetch(active_widget->window); 118 | while (key != ERR) { 119 | #ifdef KEY_RESIZE 120 | if (key == KEY_RESIZE) 121 | window_size_changed(); 122 | else 123 | #endif 124 | active_widget->handle_key(key); 125 | active_widget = get_active_widget(); 126 | if (!active_widget) 127 | break; 128 | key = wgetch(active_widget->window); 129 | } 130 | if (!active_widget) 131 | break; 132 | if (controls_changed) { 133 | controls_changed = FALSE; 134 | create_controls(); 135 | control_values_changed = FALSE; 136 | display_controls(); 137 | } else if (control_values_changed) { 138 | control_values_changed = FALSE; 139 | display_controls(); 140 | } 141 | } 142 | free(pollfds); 143 | } 144 | -------------------------------------------------------------------------------- /alsactl/monitor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Linux Sound Architecture Control Program 3 | * Copyright (c) by Takashi Iwai 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include "aconfig.h" 21 | #include "version.h" 22 | #include 23 | #include 24 | 25 | static int open_ctl(const char *name, snd_ctl_t **ctlp) 26 | { 27 | snd_ctl_t *ctl; 28 | int err; 29 | 30 | err = snd_ctl_open(&ctl, name, SND_CTL_READONLY); 31 | if (err < 0) { 32 | fprintf(stderr, "Cannot open ctl %s\n", name); 33 | return err; 34 | } 35 | err = snd_ctl_subscribe_events(ctl, 1); 36 | if (err < 0) { 37 | fprintf(stderr, "Cannot open subscribe events to ctl %s\n", name); 38 | snd_ctl_close(ctl); 39 | return err; 40 | } 41 | *ctlp = ctl; 42 | return 0; 43 | } 44 | 45 | static int print_event(int card, snd_ctl_t *ctl) 46 | { 47 | snd_ctl_event_t *event; 48 | unsigned int mask; 49 | int err; 50 | 51 | snd_ctl_event_alloca(&event); 52 | err = snd_ctl_read(ctl, event); 53 | if (err < 0) 54 | return err; 55 | 56 | if (snd_ctl_event_get_type(event) != SND_CTL_EVENT_ELEM) 57 | return 0; 58 | 59 | if (card >= 0) 60 | printf("card %d, ", card); 61 | printf("#%d (%i,%i,%i,%s,%i)", 62 | snd_ctl_event_elem_get_numid(event), 63 | snd_ctl_event_elem_get_interface(event), 64 | snd_ctl_event_elem_get_device(event), 65 | snd_ctl_event_elem_get_subdevice(event), 66 | snd_ctl_event_elem_get_name(event), 67 | snd_ctl_event_elem_get_index(event)); 68 | 69 | mask = snd_ctl_event_elem_get_mask(event); 70 | if (mask == SND_CTL_EVENT_MASK_REMOVE) { 71 | printf(" REMOVE\n"); 72 | return 0; 73 | } 74 | 75 | if (mask & SND_CTL_EVENT_MASK_VALUE) 76 | printf(" VALUE"); 77 | if (mask & SND_CTL_EVENT_MASK_INFO) 78 | printf(" INFO"); 79 | if (mask & SND_CTL_EVENT_MASK_ADD) 80 | printf(" ADD"); 81 | if (mask & SND_CTL_EVENT_MASK_TLV) 82 | printf(" TLV"); 83 | printf("\n"); 84 | return 0; 85 | } 86 | 87 | #define MAX_CARDS 256 88 | 89 | int monitor(const char *name) 90 | { 91 | snd_ctl_t *ctls[MAX_CARDS]; 92 | int ncards = 0; 93 | int show_cards; 94 | int i, err = 0; 95 | 96 | if (!name) { 97 | int card = -1; 98 | while (snd_card_next(&card) >= 0 && card >= 0) { 99 | char cardname[16]; 100 | if (ncards >= MAX_CARDS) { 101 | fprintf(stderr, "alsactl: too many cards\n"); 102 | err = -E2BIG; 103 | goto error; 104 | } 105 | sprintf(cardname, "hw:%d", card); 106 | err = open_ctl(cardname, &ctls[ncards]); 107 | if (err < 0) 108 | goto error; 109 | ncards++; 110 | } 111 | show_cards = 1; 112 | } else { 113 | err = open_ctl(name, &ctls[0]); 114 | if (err < 0) 115 | goto error; 116 | ncards++; 117 | show_cards = 0; 118 | } 119 | 120 | for (;ncards > 0;) { 121 | struct pollfd fds[ncards]; 122 | 123 | for (i = 0; i < ncards; i++) 124 | snd_ctl_poll_descriptors(ctls[i], &fds[i], 1); 125 | 126 | err = poll(fds, ncards, -1); 127 | if (err <= 0) { 128 | err = 0; 129 | break; 130 | } 131 | 132 | for (i = 0; i < ncards; i++) { 133 | unsigned short revents; 134 | snd_ctl_poll_descriptors_revents(ctls[i], &fds[i], 1, 135 | &revents); 136 | if (revents & POLLIN) 137 | print_event(show_cards ? i : -1, ctls[i]); 138 | } 139 | } 140 | 141 | error: 142 | for (i = 0; i < ncards; i++) 143 | snd_ctl_close(ctls[i]); 144 | return err; 145 | } 146 | -------------------------------------------------------------------------------- /aplay/formats.h: -------------------------------------------------------------------------------- 1 | #ifndef FORMATS_H 2 | #define FORMATS_H 1 3 | 4 | #include 5 | #include 6 | 7 | /* Definitions for .VOC files */ 8 | 9 | #define VOC_MAGIC_STRING "Creative Voice File\x1A" 10 | #define VOC_ACTUAL_VERSION 0x010A 11 | #define VOC_SAMPLESIZE 8 12 | 13 | #define VOC_MODE_MONO 0 14 | #define VOC_MODE_STEREO 1 15 | 16 | #define VOC_DATALEN(bp) ((u_long)(bp->datalen) | \ 17 | ((u_long)(bp->datalen_m) << 8) | \ 18 | ((u_long)(bp->datalen_h) << 16) ) 19 | 20 | typedef struct voc_header { 21 | u_char magic[20]; /* must be MAGIC_STRING */ 22 | u_short headerlen; /* Headerlength, should be 0x1A */ 23 | u_short version; /* VOC-file version */ 24 | u_short coded_ver; /* 0x1233-version */ 25 | } VocHeader; 26 | 27 | typedef struct voc_blocktype { 28 | u_char type; 29 | u_char datalen; /* low-byte */ 30 | u_char datalen_m; /* medium-byte */ 31 | u_char datalen_h; /* high-byte */ 32 | } VocBlockType; 33 | 34 | typedef struct voc_voice_data { 35 | u_char tc; 36 | u_char pack; 37 | } VocVoiceData; 38 | 39 | typedef struct voc_ext_block { 40 | u_short tc; 41 | u_char pack; 42 | u_char mode; 43 | } VocExtBlock; 44 | 45 | /* Definitions for Microsoft WAVE format */ 46 | 47 | #if __BYTE_ORDER == __LITTLE_ENDIAN 48 | #define COMPOSE_ID(a,b,c,d) ((a) | ((b)<<8) | ((c)<<16) | ((d)<<24)) 49 | #define LE_SHORT(v) (v) 50 | #define LE_INT(v) (v) 51 | #define BE_SHORT(v) bswap_16(v) 52 | #define BE_INT(v) bswap_32(v) 53 | #elif __BYTE_ORDER == __BIG_ENDIAN 54 | #define COMPOSE_ID(a,b,c,d) ((d) | ((c)<<8) | ((b)<<16) | ((a)<<24)) 55 | #define LE_SHORT(v) bswap_16(v) 56 | #define LE_INT(v) bswap_32(v) 57 | #define BE_SHORT(v) (v) 58 | #define BE_INT(v) (v) 59 | #else 60 | #error "Wrong endian" 61 | #endif 62 | 63 | /* Note: the following macros evaluate the parameter v twice */ 64 | #define TO_CPU_SHORT(v, be) \ 65 | ((be) ? BE_SHORT(v) : LE_SHORT(v)) 66 | #define TO_CPU_INT(v, be) \ 67 | ((be) ? BE_INT(v) : LE_INT(v)) 68 | 69 | #define WAV_RIFF COMPOSE_ID('R','I','F','F') 70 | #define WAV_RIFX COMPOSE_ID('R','I','F','X') 71 | #define WAV_WAVE COMPOSE_ID('W','A','V','E') 72 | #define WAV_FMT COMPOSE_ID('f','m','t',' ') 73 | #define WAV_DATA COMPOSE_ID('d','a','t','a') 74 | 75 | /* WAVE fmt block constants from Microsoft mmreg.h header */ 76 | #define WAV_FMT_PCM 0x0001 77 | #define WAV_FMT_IEEE_FLOAT 0x0003 78 | #define WAV_FMT_DOLBY_AC3_SPDIF 0x0092 79 | #define WAV_FMT_EXTENSIBLE 0xfffe 80 | 81 | /* Used with WAV_FMT_EXTENSIBLE format */ 82 | #define WAV_GUID_TAG "\x00\x00\x00\x00\x10\x00\x80\x00\x00\xAA\x00\x38\x9B\x71" 83 | 84 | /* it's in chunks like .voc and AMIGA iff, but my source say there 85 | are in only in this combination, so I combined them in one header; 86 | it works on all WAVE-file I have 87 | */ 88 | typedef struct { 89 | u_int magic; /* 'RIFF' */ 90 | u_int length; /* filelen */ 91 | u_int type; /* 'WAVE' */ 92 | } WaveHeader; 93 | 94 | typedef struct { 95 | u_short format; /* see WAV_FMT_* */ 96 | u_short channels; 97 | u_int sample_fq; /* frequence of sample */ 98 | u_int byte_p_sec; 99 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes */ 100 | u_short bit_p_spl; /* 8, 12 or 16 bit */ 101 | } WaveFmtBody; 102 | 103 | typedef struct { 104 | WaveFmtBody format; 105 | u_short ext_size; 106 | u_short bit_p_spl; 107 | u_int channel_mask; 108 | u_short guid_format; /* WAV_FMT_* */ 109 | u_char guid_tag[14]; /* WAV_GUID_TAG */ 110 | } WaveFmtExtensibleBody; 111 | 112 | typedef struct { 113 | u_int type; /* 'data' */ 114 | u_int length; /* samplecount */ 115 | } WaveChunkHeader; 116 | 117 | /* Definitions for Sparc .au header */ 118 | 119 | #define AU_MAGIC COMPOSE_ID('.','s','n','d') 120 | 121 | #define AU_FMT_ULAW 1 122 | #define AU_FMT_LIN8 2 123 | #define AU_FMT_LIN16 3 124 | 125 | typedef struct au_header { 126 | u_int magic; /* '.snd' */ 127 | u_int hdr_size; /* size of header (min 24) */ 128 | u_int data_size; /* size of data */ 129 | u_int encoding; /* see to AU_FMT_XXXX */ 130 | u_int sample_rate; /* sample rate */ 131 | u_int channels; /* number of channels (voices) */ 132 | } AuHeader; 133 | 134 | #endif /* FORMATS */ 135 | -------------------------------------------------------------------------------- /alsamixer/colors.c: -------------------------------------------------------------------------------- 1 | /* 2 | * colors.c - color and attribute definitions 3 | * Copyright (c) 1998,1999 Tim Janik 4 | * Jaroslav Kysela 5 | * Copyright (c) 2009 Clemens Ladisch 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include "aconfig.h" 22 | #include CURSESINC 23 | #include "colors.h" 24 | 25 | int attr_mixer_frame; 26 | int attr_mixer_text; 27 | int attr_mixer_active; 28 | int attr_ctl_frame; 29 | int attr_ctl_mute; 30 | int attr_ctl_nomute; 31 | int attr_ctl_capture; 32 | int attr_ctl_nocapture; 33 | int attr_ctl_label; 34 | int attr_ctl_label_focus; 35 | int attr_ctl_mark_focus; 36 | int attr_ctl_bar_lo; 37 | #ifdef TRICOLOR_VOLUME_BAR 38 | int attr_ctl_bar_mi; 39 | int attr_ctl_bar_hi; 40 | #endif 41 | int attr_ctl_inactive; 42 | int attr_ctl_label_inactive; 43 | int attr_errormsg; 44 | int attr_infomsg; 45 | int attr_textbox; 46 | int attr_textfield; 47 | int attr_menu; 48 | int attr_menu_selected; 49 | 50 | void init_colors(int use_color) 51 | { 52 | if (!!has_colors() == !!use_color) { 53 | start_color(); 54 | 55 | init_pair(1, COLOR_CYAN, COLOR_BLACK); 56 | init_pair(2, COLOR_YELLOW, COLOR_BLACK); 57 | init_pair(3, COLOR_WHITE, COLOR_GREEN); 58 | init_pair(4, COLOR_RED, COLOR_BLACK); 59 | init_pair(5, COLOR_WHITE, COLOR_BLACK); 60 | init_pair(6, COLOR_WHITE, COLOR_BLUE); 61 | init_pair(7, COLOR_RED, COLOR_BLUE); 62 | init_pair(8, COLOR_GREEN, COLOR_GREEN); 63 | init_pair(9, COLOR_WHITE, COLOR_RED); 64 | #ifdef TRICOLOR_VOLUME_BAR 65 | init_pair(10, COLOR_WHITE, COLOR_WHITE); 66 | init_pair(11, COLOR_RED, COLOR_RED); 67 | #endif 68 | 69 | attr_mixer_frame = COLOR_PAIR(1); 70 | attr_mixer_text = COLOR_PAIR(1); 71 | attr_mixer_active = A_BOLD | COLOR_PAIR(2); 72 | attr_ctl_frame = A_BOLD | COLOR_PAIR(1); 73 | attr_ctl_mute = COLOR_PAIR(1); 74 | attr_ctl_nomute = A_BOLD | COLOR_PAIR(3); 75 | attr_ctl_capture = A_BOLD | COLOR_PAIR(4); 76 | attr_ctl_nocapture = COLOR_PAIR(5); 77 | attr_ctl_label = A_BOLD | COLOR_PAIR(6); 78 | attr_ctl_label_focus = A_BOLD | COLOR_PAIR(7); 79 | attr_ctl_mark_focus = A_BOLD | COLOR_PAIR(4); 80 | attr_ctl_bar_lo = A_BOLD | COLOR_PAIR(8); 81 | #ifdef TRICOLOR_VOLUME_BAR 82 | attr_ctl_bar_mi = A_BOLD | COLOR_PAIR(10); 83 | attr_ctl_bar_hi = A_BOLD | COLOR_PAIR(11); 84 | #endif 85 | attr_ctl_inactive = COLOR_PAIR(5); 86 | attr_ctl_label_inactive = A_REVERSE | COLOR_PAIR(5); 87 | attr_errormsg = A_BOLD | COLOR_PAIR(9); 88 | attr_infomsg = A_BOLD | COLOR_PAIR(6); 89 | attr_textbox = A_BOLD | COLOR_PAIR(6); 90 | attr_textfield = A_REVERSE | COLOR_PAIR(5); 91 | attr_menu = A_BOLD | COLOR_PAIR(6); 92 | attr_menu_selected = A_REVERSE | COLOR_PAIR(6); 93 | } else { 94 | attr_mixer_frame = A_NORMAL; 95 | attr_mixer_text = A_NORMAL; 96 | attr_mixer_active = A_BOLD; 97 | attr_ctl_frame = A_BOLD; 98 | attr_ctl_mute = A_NORMAL; 99 | attr_ctl_nomute = A_BOLD; 100 | attr_ctl_capture = A_BOLD; 101 | attr_ctl_nocapture = A_NORMAL; 102 | attr_ctl_label = A_REVERSE; 103 | attr_ctl_label_focus = A_REVERSE | A_BOLD; 104 | attr_ctl_mark_focus = A_BOLD; 105 | attr_ctl_bar_lo = A_BOLD; 106 | #ifdef TRICOLOR_VOLUME_BAR 107 | attr_ctl_bar_mi = A_BOLD; 108 | attr_ctl_bar_hi = A_BOLD; 109 | #endif 110 | attr_ctl_inactive = A_NORMAL; 111 | attr_ctl_label_inactive = A_REVERSE; 112 | attr_errormsg = A_STANDOUT; 113 | attr_infomsg = A_NORMAL; 114 | attr_textbox = A_NORMAL; 115 | attr_textfield = A_REVERSE; 116 | attr_menu = A_NORMAL; 117 | attr_menu_selected = A_REVERSE; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /alsamixer/cli.c: -------------------------------------------------------------------------------- 1 | /* 2 | * alsamixer - curses mixer for the ALSA project 3 | * Copyright (c) 1998,1999 Tim Janik 4 | * Jaroslav Kysela 5 | * Copyright (c) 2009 Clemens Ladisch 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include "aconfig.h" 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "gettext_curses.h" 28 | #include "mixer_widget.h" 29 | #include "mainloop.h" 30 | 31 | static int use_color = 1; 32 | static struct snd_mixer_selem_regopt selem_regopt = { 33 | .ver = 1, 34 | .abstract = SND_MIXER_SABSTRACT_NONE, 35 | .device = "default", 36 | }; 37 | 38 | static void show_help(void) 39 | { 40 | puts(_("Usage: alsamixer [options]")); 41 | puts(_("Useful options:\n" 42 | " -h, --help this help\n" 43 | " -c, --card=NUMBER sound card number or id\n" 44 | " -D, --device=NAME mixer device name\n" 45 | " -V, --view=MODE starting view mode: playback/capture/all")); 46 | puts(_("Debugging options:\n" 47 | " -g, --no-color toggle using of colors\n" 48 | " -a, --abstraction=NAME mixer abstraction level: none/basic")); 49 | } 50 | 51 | static void parse_options(int argc, char *argv[]) 52 | { 53 | static const char short_options[] = "hc:D:V:gsa:"; 54 | static const struct option long_options[] = { 55 | { .name = "help", .val = 'h' }, 56 | { .name = "card", .has_arg = 1, .val = 'c' }, 57 | { .name = "device", .has_arg = 1, .val = 'D' }, 58 | { .name = "view", .has_arg = 1, .val = 'V' }, 59 | { .name = "no-color", .val = 'g' }, 60 | { .name = "abstraction", .has_arg = 1, .val = 'a' }, 61 | { } 62 | }; 63 | int option; 64 | int card_index; 65 | static char name_buf[16]; 66 | 67 | while ((option = getopt_long(argc, argv, short_options, 68 | long_options, NULL)) != -1) { 69 | switch (option) { 70 | case '?': 71 | case 'h': 72 | show_help(); 73 | exit(EXIT_SUCCESS); 74 | case 'c': 75 | card_index = snd_card_get_index(optarg); 76 | if (card_index < 0) { 77 | fprintf(stderr, _("invalid card index: %s\n"), optarg); 78 | goto fail; 79 | } 80 | sprintf(name_buf, "hw:%d", card_index); 81 | selem_regopt.device = name_buf; 82 | break; 83 | case 'D': 84 | selem_regopt.device = optarg; 85 | break; 86 | case 'V': 87 | if (*optarg == 'p' || *optarg == 'P') 88 | view_mode = VIEW_MODE_PLAYBACK; 89 | else if (*optarg == 'c' || *optarg == 'C') 90 | view_mode = VIEW_MODE_CAPTURE; 91 | else 92 | view_mode = VIEW_MODE_ALL; 93 | break; 94 | case 'g': 95 | use_color = !use_color; 96 | break; 97 | case 'a': 98 | if (!strcmp(optarg, "none")) 99 | selem_regopt.abstract = SND_MIXER_SABSTRACT_NONE; 100 | else if (!strcmp(optarg, "basic")) 101 | selem_regopt.abstract = SND_MIXER_SABSTRACT_BASIC; 102 | else { 103 | fprintf(stderr, _("unknown abstraction level: %s\n"), optarg); 104 | goto fail; 105 | } 106 | break; 107 | default: 108 | fprintf(stderr, _("unknown option: %c\n"), option); 109 | fail: 110 | fputs(_("try `alsamixer --help' for more information\n"), stderr); 111 | exit(EXIT_FAILURE); 112 | } 113 | } 114 | } 115 | 116 | int main(int argc, char *argv[]) 117 | { 118 | if (!isatty(fileno(stdin))) 119 | return 0; 120 | 121 | setlocale(LC_ALL, ""); 122 | #ifdef ENABLE_NLS_IN_CURSES 123 | textdomain(PACKAGE); 124 | #endif 125 | 126 | parse_options(argc, argv); 127 | 128 | create_mixer_object(&selem_regopt); 129 | 130 | initialize_curses(use_color); 131 | 132 | create_mixer_widget(); 133 | 134 | mainloop(); 135 | 136 | app_shutdown(); 137 | return 0; 138 | } 139 | -------------------------------------------------------------------------------- /alsamixer/proc_files.c: -------------------------------------------------------------------------------- 1 | /* 2 | * proc_files.c - shows ALSA system information files 3 | * Copyright (c) Clemens Ladisch 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "aconfig.h" 20 | #include 21 | #include 22 | #include 23 | #include "gettext_curses.h" 24 | #include "utils.h" 25 | #include "die.h" 26 | #include "mem.h" 27 | #include "colors.h" 28 | #include "widget.h" 29 | #include "textbox.h" 30 | #include "proc_files.h" 31 | 32 | static struct widget proc_widget; 33 | static ITEM *items[7]; 34 | static unsigned int items_count; 35 | static MENU *menu; 36 | 37 | static void on_menu_key(int key) 38 | { 39 | static const struct { 40 | int key; 41 | int request; 42 | } key_map[] = { 43 | { KEY_DOWN, REQ_DOWN_ITEM }, 44 | { KEY_UP, REQ_UP_ITEM }, 45 | { KEY_HOME, REQ_FIRST_ITEM }, 46 | { KEY_NPAGE, REQ_SCR_DPAGE }, 47 | { KEY_PPAGE, REQ_SCR_UPAGE }, 48 | { KEY_BEG, REQ_FIRST_ITEM }, 49 | { KEY_END, REQ_LAST_ITEM }, 50 | }; 51 | unsigned int i; 52 | 53 | for (i = 0; i < ARRAY_SIZE(key_map); ++i) 54 | if (key_map[i].key == key) { 55 | menu_driver(menu, key_map[i].request); 56 | break; 57 | } 58 | } 59 | 60 | static void on_handle_key(int key) 61 | { 62 | ITEM *item; 63 | 64 | switch (key) { 65 | case 27: 66 | case KEY_CANCEL: 67 | proc_widget.close(); 68 | break; 69 | case 10: 70 | case 13: 71 | case KEY_ENTER: 72 | item = current_item(menu); 73 | if (item) 74 | show_textfile(item_name(item)); 75 | break; 76 | default: 77 | on_menu_key(key); 78 | break; 79 | } 80 | } 81 | 82 | static bool create(void) 83 | { 84 | int rows, columns; 85 | const char *title; 86 | 87 | if (screen_lines < 3 || screen_cols < 20) { 88 | proc_widget.close(); 89 | beep(); 90 | return FALSE; 91 | } 92 | scale_menu(menu, &rows, &columns); 93 | rows += 2; 94 | columns += 2; 95 | if (rows > screen_lines) 96 | rows = screen_lines; 97 | if (columns > screen_cols) 98 | columns = screen_cols; 99 | 100 | widget_init(&proc_widget, rows, columns, SCREEN_CENTER, SCREEN_CENTER, 101 | attr_menu, WIDGET_BORDER | WIDGET_SUBWINDOW); 102 | 103 | title = _("Select File"); 104 | mvwprintw(proc_widget.window, 0, (columns - 2 - get_mbs_width(title)) / 2, " %s ", title); 105 | set_menu_win(menu, proc_widget.window); 106 | set_menu_sub(menu, proc_widget.subwindow); 107 | return TRUE; 108 | } 109 | 110 | static void on_window_size_changed(void) 111 | { 112 | unpost_menu(menu); 113 | if (!create()) 114 | return; 115 | post_menu(menu); 116 | } 117 | 118 | static void on_close(void) 119 | { 120 | unsigned int i; 121 | 122 | unpost_menu(menu); 123 | free_menu(menu); 124 | for (i = 0; i < items_count; ++i) 125 | free_item(items[i]); 126 | widget_free(&proc_widget); 127 | } 128 | 129 | static void add_item(const char *file_name) 130 | { 131 | if (access(file_name, F_OK) == 0) { 132 | items[items_count] = new_item(file_name, NULL); 133 | if (!items[items_count]) 134 | fatal_error("cannot create menu item"); 135 | ++items_count; 136 | assert(items_count < ARRAY_SIZE(items)); 137 | } 138 | } 139 | 140 | static struct widget proc_widget = { 141 | .handle_key = on_handle_key, 142 | .window_size_changed = on_window_size_changed, 143 | .close = on_close, 144 | }; 145 | 146 | void create_proc_files_list(void) 147 | { 148 | items_count = 0; 149 | add_item("/proc/asound/version"); 150 | add_item("/proc/asound/cards"); 151 | add_item("/proc/asound/devices"); 152 | add_item("/proc/asound/oss/devices"); 153 | add_item("/proc/asound/timers"); 154 | add_item("/proc/asound/pcm"); 155 | items[items_count] = NULL; 156 | 157 | menu = new_menu(items); 158 | if (!menu) 159 | fatal_error("cannot create menu"); 160 | set_menu_fore(menu, attr_menu_selected); 161 | set_menu_back(menu, attr_menu); 162 | set_menu_mark(menu, NULL); 163 | menu_opts_off(menu, O_SHOWDESC); 164 | 165 | if (!create()) 166 | return; 167 | 168 | post_menu(menu); 169 | } 170 | -------------------------------------------------------------------------------- /alsactl/init_utils_string.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2004-2005 Kay Sievers 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation version 2 of the License. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 | * 17 | */ 18 | 19 | 20 | static void remove_trailing_chars(char *path, char c) 21 | { 22 | size_t len; 23 | 24 | len = strlen(path); 25 | while (len > 0 && path[len-1] == c) 26 | path[--len] = '\0'; 27 | } 28 | 29 | /* count of characters used to encode one unicode char */ 30 | static int utf8_encoded_expected_len(const char *str) 31 | { 32 | unsigned char c = (unsigned char)str[0]; 33 | 34 | if (c < 0x80) 35 | return 1; 36 | if ((c & 0xe0) == 0xc0) 37 | return 2; 38 | if ((c & 0xf0) == 0xe0) 39 | return 3; 40 | if ((c & 0xf8) == 0xf0) 41 | return 4; 42 | if ((c & 0xfc) == 0xf8) 43 | return 5; 44 | if ((c & 0xfe) == 0xfc) 45 | return 6; 46 | return 0; 47 | } 48 | 49 | /* decode one unicode char */ 50 | static int utf8_encoded_to_unichar(const char *str) 51 | { 52 | int unichar; 53 | int len; 54 | int i; 55 | 56 | len = utf8_encoded_expected_len(str); 57 | switch (len) { 58 | case 1: 59 | return (int)str[0]; 60 | case 2: 61 | unichar = str[0] & 0x1f; 62 | break; 63 | case 3: 64 | unichar = (int)str[0] & 0x0f; 65 | break; 66 | case 4: 67 | unichar = (int)str[0] & 0x07; 68 | break; 69 | case 5: 70 | unichar = (int)str[0] & 0x03; 71 | break; 72 | case 6: 73 | unichar = (int)str[0] & 0x01; 74 | break; 75 | default: 76 | return -1; 77 | } 78 | 79 | for (i = 1; i < len; i++) { 80 | if (((int)str[i] & 0xc0) != 0x80) 81 | return -1; 82 | unichar <<= 6; 83 | unichar |= (int)str[i] & 0x3f; 84 | } 85 | 86 | return unichar; 87 | } 88 | 89 | /* expected size used to encode one unicode char */ 90 | static int utf8_unichar_to_encoded_len(int unichar) 91 | { 92 | if (unichar < 0x80) 93 | return 1; 94 | if (unichar < 0x800) 95 | return 2; 96 | if (unichar < 0x10000) 97 | return 3; 98 | if (unichar < 0x200000) 99 | return 4; 100 | if (unichar < 0x4000000) 101 | return 5; 102 | return 6; 103 | } 104 | 105 | /* check if unicode char has a valid numeric range */ 106 | static int utf8_unichar_valid_range(int unichar) 107 | { 108 | if (unichar > 0x10ffff) 109 | return 0; 110 | if ((unichar & 0xfffff800) == 0xd800) 111 | return 0; 112 | if ((unichar > 0xfdcf) && (unichar < 0xfdf0)) 113 | return 0; 114 | if ((unichar & 0xffff) == 0xffff) 115 | return 0; 116 | return 1; 117 | } 118 | 119 | /* validate one encoded unicode char and return its length */ 120 | static int utf8_encoded_valid_unichar(const char *str) 121 | { 122 | int len; 123 | int unichar; 124 | int i; 125 | 126 | len = utf8_encoded_expected_len(str); 127 | if (len == 0) 128 | return -1; 129 | 130 | /* ascii is valid */ 131 | if (len == 1) 132 | return 1; 133 | 134 | /* check if expected encoded chars are available */ 135 | for (i = 0; i < len; i++) 136 | if ((str[i] & 0x80) != 0x80) 137 | return -1; 138 | 139 | unichar = utf8_encoded_to_unichar(str); 140 | 141 | /* check if encoded length matches encoded value */ 142 | if (utf8_unichar_to_encoded_len(unichar) != len) 143 | return -1; 144 | 145 | /* check if value has valid range */ 146 | if (!utf8_unichar_valid_range(unichar)) 147 | return -1; 148 | 149 | return len; 150 | } 151 | 152 | /* replace everything but whitelisted plain ascii and valid utf8 */ 153 | static int replace_untrusted_chars(char *str) 154 | { 155 | size_t i = 0; 156 | int replaced = 0; 157 | 158 | while (str[i] != '\0') { 159 | int len; 160 | 161 | /* valid printable ascii char */ 162 | if ((str[i] >= '0' && str[i] <= '9') || 163 | (str[i] >= 'A' && str[i] <= 'Z') || 164 | (str[i] >= 'a' && str[i] <= 'z') || 165 | strchr(" #$%+-./:=?@_,", str[i])) { 166 | i++; 167 | continue; 168 | } 169 | /* valid utf8 is accepted */ 170 | len = utf8_encoded_valid_unichar(&str[i]); 171 | if (len > 1) { 172 | i += len; 173 | continue; 174 | } 175 | 176 | /* everything else is garbage */ 177 | str[i] = '_'; 178 | i++; 179 | replaced++; 180 | } 181 | 182 | return replaced; 183 | } 184 | -------------------------------------------------------------------------------- /alsactl/utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Advanced Linux Sound Architecture Control Program - Support routines 3 | * Copyright (c) by Jaroslav Kysela 4 | * 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include "alsactl.h" 36 | 37 | int file_map(const char *filename, char **buf, size_t *bufsize) 38 | { 39 | struct stat stats; 40 | int fd; 41 | 42 | fd = open(filename, O_RDONLY); 43 | if (fd < 0) { 44 | return -1; 45 | } 46 | 47 | if (fstat(fd, &stats) < 0) { 48 | close(fd); 49 | return -1; 50 | } 51 | 52 | *buf = mmap(NULL, stats.st_size, PROT_READ, MAP_SHARED, fd, 0); 53 | if (*buf == MAP_FAILED) { 54 | close(fd); 55 | return -1; 56 | } 57 | *bufsize = stats.st_size; 58 | 59 | close(fd); 60 | 61 | return 0; 62 | } 63 | 64 | void file_unmap(void *buf, size_t bufsize) 65 | { 66 | munmap(buf, bufsize); 67 | } 68 | 69 | size_t line_width(const char *buf, size_t bufsize, size_t pos) 70 | { 71 | int esc = 0; 72 | size_t count; 73 | 74 | for (count = pos; count < bufsize; count++) { 75 | if (!esc && buf[count] == '\n') 76 | break; 77 | esc = buf[count] == '\\'; 78 | } 79 | 80 | return count - pos; 81 | } 82 | 83 | void initfailed(int cardnumber, const char *reason, int exitcode) 84 | { 85 | int fp; 86 | char *str; 87 | char sexitcode[16]; 88 | 89 | if (statefile == NULL) 90 | return; 91 | if (snd_card_get_name(cardnumber, &str) < 0) 92 | return; 93 | sprintf(sexitcode, "%i", exitcode); 94 | fp = open(statefile, O_WRONLY|O_CREAT|O_APPEND, 0644); 95 | write(fp, str, strlen(str)); 96 | write(fp, ":", 1); 97 | write(fp, reason, strlen(reason)); 98 | write(fp, ":", 1); 99 | write(fp, sexitcode, strlen(sexitcode)); 100 | write(fp, "\n", 1); 101 | close(fp); 102 | free(str); 103 | } 104 | 105 | static void syslog_(int prio, const char *fcn, long line, 106 | const char *fmt, va_list ap) 107 | { 108 | char buf[1024]; 109 | 110 | snprintf(buf, sizeof(buf), "%s: %s:%ld", command, fcn, line); 111 | buf[sizeof(buf)-1] = '\0'; 112 | vsnprintf(buf + strlen(buf), sizeof(buf)-strlen(buf), fmt, ap); 113 | buf[sizeof(buf)-1] = '\0'; 114 | syslog(LOG_INFO, "%s", buf); 115 | } 116 | 117 | void info_(const char *fcn, long line, const char *fmt, ...) 118 | { 119 | va_list ap; 120 | 121 | va_start(ap, fmt); 122 | if (use_syslog) { 123 | syslog_(LOG_INFO, fcn, line, fmt, ap); 124 | } else { 125 | fprintf(stdout, "%s: %s:%ld: ", command, fcn, line); 126 | vfprintf(stdout, fmt, ap); 127 | putc('\n', stdout); 128 | } 129 | va_end(ap); 130 | } 131 | 132 | void error_(const char *fcn, long line, const char *fmt, ...) 133 | { 134 | va_list ap; 135 | 136 | va_start(ap, fmt); 137 | if (use_syslog) { 138 | syslog_(LOG_ERR, fcn, line, fmt, ap); 139 | } else { 140 | fprintf(stderr, "%s: %s:%ld: ", command, fcn, line); 141 | vfprintf(stderr, fmt, ap); 142 | putc('\n', stderr); 143 | } 144 | va_end(ap); 145 | } 146 | 147 | void cerror_(const char *fcn, long line, int cond, const char *fmt, ...) 148 | { 149 | va_list ap; 150 | 151 | if (!cond && !debugflag) 152 | return; 153 | va_start(ap, fmt); 154 | if (use_syslog) { 155 | syslog_(LOG_ERR, fcn, line, fmt, ap); 156 | } else { 157 | fprintf(stderr, "%s: %s:%ld: ", command, fcn, line); 158 | vfprintf(stderr, fmt, ap); 159 | putc('\n', stderr); 160 | } 161 | va_end(ap); 162 | } 163 | 164 | void dbg_(const char *fcn, long line, const char *fmt, ...) 165 | { 166 | va_list ap; 167 | 168 | if (!debugflag) 169 | return; 170 | va_start(ap, fmt); 171 | if (use_syslog) { 172 | syslog_(LOG_DEBUG, fcn, line, fmt, ap); 173 | } else { 174 | fprintf(stderr, "%s: %s:%ld: ", command, fcn, line); 175 | vfprintf(stderr, fmt, ap); 176 | putc('\n', stderr); 177 | } 178 | va_end(ap); 179 | } 180 | -------------------------------------------------------------------------------- /alsactl/init_sysfs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2006 Kay Sievers 3 | * 2008 Jaroslav Kysela 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the 7 | * Free Software Foundation version 2 of the License. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, write to the Free Software Foundation, Inc., 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | * 18 | */ 19 | 20 | 21 | static char sysfs_path[PATH_SIZE]; 22 | 23 | /* attribute value cache */ 24 | static LIST_HEAD(attr_list); 25 | struct sysfs_attr { 26 | struct list_head node; 27 | char path[PATH_SIZE]; 28 | char *value; /* points to value_local if value is cached */ 29 | char value_local[NAME_SIZE]; 30 | }; 31 | 32 | static int sysfs_init(void) 33 | { 34 | const char *env; 35 | char sysfs_test[PATH_SIZE]; 36 | 37 | env = getenv("SYSFS_PATH"); 38 | if (env) { 39 | strlcpy(sysfs_path, env, sizeof(sysfs_path)); 40 | remove_trailing_chars(sysfs_path, '/'); 41 | } else 42 | strlcpy(sysfs_path, "/sys", sizeof(sysfs_path)); 43 | dbg("sysfs_path='%s'", sysfs_path); 44 | 45 | strlcpy(sysfs_test, sysfs_path, sizeof(sysfs_test)); 46 | strlcat(sysfs_test, "/kernel/uevent_helper", sizeof(sysfs_test)); 47 | if (access(sysfs_test, F_OK)) { 48 | error("sysfs path '%s' is invalid\n", sysfs_path); 49 | return -errno; 50 | } 51 | 52 | INIT_LIST_HEAD(&attr_list); 53 | return 0; 54 | } 55 | 56 | static void sysfs_cleanup(void) 57 | { 58 | struct sysfs_attr *attr_loop; 59 | struct sysfs_attr *attr_temp; 60 | 61 | list_for_each_entry_safe(attr_loop, attr_temp, &attr_list, node) { 62 | list_del(&attr_loop->node); 63 | free(attr_loop); 64 | } 65 | } 66 | 67 | static char *sysfs_attr_get_value(const char *devpath, const char *attr_name) 68 | { 69 | char path_full[PATH_SIZE]; 70 | const char *path; 71 | char value[NAME_SIZE]; 72 | struct sysfs_attr *attr_loop; 73 | struct sysfs_attr *attr; 74 | struct stat statbuf; 75 | int fd; 76 | ssize_t size; 77 | size_t sysfs_len; 78 | 79 | dbg("open '%s'/'%s'", devpath, attr_name); 80 | sysfs_len = strlcpy(path_full, sysfs_path, sizeof(path_full)); 81 | path = &path_full[sysfs_len]; 82 | strlcat(path_full, devpath, sizeof(path_full)); 83 | strlcat(path_full, "/", sizeof(path_full)); 84 | strlcat(path_full, attr_name, sizeof(path_full)); 85 | 86 | /* look for attribute in cache */ 87 | list_for_each_entry(attr_loop, &attr_list, node) { 88 | if (strcmp(attr_loop->path, path) == 0) { 89 | dbg("found in cache '%s'", attr_loop->path); 90 | return attr_loop->value; 91 | } 92 | } 93 | 94 | /* store attribute in cache (also negatives are kept in cache) */ 95 | dbg("new uncached attribute '%s'", path_full); 96 | attr = malloc(sizeof(struct sysfs_attr)); 97 | if (attr == NULL) 98 | return NULL; 99 | memset(attr, 0x00, sizeof(struct sysfs_attr)); 100 | strlcpy(attr->path, path, sizeof(attr->path)); 101 | dbg("add to cache '%s'", path_full); 102 | list_add(&attr->node, &attr_list); 103 | 104 | if (lstat(path_full, &statbuf) != 0) { 105 | dbg("stat '%s' failed: %s", path_full, strerror(errno)); 106 | goto out; 107 | } 108 | 109 | if (S_ISLNK(statbuf.st_mode)) { 110 | /* links return the last element of the target path */ 111 | char link_target[PATH_SIZE + 1]; 112 | int len; 113 | const char *pos; 114 | 115 | len = readlink(path_full, link_target, sizeof(link_target) - 1); 116 | if (len > 0) { 117 | link_target[len] = '\0'; 118 | pos = strrchr(link_target, '/'); 119 | if (pos != NULL) { 120 | dbg("cache '%s' with link value '%s'", path_full, pos+1); 121 | strlcpy(attr->value_local, &pos[1], sizeof(attr->value_local)); 122 | attr->value = attr->value_local; 123 | } 124 | } 125 | goto out; 126 | } 127 | 128 | /* skip directories */ 129 | if (S_ISDIR(statbuf.st_mode)) 130 | goto out; 131 | 132 | /* skip non-readable files */ 133 | if ((statbuf.st_mode & S_IRUSR) == 0) 134 | goto out; 135 | 136 | /* read attribute value */ 137 | fd = open(path_full, O_RDONLY); 138 | if (fd < 0) { 139 | dbg("attribute '%s' does not exist", path_full); 140 | goto out; 141 | } 142 | size = read(fd, value, sizeof(value)); 143 | close(fd); 144 | if (size < 0) 145 | goto out; 146 | if (size == sizeof(value)) 147 | goto out; 148 | 149 | /* got a valid value, store and return it */ 150 | value[size] = '\0'; 151 | remove_trailing_chars(value, '\n'); 152 | dbg("cache '%s' with attribute value '%s'", path_full, value); 153 | strlcpy(attr->value_local, value, sizeof(attr->value_local)); 154 | attr->value = attr->value_local; 155 | 156 | out: 157 | return attr->value; 158 | } 159 | -------------------------------------------------------------------------------- /amixer/amixer.1: -------------------------------------------------------------------------------- 1 | .TH AMIXER 1 "11 Aug 2000" 2 | .SH NAME 3 | amixer \- command-line mixer for ALSA soundcard driver 4 | .SH SYNOPSIS 5 | \fBamixer\fP [\fI\-option\fP] [\fIcmd\fP] 6 | .SH DESCRIPTION 7 | \fBamixer\fP allows command\-line control of the mixer for the ALSA 8 | soundcard driver. 9 | \fBamixer\fP supports multiple soundcards. 10 | 11 | \fBamixer\fR with no arguments will display the current mixer settings 12 | for the default soundcard and device. This is a good way to see a list 13 | of the simple mixer controls you can use. 14 | 15 | .SH COMMANDS 16 | 17 | .TP 18 | \fIhelp\fP 19 | Shows syntax. 20 | 21 | .TP 22 | \fIinfo\fP 23 | Shows the information about a mixer device. 24 | 25 | .TP 26 | \fIscontrols\fP 27 | Shows a complete list of simple mixer controls. 28 | 29 | .TP 30 | \fIscontents\fP 31 | Shows a complete list of simple mixer controls with their contents. 32 | 33 | .TP 34 | \fIset\fP or \fIsset\fP <\fISCONTROL\fP> <\fIPARAMETER\fP> ... 35 | Sets the simple mixer control contents. The parameter can be the volume 36 | either as a percentage from 0% to 100% with \fI%\fP suffix, 37 | a dB gain with \fIdB\fP suffix (like \-12.5dB), or an exact hardware value. 38 | The dB gain can be used only for the mixer elements with available 39 | dB information. 40 | When plus(+) or minus(\-) letter is appended after 41 | volume value, the volume is incremented or decremented from the current 42 | value, respectively. 43 | 44 | The parameters \fIcap, nocap, mute, unmute, toggle\fP are used to 45 | change capture (recording) and muting for the group specified. 46 | 47 | The optional modifiers can be put as extra parameters to specify 48 | the stream direction or channels to apply. 49 | The modifiers \fIplayback\fP and \fIcapture\fP specify the stream, 50 | and the modifiers \fIfront, rear, center, woofer\fP are used to specify 51 | channels to be changed. 52 | 53 | A simple mixer control must be specified. Only one device can be controlled 54 | at a time. 55 | 56 | .TP 57 | \fIget\fP or \fIsget\fP <\fISCONTROL\fP> 58 | Shows the simple mixer control contents. 59 | 60 | A simple mixer control must be specified. Only one device can be controlled 61 | at a time. 62 | 63 | .TP 64 | \fIcontrols\fP 65 | Shows a complete list of card controls. 66 | 67 | .TP 68 | \fIcontents\fP 69 | Shows a complete list of card controls with their contents. 70 | 71 | .TP 72 | \fIcset\fP <\fICONTROL\fP> <\fIPARAMETER\fP> ... 73 | Sets the card control contents. The identifier has these components: iface, 74 | name, index, device, subdevice, numid. The next argument specifies the value 75 | of control. 76 | 77 | .TP 78 | \fIcget\fP <\fICONTROL\fP> 79 | Shows the card control contents. The identifier has same syntax as for 80 | the \fIcset\fP command. 81 | 82 | .SH OPTIONS 83 | 84 | .TP 85 | \fI\-c\fP card 86 | 87 | Select the card number to control. The device name created from this 88 | parameter has syntax 'hw:N' where N is specified card number. 89 | 90 | .TP 91 | \fI\-D\fP device 92 | 93 | Select the device name to control. The default control name is 'default'. 94 | 95 | .TP 96 | \fI\-s\fP | \fI\-\-stdin\fP 97 | 98 | Read from stdin and execute the command on each line sequentially. 99 | When this option is given, the command in command\-line arguments is ignored. 100 | 101 | Only sset and cset are accepted. Other commands are ignored. 102 | The commands to unmatched ids are ignored without errors too. 103 | 104 | .TP 105 | \fI\-h\fP 106 | Help: show syntax. 107 | 108 | .TP 109 | \fI\-q\fP 110 | Quiet mode. Do not show results of changes. 111 | 112 | .TP 113 | \fI\-R\fP 114 | Use the raw value for evaluating the percentage representation. 115 | This is the default mode. 116 | 117 | .TP 118 | \fI\-M\fP 119 | Use the mapped volume for evaluating the percentage representation 120 | like \fBalsamixer\fR, to be more natural for human ear. 121 | 122 | .SH EXAMPLES 123 | 124 | .TP 125 | \fBamixer \-c 1 sset Line,0 80%,40% unmute cap\fR 126 | will set the second soundcard's left line input volume to 80% and 127 | right line input to 40%, unmute it, and select it as a source for 128 | capture (recording).\fR 129 | 130 | .TP 131 | \fBamixer \-c 1 \-\- sset Master playback \-20dB\fR 132 | will set the master volume of the second card to \-20dB. If the master 133 | has multiple channels, all channels are set to the same value. 134 | 135 | .TP 136 | \fBamixer \-c 1 set PCM 2dB+\fR 137 | will increase the PCM volume of the second card with 2dB. When both 138 | playback and capture volumes exist, this is applied to both volumes. 139 | 140 | .TP 141 | \fBamixer \-c 2 cset iface=MIXER,name='Line Playback Volume",index=1 40%\fR 142 | will set the third soundcard's second line playback volume(s) to 40% 143 | 144 | .TP 145 | \fBamixer \-c 2 cset numid=34 40%\fR 146 | will set the 34th soundcard element to 40% 147 | 148 | .SH SEE ALSO 149 | \fB 150 | alsamixer(1) 151 | \fP 152 | 153 | .SH BUGS 154 | None known. 155 | 156 | .SH AUTHOR 157 | \fBamixer\fP is by Jaroslav Kysela . 158 | This document is by Paul Winkler and Jaroslav Kysela . 159 | -------------------------------------------------------------------------------- /alsamixer/device_name.c: -------------------------------------------------------------------------------- 1 | /* 2 | * device_name_form.c - ask for sound control device name 3 | * Copyright (c) Clemens Ladisch 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "aconfig.h" 20 | #include 21 | #include 22 | #include CURSESINC 23 | #include 24 | #include "gettext_curses.h" 25 | #include "die.h" 26 | #include "mem.h" 27 | #include "utils.h" 28 | #include "colors.h" 29 | #include "widget.h" 30 | #include "mixer_widget.h" 31 | #include "card_select.h" 32 | #include "device_name.h" 33 | 34 | static struct widget form_widget; 35 | static FIELD *fields[3]; 36 | static FORM *form; 37 | 38 | static char *dup_current_name(void) 39 | { 40 | int rows, cols, max, i; 41 | char *s; 42 | 43 | if (form_driver(form, REQ_VALIDATION) == E_OK) { 44 | dynamic_field_info(fields[1], &rows, &cols, &max); 45 | s = ccalloc(1, cols + 1); 46 | memcpy(s, field_buffer(fields[1], 0), cols); 47 | for (i = strlen(s) - 1; i >= 0 && s[i] == ' '; --i) 48 | s[i] = '\0'; 49 | return s; 50 | } else { 51 | return cstrdup(""); 52 | } 53 | } 54 | 55 | static void on_key_enter(void) 56 | { 57 | char *s; 58 | bool ok; 59 | 60 | s = dup_current_name(); 61 | ok = select_card_by_name(s); 62 | free(s); 63 | if (ok) { 64 | form_widget.close(); 65 | close_card_select_list(); 66 | } 67 | } 68 | 69 | static void on_form_key(int key) 70 | { 71 | static const struct { 72 | int key; 73 | int request; 74 | } key_map[] = { 75 | { KEY_LEFT, REQ_PREV_CHAR }, 76 | { KEY_RIGHT, REQ_NEXT_CHAR }, 77 | { KEY_HOME, REQ_BEG_FIELD }, 78 | { KEY_BACKSPACE, REQ_DEL_PREV }, 79 | { KEY_DC, REQ_DEL_CHAR }, 80 | { KEY_BEG, REQ_BEG_FIELD }, 81 | { KEY_END, REQ_END_FIELD }, 82 | }; 83 | unsigned int i; 84 | 85 | if (key >= 32 && key < 256) { 86 | form_driver(form, key); 87 | return; 88 | } 89 | for (i = 0; i < ARRAY_SIZE(key_map); ++i) 90 | if (key_map[i].key == key) { 91 | form_driver(form, key_map[i].request); 92 | break; 93 | } 94 | } 95 | 96 | static void on_handle_key(int key) 97 | { 98 | switch (key) { 99 | case 27: 100 | case KEY_CANCEL: 101 | form_widget.close(); 102 | break; 103 | case 10: 104 | case 13: 105 | case KEY_ENTER: 106 | on_key_enter(); 107 | break; 108 | default: 109 | on_form_key(key); 110 | break; 111 | } 112 | } 113 | 114 | static bool create(void) 115 | { 116 | const char *title; 117 | 118 | if (screen_lines < 6 || screen_cols < 36) { 119 | form_widget.close(); 120 | beep(); 121 | return FALSE; 122 | } 123 | widget_init(&form_widget, 124 | 6, 36, SCREEN_CENTER, SCREEN_CENTER, 125 | attr_textbox, WIDGET_BORDER | WIDGET_SUBWINDOW | WIDGET_CURSOR_VISIBLE); 126 | title = _("Sound Card"); 127 | mvwprintw(form_widget.window, 0, (36 - 2 - get_mbs_width(title)) / 2, " %s ", title); 128 | 129 | set_form_win(form, form_widget.window); 130 | set_form_sub(form, form_widget.subwindow); 131 | return TRUE; 132 | } 133 | 134 | static void on_window_size_changed(void) 135 | { 136 | form_driver(form, REQ_VALIDATION); /* save field value */ 137 | unpost_form(form); 138 | 139 | if (!create()) 140 | return; 141 | 142 | /* 143 | * This call fails because ncurses does not allow changing options of 144 | * the current field, and we cannot change the current field because 145 | * there is only one. The only way to make this work would be to throw 146 | * away and recreate all fields. 147 | */ 148 | field_opts_off(fields[1], O_BLANK); 149 | 150 | post_form(form); 151 | } 152 | 153 | static void on_close(void) 154 | { 155 | unpost_form(form); 156 | free_form(form); 157 | free_field(fields[0]); 158 | free_field(fields[1]); 159 | widget_free(&form_widget); 160 | } 161 | 162 | static struct widget form_widget = { 163 | .handle_key = on_handle_key, 164 | .window_size_changed = on_window_size_changed, 165 | .close = on_close, 166 | }; 167 | 168 | void create_device_name_form(void) 169 | { 170 | fields[0] = new_field(1, 32, 1, 1, 0, 0); 171 | if (!fields[0]) 172 | fatal_error("cannot create field"); 173 | field_opts_off(fields[0], O_ACTIVE); 174 | field_opts_off(fields[0], O_EDIT); 175 | set_field_fore(fields[0], attr_textbox); 176 | set_field_back(fields[0], attr_textbox); 177 | set_field_buffer(fields[0], 0, _("Device name:")); 178 | 179 | fields[1] = new_field(1, 32, 2, 1, 0, 0); 180 | if (!fields[1]) 181 | fatal_error("cannot create field"); 182 | field_opts_off(fields[1], O_AUTOSKIP); 183 | field_opts_off(fields[1], O_NULLOK); 184 | field_opts_off(fields[1], O_STATIC); 185 | set_field_fore(fields[1], attr_textfield); 186 | set_field_back(fields[1], attr_textfield); 187 | set_field_buffer(fields[1], 0, mixer_device_name); 188 | 189 | form = new_form(fields); 190 | if (!form) 191 | fatal_error("cannot create form"); 192 | 193 | if (!create()) 194 | return; 195 | 196 | post_form(form); 197 | } 198 | -------------------------------------------------------------------------------- /alsactl/alsactl.1: -------------------------------------------------------------------------------- 1 | .TH ALSACTL 1 "07 May 2014" 2 | .SH NAME 3 | alsactl \- advanced controls for ALSA soundcard driver 4 | 5 | .SH SYNOPSIS 6 | 7 | \fBalsactl\fP [\fIoptions\fP] [\fIstore\fP|\fIrestore\fP|\fIinit\fP] 8 | 9 | \fBalsactl\fP \fImonitor\fP 10 | 11 | .SH DESCRIPTION 12 | \fBalsactl\fP is used to control advanced settings for the ALSA 13 | soundcard drivers. It supports multiple soundcards. If your card has 14 | features that you can't seem to control from a mixer application, 15 | you have come to the right place. 16 | 17 | .SH COMMANDS 18 | 19 | \fIstore\fP saves the current driver state for the selected soundcard 20 | to the configuration file. 21 | 22 | \fIrestore\fP loads driver state for the selected soundcard from the 23 | configuration file. If restoring fails (eventually partly), the init 24 | action is called. 25 | 26 | \fInrestore\fP is like \fIrestore\fP, but it notifies also the daemon 27 | to do new rescan for available soundcards. 28 | 29 | \fIinit\fP tries to initialize all devices to a default state. If device 30 | is not known, error code 99 is returned. 31 | 32 | \fIdaemon\fP manages to save periodically the sound state. 33 | 34 | \fIrdaemon\fP like \fIdaemon\fP but restore the sound state at first. 35 | 36 | \fIkill\fP notifies the daemon to do the specified operation (quit, 37 | rescan, save_and_quit). 38 | 39 | \fImonitor\fP is for monitoring the events received from the given 40 | control device. 41 | 42 | If no soundcards are specified, setup for all cards will be saved, 43 | loaded or monitored. 44 | 45 | .SH OPTIONS 46 | 47 | .TP 48 | \fI\-h, \-\-help\fP 49 | Help: show available flags and commands. 50 | 51 | .TP 52 | \fI\-d, \-\-debug\fP 53 | Use debug mode: a bit more verbose. 54 | 55 | .TP 56 | \fI\-v, \-\-version\fP 57 | Print alsactl version number. 58 | 59 | .TP 60 | \fI\-f, \-\-file\fP 61 | Select the configuration file to use. The default is /var/lib/alsa/asound.state. 62 | 63 | .TP 64 | \fI\-l, \-\-lock\fP 65 | Use the file locking to serialize the concurrent access to the state file (this 66 | option is default for the global state file). 67 | 68 | .TP 69 | \fI\-L, \-\-no-lock\fP 70 | Do not use the file locking to serialize the concurrent access to the state 71 | file (including the global state file). 72 | 73 | .TP 74 | \fI\-O, \-\-lock-state-file\fP 75 | Select the state lock file path. 76 | 77 | .TP 78 | \fI\-F, \-\-force\fP 79 | Used with restore command. Try to restore the matching control elements 80 | as much as possible. This option is set as default now. 81 | 82 | .TP 83 | \fI\-g, \-\-ignore\fP 84 | Used with store and restore commands. Do not show 'No soundcards found' 85 | and do not set an error exit code when soundcards are not installed. 86 | 87 | .TP 88 | \fI\-P, \-\-pedantic\fP 89 | Used with restore command. Don't restore mismatching control elements. 90 | This option was the old default behavior. 91 | 92 | .TP 93 | \fI\-I, \-\-no\-init\-fallback\fP 94 | Don't initialize cards if restore fails. Since version 1.0.18, 95 | \fBalsactl\fP tries to initialize the card with the restore operation 96 | as default. But this can cause incompatibility with the older version. 97 | The caller may expect that the state won't be touched if no state file 98 | exists. This option takes the restore behavior back to the older 99 | version by suppressing the initialization. 100 | 101 | .TP 102 | \fI\-r, \-\-runstate\fP 103 | Save restore and init state to this file. The file will contain only errors. 104 | Errors are appended with the soundcard id to the end of file. 105 | 106 | .TP 107 | \fI\-R, \-\-remove\fP 108 | Remove runstate file at first. 109 | 110 | .TP 111 | \fI\-E, \-\-env\fP #=# 112 | Set environment variable (useful for init action or you may override 113 | ALSA_CONFIG_PATH to read different or optimized configuration - may be 114 | useful for "boot" scripts). 115 | 116 | .TP 117 | \fI\-i, \-\-initfile\fP 118 | The configuration file for init. By default, PREFIX/share/alsa/init/00main 119 | is used. 120 | 121 | .TP 122 | \fI\-p, \-\-period\fP 123 | The store period in seconds for the daemon command. 124 | 125 | .TP 126 | \fI\-e, \-\-pid-file\fP 127 | The pathname to store the process-id file in the HDB UUCP format (ASCII). 128 | 129 | .TP 130 | \fI\-b, \-\-background\fP 131 | Run the task in background. 132 | 133 | .TP 134 | \fI\-s, \-\-syslog\fP 135 | Use syslog for messages. 136 | 137 | .TP 138 | \fI\-n, \-\-nice\fP 139 | Set the process priority (see 'man nice') 140 | 141 | .TP 142 | \fI\-c, \-\-sched-idle\fP 143 | Set the process scheduling policy to idle (SCHED_IDLE). 144 | 145 | .SH FILES 146 | \fI/var/lib/alsa/asound.state\fP (or whatever file you specify with the 147 | \fB\-f\fP flag) is used to store current settings for your 148 | soundcards. The settings include all the usual soundcard mixer 149 | settings. More importantly, alsactl is 150 | capable of controlling other card-specific features that mixer apps 151 | usually don't know about. 152 | 153 | The configuration file is generated automatically by running 154 | \fBalsactl store\fP. Editing the configuration file by hand may be 155 | necessary for some soundcard features (e.g. enabling/disabling 156 | automatic mic gain, digital output, joystick/game ports, some future MIDI 157 | routing options, etc). 158 | 159 | .SH SEE ALSO 160 | \fB 161 | amixer(1), 162 | alsamixer(1), 163 | aplay(1), 164 | alsactl_init(7) 165 | \fP 166 | 167 | .SH BUGS 168 | None known. 169 | 170 | .SH AUTHOR 171 | \fBalsactl\fP is by Jaroslav Kysela and Abramo Bagnara 172 | . This document is by Paul Winkler . 173 | -------------------------------------------------------------------------------- /speaker-test/speaker-test.1: -------------------------------------------------------------------------------- 1 | .\" -*- nroff -*- 2 | .\" macros 3 | .de EX \" Begin Example 4 | . IP 5 | . ft CW 6 | . nf 7 | . ne \\$1 8 | .. 9 | .de EE \" End Example 10 | . ft P 11 | . fi 12 | . PP 13 | .. 14 | .TH SPEAKER\-TEST 1 "April 2nd, 2011" speaker\-test 15 | .SH NAME 16 | speaker\-test \- command\-line speaker test tone generator for ALSA 17 | .SH SYNOPSIS 18 | .B speaker\-test [\-options] 19 | 20 | .SH DESCRIPTION 21 | \fBspeaker\-test\fP generates a tone that can be used to test the speakers of a computer. 22 | 23 | \fBspeaker\-test\fP by default will test the \fIdefault\fP device. If you 24 | want to test another sound device you will have first to get a list of 25 | all of the sound cards in your system and the devices associated with 26 | those cards. Notice that there might be for example, one device for 27 | analog sound, one for digital sound and one for HDMI sound. 28 | To get the list of available cards and devices you can run \fBaplay \-L\fR. 29 | 30 | .P \fBaplay\fR's output will be similar to this one: 31 | 32 | .nf 33 | $ aplay \-L 34 | null 35 | Discard all samples (playback) or generate zero samples (capture) 36 | default:CARD=ICH5 37 | Intel ICH5, Intel ICH5 38 | Default Audio Device 39 | front:CARD=ICH5,DEV=0 40 | Intel ICH5, Intel ICH5 41 | Front speakers 42 | surround40:CARD=ICH5,DEV=0 43 | Intel ICH5, Intel ICH5 44 | 4.0 Surround output to Front and Rear speakers 45 | (...) 46 | .fi 47 | 48 | .P Each of the devices is listed in the beginning of the definition so, 49 | in the above example, there are four devices listed: null, default, front 50 | and surround40. So, if you want to test the last device you can 51 | run \fBspeaker\-test \-Dsurround40:ICH5 \-c 6\fR. The \fB\-c\fR option will 52 | indicate that the six audio channels in the device have to be tested. 53 | 54 | 55 | 56 | 57 | 58 | .SH OPTIONS 59 | 60 | .TP 61 | \fB\-c\fP | \fB\-\-channels\fP \fINUM\fP 62 | \fINUM\fP channels in stream 63 | 64 | .TP 65 | \fB\-D\fP | \fB\-\-device\fP \fINAME\fP 66 | PCM device name \fINAME\fP 67 | 68 | .TP 69 | \fB\-f\fP | \fB\-\-frequency\fP \fIFREQ\fP 70 | sine wave of \fIFREQ\fP Hz 71 | 72 | .TP 73 | \fB\-\-help\fP 74 | Print usage help 75 | 76 | .TP 77 | \fB\-b\fP | \fB\-\-buffer\fP \fITIME\fP 78 | Use buffer size of \fITIME\fP microseconds. 79 | When 0 is given, use the maximal buffer size. 80 | The default value is 0. 81 | 82 | .TP 83 | \fB\-p\fP | \fB\-\-period\fP \fITIME\fP 84 | Use period size of \fITIME\fP microseconds. 85 | When 0 is given, the periods given by \fB\-P\fP option is used. 86 | The default value is 0. 87 | 88 | .TP 89 | \fB\-P\fP | \fB\-\-nperiods\fP \fIPERIODS\fP 90 | Use number of periods. The default value is 4. 91 | 92 | .TP 93 | \fB\-r\fP | \fB\-\-rate\fP \fIRATE\fP 94 | stream of \fIRATE\fP Hz 95 | 96 | .TP 97 | \fB\-t\fP | \fB\-\-test\fP \fBpink\fP|\fBsine\fP|\fBwav\fP 98 | \fB\-t pink\fP means use pink noise (default). 99 | 100 | Pink noise is perceptually uniform noise -- that is, it sounds like every frequency at once. If you can hear any tone it may indicate resonances in your speaker system or room. 101 | 102 | \fB\-t sine\fP means to use sine wave. 103 | 104 | \fB\-t wav\fP means to play WAV files, either pre-defined files or given via \fB\-w\fP option. 105 | 106 | You can pass the number from 1 to 3 as a backward compatibility. 107 | 108 | .TP 109 | \fB\-l\fP | \fB\-\-nloops\fP \fICOUNT\fP 110 | 111 | Specifies the number of loops. Zero means to run infinitely. 112 | 113 | When \fB\-s\fP option below with a valid channel is given, \fBspeaker\-test\fP will perform 114 | always a single-shot without looping. 115 | 116 | .TP 117 | \fB\-s\fP | \fB\-\-speaker\fP \fICHANNEL\fP 118 | Do a single-shot speaker test for the given channel. The channel number starts from 1. 119 | The channel number corresponds to left, right, rear-left, rear-right, center, LFE, 120 | side-left, side-right, and so on. 121 | 122 | For example, when 1 is passed, it tests the left channel only once rather than both channels 123 | with looping. 124 | 125 | .TP 126 | \fB\-w\fP | \fB\-\-wavfile\fP \fIFILE\fP 127 | Use the given WAV file for the playback instead of pre-defined WAV files. 128 | 129 | .TP 130 | \fB\-W\fP | \fB\-\-wavdir\fP \fIDIRECTORY\fP 131 | Specify the directory containing WAV files for playback. 132 | The default path is \fI/usr/share/sounds/alsa\fP. 133 | 134 | .TP 135 | \fB\-m\fP | \fB\-\-chmap\fP \fIMAP\fP 136 | Pass the channel map to override. 137 | If the playback in a specific channel order or channel positions is 138 | required, pass the channel position strings to this option. 139 | 140 | .TP 141 | \fB\-X\fP | \fB\-\-force-frequency\fP 142 | Allow supplied \fIFREQ\fP to be outside the default range of 30-8000Hz. A minimum of 1Hz is still enforced. 143 | 144 | .SH USAGE EXAMPLES 145 | 146 | Produce stereo sound from one stereo jack: 147 | .EX 148 | speaker\-test \-Dplug:front \-c2 149 | .EE 150 | 151 | Produce 4 speaker sound from two stereo jacks: 152 | .EX 153 | speaker\-test \-Dplug:surround40 \-c4 154 | .EE 155 | 156 | Produce 5.1 speaker sound from three stereo jacks: 157 | .EX 158 | speaker\-test \-Dplug:surround51 \-c6 159 | .EE 160 | 161 | To send a nice low 75Hz tone to the Woofer and then exit without touching any other speakers: 162 | .EX 163 | speaker\-test \-Dplug:surround51 \-c6 \-s1 \-f75 164 | .EE 165 | 166 | To do a 2\-speaker test using the spdif (coax or optical) output: 167 | .EX 168 | speaker\-test \-Dplug:spdif \-c2 169 | .EE 170 | 171 | Play in the order of front\-right and front-left from the front PCM 172 | .EX 173 | speaker\-test \-Dplug:front \-c2 \-mFR,FL 174 | .EE 175 | 176 | .SH SEE ALSO 177 | .BR aplay(1) 178 | 179 | .SH AUTHOR 180 | The speaker\-test program was written by James Courtier-Dutton. 181 | Pink noise support was added by Nathan Hurst. 182 | Further extensions by Takashi Iwai. 183 | -------------------------------------------------------------------------------- /alsaloop/alsaloop.1: -------------------------------------------------------------------------------- 1 | .TH ALSALOOP 1 "5 Aug 2010" 2 | .SH NAME 3 | alsaloop \- command\-line PCM loopback 4 | .SH SYNOPSIS 5 | \fBalsaloop\fP [\fI\-option\fP] [\fIcmd\fP] 6 | .SH DESCRIPTION 7 | 8 | \fBalsaloop\fP allows create a PCM loopback between a PCM capture device 9 | and a PCM playback device. 10 | 11 | \fBalsaloop\fP supports multiple soundcards, adaptive clock synchronization, 12 | adaptive rate resampling using the samplerate library (if available in 13 | the system). Also, mixer controls can be redirected from one card to 14 | another (for example Master and PCM). 15 | 16 | .SH OPTIONS 17 | 18 | .TP 19 | \fI\-h\fP | \fI\-\-help\fP 20 | 21 | Prints the help information. 22 | 23 | .TP 24 | \fI\-g \fP | \fI\-\-config=\fP 25 | 26 | Use given configuration file. The syntax of this file is simple: one line 27 | contains the command line options for one job. The '#' means comment and 28 | rest of line is ignored. Example: 29 | 30 | # First line \- comment, second line \- first job 31 | \-C hw:1,0 \-P hw:0,0 \-t 50000 \-T 1 32 | # Third line \- comment, fourth line \- second job 33 | \-C hw:1,1 \-P hw:0,1 \-t 40000 \-T 2 34 | 35 | .TP 36 | \fI\-d\fP | \fI\-\-daemonize\fP 37 | 38 | Daemonize the main process and use syslog for messages. 39 | 40 | .TP 41 | \fI\-P \fP | \fI\-\-pdevice=\fP 42 | 43 | Use given playback device. 44 | 45 | .TP 46 | \fI\-C \fP | \fI\-\-cdevice=\fP 47 | 48 | Use given capture device. 49 | 50 | .TP 51 | \fI\-X \fP | \fI\-\-pctl=\fP 52 | 53 | Use given CTL device for playback. 54 | 55 | .TP 56 | \fI\-Y \fP | \fI\-\-cctl=\fP 57 | 58 | Use given CTL device for capture. 59 | 60 | .TP 61 | \fI\-l \fP | \fI\-\-latency=\fP 62 | 63 | Requested latency in frames. 64 | 65 | .TP 66 | \fI\-t \fP | \fI\-\-tlatency=\fP 67 | 68 | Requested latency in usec (1/1000000sec). 69 | 70 | .TP 71 | \fI\-f \fP | \fI\-\-format=\fP 72 | 73 | Format specification (usually S16_LE S32_LE). Use \-h to list all formats. 74 | Default format is S16_LE. 75 | 76 | .TP 77 | \fI\-c \fP | \fI\-\-channels=\fP 78 | 79 | Channel count specification. Default value is 2. 80 | 81 | .TP 82 | \fI\-c \fP | \fI\-\-rate=\fP 83 | 84 | Rate specification. Default value is 48000 (Hz). 85 | 86 | .TP 87 | \fI\-n\fP | \fI\-\-resample\fP 88 | 89 | Allow rate resampling using alsa\-lib. 90 | 91 | .TP 92 | \fI\-A \fP | \fI\-\-samplerate=\fP 93 | 94 | Use libsamplerate and choose a converter: 95 | 96 | 0 or sincbest \- best quality 97 | 1 or sincmedium \- medium quality 98 | 2 or sincfastest \- lowest quality 99 | 3 or zerohold \- hold zero samples 100 | 4 or linear \- worst quality - linear resampling 101 | 5 or auto \- choose best method 102 | 103 | .TP 104 | \fI\-B \fP | \fI\-\-buffer=\fP 105 | 106 | Buffer size in frames. 107 | 108 | .TP 109 | \fI\-E \fP | \fI\-\-period=\fP 110 | 111 | Period size in frames. 112 | 113 | .TP 114 | \fI\-s \fP | \fI\-\-seconds=\fP 115 | 116 | Duration of loop in seconds. 117 | 118 | .TP 119 | \fI\-b\fP | \fI\-\-nblock\fP 120 | 121 | Non\-block mode (very early process wakeup). Eats more CPU. 122 | 123 | .TP 124 | \fI\-S \fP | \fI\-\-sync=\fP 125 | 126 | Sync mode specification for capture to playback stream: 127 | 0 or none \- do not touch the stream 128 | 1 or simple \- add or remove samples to keep 129 | both streams synchronized 130 | 2 or captshift \- use driver for the capture device 131 | (if supported) to compensate 132 | the rate shift 133 | 3 or playshift \- use driver for the playback device 134 | (if supported) to compensate 135 | the rate shift 136 | 4 or samplerate \- use samplerate library to do rate resampling 137 | 5 or auto \- automatically selects the best method 138 | in this order: captshift, playshift, 139 | samplerate, simple 140 | 141 | .TP 142 | \fI\-T \fP | \fI\-\-thread=\fP 143 | 144 | Thread number (\-1 means create a unique thread). All jobs with same 145 | thread numbers are run within one thread. 146 | 147 | .TP 148 | \fI\-m \fP | \fI\-\-mixer=\fP 149 | 150 | Redirect mixer control from the playback card to the capture card. Format of 151 | \fImixid\fP is SRCID(PLAYBACK)[@DSTID(PLAYBACK)]: 152 | 153 | "name='Master Playback Switch'@name='Another Switch'" 154 | "name='PCM Playback Volume'" 155 | 156 | Known attributes: 157 | 158 | name \- control ID name 159 | index \- control ID index 160 | device \- control ID device 161 | subdevice \- control ID subdevice 162 | iface \- control ID interface 163 | numid \- control ID numid 164 | 165 | .TP 166 | \fI\-O \fP | \fI\-\-ossmixer=\fP 167 | 168 | Redirect mixer control from the OSS Mixer emulation layer (capture card) 169 | to the ALSA layer (capture card). Format of \fIossmixid\fP is 170 | ALSAID[,INDEX]@OSSID: 171 | 172 | "Master@VOLUME" 173 | "PCM,1@ALTPCM" 174 | 175 | Known OSS attributes: 176 | 177 | VOLUME, BASS, TREBLE, SYNTH, PCM, SPEAKER, LINE, MIC, CD, IMIX, ALTPCM, 178 | RECLEV, IGAIN, OGAIN, LINE1, LINE2, LINE3, DIGITAL1, DIGITAL2, DIGITAL3, 179 | PHONEIN, PHONEOUT, VIDEO, RADIO, MONITOR 180 | 181 | .TP 182 | \fI\-v\fP | \fI\-\-verbose\fP 183 | 184 | Verbose mode. Use multiple times to increase verbosity. 185 | 186 | 187 | .TP 188 | \fI\-U\fP | \fI\-\-xrun\fP 189 | 190 | Verbose xrun profiling. 191 | 192 | .TP 193 | \fI\-W \fP | \fI\-\-wake=\fP 194 | 195 | Set process wake timeout. 196 | 197 | .SH EXAMPLES 198 | 199 | .TP 200 | \fBalsaloop \-C hw:0,0 \-P hw:1,0 \-t 50000\fR 201 | 202 | .SH BUGS 203 | None known. 204 | .SH AUTHOR 205 | \fBalsaloop\fP is by Jaroslav Kysela . 206 | This document is by Jaroslav Kysela . 207 | -------------------------------------------------------------------------------- /bat/signal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Caleb Crome 3 | * Copyright (C) 2013-2015 Intel Corporation 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | */ 16 | 17 | /* 18 | * This is a general purpose sine wave generator that will stay stable 19 | * for a long time, and with a little renormalization, could stay stay 20 | * stable indefinitely 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "gettext.h" 33 | #include "common.h" 34 | #include "signal.h" 35 | 36 | /* 37 | * Initialize the sine wave generator. 38 | * sin_generator: gets initialized by this call. 39 | * frequency: the frequency for the sine wave. must be < 0.5*sample_rate 40 | * sample_rate: the sample rate... 41 | * returns 0 on success, -1 on error. 42 | */ 43 | int sin_generator_init(struct sin_generator *sg, float magnitude, 44 | float frequency, float sample_rate) 45 | { 46 | /* angular frequency: cycles/sec / (samp/sec) * rad/cycle = rad/samp */ 47 | float w = frequency / sample_rate * 2 * M_PI; 48 | if (frequency >= sample_rate / 2) 49 | return -1; 50 | sg->phasor_real = cos(w); 51 | sg->phasor_imag = sin(w); 52 | sg->magnitude = magnitude; 53 | sg->state_real = 0.0; 54 | sg->state_imag = magnitude; 55 | sg->frequency = frequency; 56 | sg->sample_rate = sample_rate; 57 | return 0; 58 | } 59 | 60 | /* 61 | * Generates the next sample in the sine wave. 62 | * should be much faster than calling a sin function 63 | * if it's inlined and optimized. 64 | * 65 | * returns the next value. no possibility of error. 66 | */ 67 | float sin_generator_next_sample(struct sin_generator *sg) 68 | { 69 | /* get shorthand to pointers */ 70 | const double pr = sg->phasor_real; 71 | const double pi = sg->phasor_imag; 72 | const double sr = sg->state_real; 73 | const double si = sg->state_imag; 74 | /* step the phasor -- complex multiply */ 75 | sg->state_real = sr * pr - si * pi; 76 | sg->state_imag = sr * pi + pr * si; 77 | /* return the input value so sine wave starts at exactly 0.0 */ 78 | return (float)sr; 79 | } 80 | 81 | /* fills a vector with a sine wave */ 82 | void sin_generator_vfill(struct sin_generator *sg, float *buf, int n) 83 | { 84 | int i; 85 | for (i = 0; i < n; i++) 86 | *buf++ = sin_generator_next_sample(sg); 87 | } 88 | 89 | static int reorder(struct bat *bat, float *val, int frames) 90 | { 91 | float *new_buf = NULL; 92 | int i, c, bytes; 93 | 94 | bytes = frames * bat->channels * sizeof(float); 95 | 96 | new_buf = (float *) malloc(bytes); 97 | if (new_buf == NULL) { 98 | fprintf(bat->err, _("Not enough memory.\n")); 99 | return -ENOMEM; 100 | } 101 | 102 | memcpy(new_buf, val, bytes); 103 | for (i = 0; i < frames; i++) 104 | for (c = 0; c < bat->channels; c++) 105 | val[i * bat->channels + c] = 106 | new_buf[c * frames + i]; 107 | free(new_buf); 108 | 109 | return 0; 110 | } 111 | 112 | static int adjust_waveform(struct bat *bat, float *val, int frames, 113 | int channels) 114 | { 115 | int i, nsamples, max; 116 | float factor, offset = 0.0; 117 | 118 | switch (bat->format) { 119 | case BAT_PCM_FORMAT_U8: 120 | max = INT8_MAX; 121 | offset = max; /* shift for unsigned format */ 122 | break; 123 | case BAT_PCM_FORMAT_S16_LE: 124 | max = INT16_MAX; 125 | break; 126 | case BAT_PCM_FORMAT_S24_3LE: 127 | max = (1 << 23) - 1; 128 | break; 129 | case BAT_PCM_FORMAT_S32_LE: 130 | max = INT32_MAX; 131 | break; 132 | default: 133 | fprintf(bat->err, _("Invalid PCM format: %d\n"), bat->format); 134 | return -EINVAL; 135 | } 136 | 137 | factor = max * RANGE_FACTOR; 138 | nsamples = channels * frames; 139 | 140 | for (i = 0; i < nsamples; i++) 141 | val[i] = val[i] * factor + offset; 142 | 143 | return 0; 144 | } 145 | 146 | int generate_sine_wave(struct bat *bat, int frames, void *buf) 147 | { 148 | int err = 0; 149 | int c, nsamples; 150 | float *sinus_f = NULL; 151 | static struct sin_generator sg[MAX_CHANNELS]; 152 | 153 | nsamples = bat->channels * frames; 154 | sinus_f = (float *) malloc(nsamples * sizeof(float)); 155 | if (sinus_f == NULL) { 156 | fprintf(bat->err, _("Not enough memory.\n")); 157 | return -ENOMEM; 158 | } 159 | 160 | for (c = 0; c < bat->channels; c++) { 161 | /* initialize static struct at the first time */ 162 | if (sg[c].frequency != bat->target_freq[c]) 163 | sin_generator_init(&sg[c], 1.0, bat->target_freq[c], 164 | bat->rate); 165 | /* fill buffer for each channel */ 166 | sin_generator_vfill(&sg[c], sinus_f + c * frames, frames); 167 | } 168 | 169 | /* reorder samples to interleaved mode */ 170 | err = reorder(bat, sinus_f, frames); 171 | if (err != 0) 172 | goto exit; 173 | 174 | /* adjust amplitude and offset of waveform */ 175 | err = adjust_waveform(bat, sinus_f, frames, bat->channels); 176 | if (err != 0) 177 | goto exit; 178 | 179 | bat->convert_float_to_sample(sinus_f, buf, frames, bat->channels); 180 | 181 | exit: 182 | free(sinus_f); 183 | 184 | return err; 185 | } 186 | 187 | /* generate single channel sine waveform without sample conversion */ 188 | int generate_sine_wave_raw_mono(struct bat *bat, float *buf, 189 | float freq, int nsamples) 190 | { 191 | int err = 0; 192 | struct sin_generator sg; 193 | 194 | err = sin_generator_init(&sg, 1.0, freq, bat->rate); 195 | if (err < 0) 196 | return err; 197 | sin_generator_vfill(&sg, buf, nsamples); 198 | 199 | /* adjust amplitude and offset of waveform */ 200 | err = adjust_waveform(bat, buf, nsamples, 1); 201 | 202 | return err; 203 | } 204 | -------------------------------------------------------------------------------- /alsamixer/volume_mapping.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Clemens Ladisch 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * The functions in this file map the value ranges of ALSA mixer controls onto 19 | * the interval 0..1. 20 | * 21 | * The mapping is designed so that the position in the interval is proportional 22 | * to the volume as a human ear would perceive it (i.e., the position is the 23 | * cubic root of the linear sample multiplication factor). For controls with 24 | * a small range (24 dB or less), the mapping is linear in the dB values so 25 | * that each step has the same size visually. Only for controls without dB 26 | * information, a linear mapping of the hardware volume register values is used 27 | * (this is the same algorithm as used in the old alsamixer). 28 | * 29 | * When setting the volume, 'dir' is the rounding direction: 30 | * -1/0/1 = down/nearest/up. 31 | */ 32 | 33 | #define _ISOC99_SOURCE /* lrint() */ 34 | #define _GNU_SOURCE /* exp10() */ 35 | #include "aconfig.h" 36 | #include 37 | #include 38 | #include "volume_mapping.h" 39 | 40 | #ifdef __UCLIBC__ 41 | /* 10^x = 10^(log e^x) = (e^x)^log10 = e^(x * log 10) */ 42 | #define exp10(x) (exp((x) * log(10))) 43 | #endif /* __UCLIBC__ */ 44 | 45 | #define MAX_LINEAR_DB_SCALE 24 46 | 47 | static inline bool use_linear_dB_scale(long dBmin, long dBmax) 48 | { 49 | return dBmax - dBmin <= MAX_LINEAR_DB_SCALE * 100; 50 | } 51 | 52 | static long lrint_dir(double x, int dir) 53 | { 54 | if (dir > 0) 55 | return lrint(ceil(x)); 56 | else if (dir < 0) 57 | return lrint(floor(x)); 58 | else 59 | return lrint(x); 60 | } 61 | 62 | enum ctl_dir { PLAYBACK, CAPTURE }; 63 | 64 | static int (* const get_dB_range[2])(snd_mixer_elem_t *, long *, long *) = { 65 | snd_mixer_selem_get_playback_dB_range, 66 | snd_mixer_selem_get_capture_dB_range, 67 | }; 68 | static int (* const get_raw_range[2])(snd_mixer_elem_t *, long *, long *) = { 69 | snd_mixer_selem_get_playback_volume_range, 70 | snd_mixer_selem_get_capture_volume_range, 71 | }; 72 | static int (* const get_dB[2])(snd_mixer_elem_t *, snd_mixer_selem_channel_id_t, long *) = { 73 | snd_mixer_selem_get_playback_dB, 74 | snd_mixer_selem_get_capture_dB, 75 | }; 76 | static int (* const get_raw[2])(snd_mixer_elem_t *, snd_mixer_selem_channel_id_t, long *) = { 77 | snd_mixer_selem_get_playback_volume, 78 | snd_mixer_selem_get_capture_volume, 79 | }; 80 | static int (* const set_dB[2])(snd_mixer_elem_t *, snd_mixer_selem_channel_id_t, long, int) = { 81 | snd_mixer_selem_set_playback_dB, 82 | snd_mixer_selem_set_capture_dB, 83 | }; 84 | static int (* const set_raw[2])(snd_mixer_elem_t *, snd_mixer_selem_channel_id_t, long) = { 85 | snd_mixer_selem_set_playback_volume, 86 | snd_mixer_selem_set_capture_volume, 87 | }; 88 | 89 | static double get_normalized_volume(snd_mixer_elem_t *elem, 90 | snd_mixer_selem_channel_id_t channel, 91 | enum ctl_dir ctl_dir) 92 | { 93 | long min, max, value; 94 | double normalized, min_norm; 95 | int err; 96 | 97 | err = get_dB_range[ctl_dir](elem, &min, &max); 98 | if (err < 0 || min >= max) { 99 | err = get_raw_range[ctl_dir](elem, &min, &max); 100 | if (err < 0 || min == max) 101 | return 0; 102 | 103 | err = get_raw[ctl_dir](elem, channel, &value); 104 | if (err < 0) 105 | return 0; 106 | 107 | return (value - min) / (double)(max - min); 108 | } 109 | 110 | err = get_dB[ctl_dir](elem, channel, &value); 111 | if (err < 0) 112 | return 0; 113 | 114 | if (use_linear_dB_scale(min, max)) 115 | return (value - min) / (double)(max - min); 116 | 117 | normalized = exp10((value - max) / 6000.0); 118 | if (min != SND_CTL_TLV_DB_GAIN_MUTE) { 119 | min_norm = exp10((min - max) / 6000.0); 120 | normalized = (normalized - min_norm) / (1 - min_norm); 121 | } 122 | 123 | return normalized; 124 | } 125 | 126 | static int set_normalized_volume(snd_mixer_elem_t *elem, 127 | snd_mixer_selem_channel_id_t channel, 128 | double volume, 129 | int dir, 130 | enum ctl_dir ctl_dir) 131 | { 132 | long min, max, value; 133 | double min_norm; 134 | int err; 135 | 136 | err = get_dB_range[ctl_dir](elem, &min, &max); 137 | if (err < 0 || min >= max) { 138 | err = get_raw_range[ctl_dir](elem, &min, &max); 139 | if (err < 0) 140 | return err; 141 | 142 | value = lrint_dir(volume * (max - min), dir) + min; 143 | return set_raw[ctl_dir](elem, channel, value); 144 | } 145 | 146 | if (use_linear_dB_scale(min, max)) { 147 | value = lrint_dir(volume * (max - min), dir) + min; 148 | return set_dB[ctl_dir](elem, channel, value, dir); 149 | } 150 | 151 | if (min != SND_CTL_TLV_DB_GAIN_MUTE) { 152 | min_norm = exp10((min - max) / 6000.0); 153 | volume = volume * (1 - min_norm) + min_norm; 154 | } 155 | value = lrint_dir(6000.0 * log10(volume), dir) + max; 156 | return set_dB[ctl_dir](elem, channel, value, dir); 157 | } 158 | 159 | double get_normalized_playback_volume(snd_mixer_elem_t *elem, 160 | snd_mixer_selem_channel_id_t channel) 161 | { 162 | return get_normalized_volume(elem, channel, PLAYBACK); 163 | } 164 | 165 | double get_normalized_capture_volume(snd_mixer_elem_t *elem, 166 | snd_mixer_selem_channel_id_t channel) 167 | { 168 | return get_normalized_volume(elem, channel, CAPTURE); 169 | } 170 | 171 | int set_normalized_playback_volume(snd_mixer_elem_t *elem, 172 | snd_mixer_selem_channel_id_t channel, 173 | double volume, 174 | int dir) 175 | { 176 | return set_normalized_volume(elem, channel, volume, dir, PLAYBACK); 177 | } 178 | 179 | int set_normalized_capture_volume(snd_mixer_elem_t *elem, 180 | snd_mixer_selem_channel_id_t channel, 181 | double volume, 182 | int dir) 183 | { 184 | return set_normalized_volume(elem, channel, volume, dir, CAPTURE); 185 | } 186 | -------------------------------------------------------------------------------- /bat/alsabat.1: -------------------------------------------------------------------------------- 1 | .TH ALSABAT 1 "20th October 2015" 2 | .SH NAME 3 | alsabat \- command\-line sound tester for ALSA sound card driver 4 | 5 | .SH SYNOPSIS 6 | \fBalsabat\fP [\fIflags\fP] 7 | 8 | .SH DESCRIPTION 9 | \fBALSABAT(ALSA Basic Audio Tester)\fP is a simple command\-line utility 10 | intended to help automate audio driver and sound server testing with little 11 | human interaction. ALSABAT can be used to test audio quality, stress test 12 | features and test audio before and after PM state changes. 13 | 14 | ALSABAT's design is relatively simple. ALSABAT plays an audio stream and 15 | captures the same stream in either a digital or analog loop back. It then 16 | compares the captured stream using a FFT to the original to determine if 17 | the test case passes or fails. 18 | 19 | ALSABAT can either run wholly on the target machine being tested (standalone 20 | mode) or can run as a client/server mode where by alsabat client runs on the 21 | target and runs as a server on a separate tester machine. The client/server 22 | mode still requires some manual interaction for synchronization, but this 23 | is actively being developed for future releases. 24 | 25 | The hardware testing configuration may require the use of an analog cable 26 | connecting target to tester machines or a cable to create an analog 27 | loopback if no loopback mode is not available on the sound hardware that 28 | is being tested. 29 | An analog loopback cable can be used to connect the "line in" to "line out" 30 | jacks to create a loopback. If only headphone and mic jacks (or combo jack) 31 | are available then the following simple circuit can be used to create an 32 | analog loopback :- 33 | 34 | https://source.android.com/devices/audio/loopback.html 35 | 36 | If tinyalsa is installed in system, user can choose tinyalsa as backend lib 37 | of alsabat, with configure option "--enable-alsabat-backend-tiny". 38 | 39 | .SH OPTIONS 40 | .TP 41 | \fI\-h, \-\-help\fP 42 | Help: show syntax. 43 | .TP 44 | \fI\-D\fP 45 | Select sound card to be tested by name. 46 | .TP 47 | \fI\-P\fP 48 | Select the playback PCM device. 49 | .TP 50 | \fI\-C\fP 51 | Select the capture PCM device. 52 | .TP 53 | \fI\-f\fP 54 | Sample format 55 | .br 56 | Recognized sample formats are: U8 S16_LE S24_3LE S32_LE 57 | .br 58 | Some of these may not be available on selected hardware 59 | .br 60 | The available format shortcuts are: 61 | .nf 62 | \-f cd (16 bit little endian, 44100, stereo) [\-f S16_LE \-c2 \-r44100] 63 | \-f dat (16 bit little endian, 48000, stereo) [\-f S16_LE \-c2 \-r48000] 64 | .fi 65 | If no format is given S16_LE is used. 66 | .TP 67 | \fI\-c\fP 68 | The number of channels. The default is one channel. 69 | Valid values at the moment are 1 or 2. 70 | .TP 71 | \fI\-r\fP 72 | Sampling rate in Hertz. The default rate is 44100 Hertz. 73 | Valid values depends on hardware support. 74 | .TP 75 | \fI\-n\fP 76 | Duration of generated signal. 77 | The value could be either of the two forms: 78 | .br 79 | 1. Decimal integer, means number of frames; 80 | .br 81 | 2. Floating point with suffix 's', means number of seconds. 82 | .br 83 | The default is 2 seconds. 84 | .TP 85 | \fI\-k\fP 86 | Sigma k value for analysis. 87 | .br 88 | The analysis function reads data from WAV file, run FFT against the data 89 | to get magnitude of frequency vectors, and then calculates the average 90 | value and standard deviation of frequency vectors. After that, we define 91 | a threshold: 92 | .br 93 | threshold = k * standard_deviation + mean_value 94 | .br 95 | Frequencies with amplitude larger than threshold will be recognized as a 96 | peak, and the frequency with largest peak value will be recognized as a 97 | detected frequency. 98 | .br 99 | ALSABAT then compares the detected frequency to target frequency, to 100 | decide if the detecting passes or fails. 101 | .br 102 | The default value is 3.0. 103 | .TP 104 | \fI\-F\fP 105 | Target frequency for signal generation and analysis, in Hertz. 106 | The default is 997.0 Hertz. 107 | Valid range is (DC_THRESHOLD, 40% * Sampling rate). 108 | .TP 109 | \fI\-p\fP 110 | Total number of periods to play or capture. 111 | .TP 112 | \fI\-\-log=#\fP 113 | Write stderr and stdout output to this log file. 114 | .TP 115 | \fI\-\-file=#\fP 116 | Input WAV file for playback. 117 | .TP 118 | \fI\-\-saveplay=#\fP 119 | Target WAV file to save capture test content. 120 | .TP 121 | \fI\-\-local\fP 122 | Internal loopback mode. 123 | Playback, capture and analysis internal to ALSABAT only. This is intended 124 | for developers to test new ALSABAT features as no audio is routed outside 125 | of ALSABAT. 126 | .TP 127 | \fI\-\-standalone\fP 128 | Add support for standalone mode where ALSABAT will run on a different machine 129 | to the one being tested. 130 | In standalone mode, the sound data can be generated, playback and captured 131 | just like in normal mode, but will not be analyzed. 132 | The ALSABAT being built without libfftw3 support is always in standalone mode. 133 | The ALSABAT in normal mode can also bypass data analysis using option 134 | "--standalone". 135 | .TP 136 | \fI\-\-roundtriplatency\fP 137 | Round trip latency test. 138 | Audio latency is the time delay as an audio signal passes through a system. 139 | There are many kinds of audio latency metrics. One useful metric is the 140 | round trip latency, which is the sum of output latency and input latency. 141 | .TP 142 | \fI\-\-snr\-db=#\fP 143 | Noise detection threshold in SNR (dB). 26dB indicates 5% noise in amplitude. 144 | ALSABAT will return error if signal SNR is smaller than the threshold. 145 | .TP 146 | \fI\-\-snr\-pc=#\fP 147 | Noise detection threshold in percentage of noise amplitude (%). 148 | ALSABAT will return error if the noise amplitude is larger than the threshold. 149 | 150 | .SH EXAMPLES 151 | 152 | .TP 153 | \fBalsabat \-P plughw:0,0 \-C plughw:0,0 \-c 2 \-f S32_LE \-F 250\fR 154 | Generate and play a sine wave of 250 Hertz with 2 channel and S32_LE format, 155 | and then capture and analyze. 156 | 157 | .TP 158 | \fBalsabat \-P plughw:0,0 \-C plughw:0,0 \-\-file 500Hz.wav\fR 159 | Play the RIFF WAV file "500Hz.wav" which contains 500 Hertz waveform LPCM 160 | data, and then capture and analyze. 161 | 162 | .SH RETURN VALUE 163 | .br 164 | On success, returns 0. 165 | .br 166 | If no peak be detected, returns -1001; 167 | .br 168 | If only DC be detected, returns -1002; 169 | .br 170 | If peak frequency does not match with the target frequency, returns -1003. 171 | 172 | .SH SEE ALSO 173 | \fB 174 | aplay(1) 175 | \fP 176 | 177 | .SH BUGS 178 | Currently only support RIFF WAV format with PCM data. Please report any bugs to 179 | the alsa-devel mailing list. 180 | 181 | .SH AUTHOR 182 | \fBalsabat\fP is by Liam Girdwood , Bernard 183 | Gautier and Han Lu . 184 | This document is by Liam Girdwood and Han Lu 185 | . 186 | -------------------------------------------------------------------------------- /alsamixer/card_select.c: -------------------------------------------------------------------------------- 1 | /* 2 | * card_select.c - select a card by list or device name 3 | * Copyright (c) Clemens Ladisch 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "aconfig.h" 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "gettext_curses.h" 26 | #include "die.h" 27 | #include "mem.h" 28 | #include "utils.h" 29 | #include "colors.h" 30 | #include "widget.h" 31 | #include "mixer_widget.h" 32 | #include "device_name.h" 33 | #include "card_select.h" 34 | 35 | struct card { 36 | struct card *next; 37 | char *indexstr; 38 | char *name; 39 | char *device_name; 40 | }; 41 | 42 | static struct widget list_widget; 43 | static struct card first_card; 44 | static ITEM **items; 45 | static MENU *menu; 46 | static ITEM *initial_item; 47 | 48 | static void on_key_enter(void) 49 | { 50 | ITEM *item = current_item(menu); 51 | if (item) { 52 | struct card *card = item_userptr(item); 53 | if (card->device_name) { 54 | if (select_card_by_name(card->device_name)) 55 | list_widget.close(); 56 | } else { 57 | create_device_name_form(); 58 | } 59 | } 60 | } 61 | 62 | static void on_menu_key(int key) 63 | { 64 | static const struct { 65 | int key; 66 | int request; 67 | } key_map[] = { 68 | { KEY_DOWN, REQ_DOWN_ITEM }, 69 | { KEY_UP, REQ_UP_ITEM }, 70 | { KEY_HOME, REQ_FIRST_ITEM }, 71 | { KEY_NPAGE, REQ_SCR_DPAGE }, 72 | { KEY_PPAGE, REQ_SCR_UPAGE }, 73 | { KEY_BEG, REQ_FIRST_ITEM }, 74 | { KEY_END, REQ_LAST_ITEM }, 75 | }; 76 | unsigned int i; 77 | 78 | for (i = 0; i < ARRAY_SIZE(key_map); ++i) 79 | if (key_map[i].key == key) { 80 | menu_driver(menu, key_map[i].request); 81 | break; 82 | } 83 | } 84 | 85 | static void on_handle_key(int key) 86 | { 87 | switch (key) { 88 | case 27: 89 | case KEY_CANCEL: 90 | case 'q': 91 | case 'Q': 92 | list_widget.close(); 93 | break; 94 | case 10: 95 | case 13: 96 | case KEY_ENTER: 97 | on_key_enter(); 98 | break; 99 | default: 100 | on_menu_key(key); 101 | break; 102 | } 103 | } 104 | 105 | static bool create(void) 106 | { 107 | int rows, columns; 108 | const char *title; 109 | 110 | if (screen_lines < 3 || screen_cols < 10) { 111 | beep(); 112 | list_widget.close(); 113 | return FALSE; 114 | } 115 | scale_menu(menu, &rows, &columns); 116 | rows += 2; 117 | columns += 2; 118 | if (rows > screen_lines) 119 | rows = screen_lines; 120 | if (columns > screen_cols) 121 | columns = screen_cols; 122 | 123 | widget_init(&list_widget, rows, columns, SCREEN_CENTER, SCREEN_CENTER, 124 | attr_menu, WIDGET_BORDER | WIDGET_SUBWINDOW); 125 | 126 | title = _("Sound Card"); 127 | mvwprintw(list_widget.window, 0, (columns - 2 - get_mbs_width(title)) / 2, " %s ", title); 128 | set_menu_win(menu, list_widget.window); 129 | set_menu_sub(menu, list_widget.subwindow); 130 | return TRUE; 131 | } 132 | 133 | static void on_window_size_changed(void) 134 | { 135 | unpost_menu(menu); 136 | if (!create()) 137 | return; 138 | post_menu(menu); 139 | } 140 | 141 | static void on_close(void) 142 | { 143 | unsigned int i; 144 | struct card *card, *next_card; 145 | 146 | unpost_menu(menu); 147 | free_menu(menu); 148 | for (i = 0; items[i]; ++i) 149 | free_item(items[i]); 150 | free(items); 151 | for (card = first_card.next; card; card = next_card) { 152 | next_card = card->next; 153 | free(card->indexstr); 154 | free(card->name); 155 | free(card->device_name); 156 | free(card); 157 | } 158 | widget_free(&list_widget); 159 | } 160 | 161 | void close_card_select_list(void) 162 | { 163 | on_close(); 164 | } 165 | 166 | static struct widget list_widget = { 167 | .handle_key = on_handle_key, 168 | .window_size_changed = on_window_size_changed, 169 | .close = on_close, 170 | }; 171 | 172 | static int get_cards(void) 173 | { 174 | int count, number, err; 175 | snd_ctl_t *ctl; 176 | snd_ctl_card_info_t *info; 177 | char buf[16]; 178 | struct card *card, *prev_card; 179 | 180 | first_card.indexstr = "-"; 181 | first_card.name = _("(default)"); 182 | first_card.device_name = "default"; 183 | count = 1; 184 | 185 | snd_ctl_card_info_alloca(&info); 186 | prev_card = &first_card; 187 | number = -1; 188 | for (;;) { 189 | err = snd_card_next(&number); 190 | if (err < 0) 191 | fatal_alsa_error(_("cannot enumerate sound cards"), err); 192 | if (number < 0) 193 | break; 194 | sprintf(buf, "hw:%d", number); 195 | err = snd_ctl_open(&ctl, buf, 0); 196 | if (err < 0) 197 | continue; 198 | err = snd_ctl_card_info(ctl, info); 199 | snd_ctl_close(ctl); 200 | if (err < 0) 201 | continue; 202 | card = ccalloc(1, sizeof *card); 203 | sprintf(buf, "%d", number); 204 | card->indexstr = cstrdup(buf); 205 | card->name = cstrdup(snd_ctl_card_info_get_name(info)); 206 | sprintf(buf, "hw:%d", number); 207 | card->device_name = cstrdup(buf); 208 | prev_card->next = card; 209 | prev_card = card; 210 | ++count; 211 | } 212 | 213 | card = ccalloc(1, sizeof *card); 214 | card->indexstr = cstrdup(" "); 215 | card->name = cstrdup(_("enter device name...")); 216 | prev_card->next = card; 217 | ++count; 218 | 219 | return count; 220 | } 221 | 222 | static void create_list_items(int cards) 223 | { 224 | int i; 225 | struct card *card; 226 | ITEM *item; 227 | 228 | initial_item = NULL; 229 | items = ccalloc(cards + 1, sizeof(ITEM*)); 230 | i = 0; 231 | for (card = &first_card; card; card = card->next) { 232 | item = new_item(card->indexstr, card->name); 233 | if (!item) 234 | fatal_error("cannot create menu item"); 235 | set_item_userptr(item, card); 236 | items[i++] = item; 237 | if (!initial_item && 238 | mixer_device_name && 239 | (!card->device_name || 240 | !strcmp(card->device_name, mixer_device_name))) 241 | initial_item = item; 242 | } 243 | assert(i == cards); 244 | } 245 | 246 | void create_card_select_list(void) 247 | { 248 | int cards; 249 | 250 | cards = get_cards(); 251 | create_list_items(cards); 252 | 253 | menu = new_menu(items); 254 | if (!menu) 255 | fatal_error("cannot create menu"); 256 | set_menu_fore(menu, attr_menu_selected); 257 | set_menu_back(menu, attr_menu); 258 | set_menu_mark(menu, NULL); 259 | if (initial_item) 260 | set_current_item(menu, initial_item); 261 | set_menu_spacing(menu, 2, 1, 1); 262 | menu_opts_on(menu, O_SHOWDESC); 263 | 264 | if (!create()) 265 | return; 266 | 267 | post_menu(menu); 268 | } 269 | --------------------------------------------------------------------------------