Getting decent sound from built-in audio under Linux

Last modified: Sun Aug 6 13:05:02 EDT 2006


You have:

You want:  Decent audio under Linux.

Playback

Movies and music (digital stereo, Dolby Digital or DTS out)

The problem:  By default, only the analog channels are lit up, and they sound like crap.  High-powered CDs sound noisy and get worse when you max out the volume.

The solution:

  1. Install kernel version 2.6.12.2 or newer.  The correct ALSA driver should be enabled by default.  Using version 2.6.12.2 from kernel.org, the relevant checkbox in make menuconfig is Device Drivers → Sound → Advanced Linux Sound Architecture → PCI devices → Intel/SiS/nVidia/AMD/ALi AC97 Controller.

  2. Set up your receiver to use the digital S/PDIF signal.

  3. The mobo's sound hoobajoob only supports a 48 kHz sample rate.  To play a sound file, you want to convert it to a 48 kHz sample rate using polyphase resampling and then send it to your S/PDIF device.  For proof that polyphase is the best, see http://leute.server.de/wilde/resample.html.

    The sample rate conversion can be done using sox.  To find your S/PDIF device, type aplay --list-devices and look for likely candidates (such as things called IEC958).  In this case, it is card 0, device 4.

    bash-3.00$ aplay --list-devices
    **** List of PLAYBACK Hardware Devices ****
    card 0: ICH5 [Intel ICH5], device 0: Intel ICH [Intel ICH5]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    card 0: ICH5 [Intel ICH5], device 4: Intel ICH - IEC958 [Intel ICH5 - IEC958]
      Subdevices: 0/1
      Subdevice #0: subdevice #0
    

    Add the following function to your ~/.bashrc or ~/.bash_profile, substituting card and device numbers as appropriate on the aplay commands, and you will be able to play a stereo sound file from the command line by typing play soundfile.xyz.

    function play {
    
      # This function has a bunch of extra logic in it because (A) sox
      # doesn't decode flac files yet and (B) sox fails if you ask it to
      # resample something to its current sample rate.
    
      if [[ $1 == *.flac ]]; then
        { flac -s -d -c $1 | sox -t wav - -w -t wav -c 2 -r 48000 - polyphase ||
          flac -s -d -c $1 | sox -t wav - -w -t wav -c 2 - ;
        } | aplay -Dhw:0,4
      else
        { sox $1 -w -t wav -c 2 -r 48000 - polyphase ||
          sox $1 -w -t wav -c 2 - ;
        } | aplay -Dhw:0,4
      fi
    }
    

    The above examples work as of aplay version 1.0.9a, sox version 12.17.8 and bash version 3.00.16(2)-release.

  4. To get xine to pass Dolby Digital and DTS signals through to the receiver, do the following settings under right click → Settings → Setup.

    That works as of xine version 0.99.3.

Video games (5.1 analog out)

The problem:  Analog channels other than front left and right are totally fubar.

The solution:

I have only tested this as far as 5.1 sound, though the hardware supports 7.1.

Analog 5.1 output can be tested with the command speaker-test -b 8192 -Dplug:surround51 -c6.  (I did have problems with the default buffer size.)

The hard problem is that the sound does not go to the correct channels.  The fix for this is to replace the messed up ALSA config file /usr/share/alsa/cards/ICH4.conf with the corrected version that Uday Kumar Reddy Bondhugula is distributing from his ALSA Multi-channel Audio mini-HOWTO page and reboot.  Here is a cached copy.

Once the sound is going to the correct channels, there is still the matter of configuring things in alsamixer.  Use the following settings.

This works as of kernel version 2.6.17.4, alsamixer 1.0.11 and speaker-test 1.0.11.

Recording

The problem:  No matter what application and what settings you use, you only manage to record silence.

The solution:

(Assuming that you have already installed the latest kernel as discussed above)

To enable audio capture from line-in, you must run alsamixer -V capture and select the Aux device.

That's right, Aux, not Line!

Cursor over to Aux and press the space bar to select it.  Then cursor over to Capture and hold down the up arrow until it is at 100%.

Also run alsamixer without -V capture, un-mute the Aux playback device (press M) and set its volume at 100% so that you will be able to hear what you are doing.  You will have to switch your receiver back to analog to hear it.

As usual, your ALSA configuration can be saved to /etc/asound.state by running alsactl store as root and can be restored at boot time with alsactl restore.

To avoid problems, always record at 48 kHz, stereo, 16 bits, signed, little endian.

You can record in mhwaveedit if you select the ALSA driver on the Sound tab in Edit → Preferences and, using the nearby Settings button, set the recording device to hwmhwaveedit is good for recording because it gives you dials showing the amplitude of the signal coming in.

Wav file playback from mhwaveedit via ALSA used to go at the wrong sample rate if the device was set to plughw:0,4; now it is completely broken.  Under Preferences → Sound, set Driver to Open Sound System to use the OSS emulation modules instead.  Output will go to the analog channels.

You can also record from the command line using arecord, but then it's harder to calibrate the input volume.

Originally tested with mhwaveedit 1.4.2, arecord 1.0.8, alsamixer 1.0.8 and kernel version 2.6.12.2.  Since upgrading kernel, libraries, etc., ALSA playback broke and stayed broken even with a fresh build of mhwaveedit 1.4.8.  I have not yet tested recording ability with the new kernel or the surround sound hack.


KB
Home