cheatsheet.zwischenspeicher.info

Some tech documentation and snippets, finally organized.
Posts tagged as audio

Burning a mixed-mode CD-R

It is possible to "enhance" an audio CD with arbitrary files as a bonus track. The following post shows how to create such a mixed-mode CD or enhanced CD on the command line.

Create suitable wav files with libav-tools

$ cd $AUDIOSOURCEDIR
$ for i in $(ls); do avconv -i $i /path/to/outdir/$i.wav; done

Note: ffmpeg will work as well, with the same syntax and options: just /avconv/ffmpeg/.

Burn the audio-tracks

$ cd $WAVDIR
$ wodim -v dev=/dev/sr0 speed=4 -multi -audio *.wav

The -multi switch (for multi session) is necessary to prevent wodim from closing the disk after burning. Additionally, I use the slow speed=4 option to burn sharper delimited dots and thus enhance the disk's readability in older (or dusty) audio players.

Analyze the audio-session and prepare the "bonus track"

$ TRACKINFO=`cdrecord -msinfo dev=1,0,0`
$ echo $TRACKINFO
  0,105248

In this case, the first session started at sector 0 and the following will start at sector 105248. This information can now be passed to mkisofs or the newer xorrisofs:

$ xorrisofs -J -r -C $TRACKINFO -V $16_CHAR_DISKLABEL -o /path/to/data.iso /path/to/data

Append the iso to the disk

$ wodim -v dev=/dev/sr0 -data /path/to/data.iso

The resulting CD will serve the first session to all common audio CD players, while the second (data) session can be accessed with a CD-ROM drive.

Note: Not all CD-ROM drives support mixed-mode media - some may fail to access the audio tracks from the first session.

X11 screencast (with audio)

Screenrecording of a 1024x768 pixel area, with an x/y-offset of 80/120px. Sound is recorded at a bitrate of 128kb/s from the analog input of the default ALSA sound card, the outline of the captured region is displayed on screen:

avconv -f x11grab -show_region 1 \
       -s 1024x768 -i :0.0+80,120 \
       -f alsa -i hw:0 \
       -b:v 1200k -b:a 128k \
       -y ~/screencast.mpg

Don't forget to check the mixer settings!


Recording sound from another application instead of an external source requires to modprobe the snd_aloop kernel module and a line of ALSA configuration:

### File: ~/.asoundrc

pcm.!default { type plug slave.pcm "hw:Loopback,0,0" }

Additionally, the avconv audio input parameters need to be changed to

-f alsa -i hw:Loopback,1,0

The configuration of an optional output channel for audio monitoring is described here at ffmpeg.org.

ALSA: changing audio device priority

ALSA enumerates available audio devices in the order their corresponding kernel modules are loaded, so e.g. connecting an audio capable HDMI device can break on-board sound. For a permanent and system wide change of audio device priority, this order can be manipulated by adding a simple configuration file with the suffix .conf to the folder /etc/modprobe.d/.

First it needs to get a list of the loaded sound modules:

$ cat /proc/asound/modules
 0 MODULE_X
 1 MODULE_Y
 2 MODULE_Z

In the best case, all audio devices use different kernel modules, which will be listed, one per line, with the key options and an index value:

### File: /etc/modprobe.d/alsa.conf

options MODULE_1 index=0
options MODULE_2 index=1
options MODULE_3 index=2

If there are several audio devices based on the same chipset, additionally their associated card IDs need to be specified. The command

$ aplay -l | grep ^card

will return the necessary identifiers in the second column, right after card #:. Add them to the respective lines in /etc/modprobe.d/alsa.conf as new column three, between module name and index number.

To be prepared for the occasional use of a USB audio adapter, I suggest to additionally list the snd-usb-audio module and assign it index=0.

Here my current configuration:

### File: /etc/modprobe.d/alsa.conf

options snd-usb-audio               index=0
options snd-hda-intel   id=VT82xx   index=1
options snd-hda-intel   id=HDMI     index=2

Although this is Linux, the easiest way to make the changes take effect is to reboot the system ;)


If you have several devices with the same ID, you can make ALSA directly address the hardware by adding the following entries to /etc/asound.conf or ~/asoundrc - the respective card number can again be determined with the command aplay -l.

### File: /etc/asound.conf 
###       OR
###       ~/.asoundrc

pcm.!default {
    type hw
    card 1
}

ctl.!default {
    type hw
    card 1
}

Note: This way no other applications can access the sound card concurrently.


As a last solution, it is possible to fully disable specific cards with a line like the following in /etc/modprobe.d/alsa.conf:

### File: /etc/modprobe.d/alsa.conf

options snd-hda-intel   enable=0,1

The array will disable (0) the first and enable (1) the second of two cards.