[mythtv-users] Simultaneous analogue (analog) and S/PDIF output

Alex Butcher mythlist at assursys.co.uk
Thu Jan 13 21:53:26 UTC 2011


On Wed, 12 Jan 2011, Alex Butcher wrote:

>> So to summarise (again :) ):
>> Output device: ALSA:myfancymixer_i_created_in_asoundrc
> ALSA:both probably (as per .asoundrc), then.
>> Multichannel PCM uncheck
>> AC3 = DTS = check
>> Speakers 5.1
>> upmixer: uncheck
>> advanced: check
>> override passthrough: check
>> passthrough device: ALSA:iec958:AES0=6 (can probably use the default
>> entry: ALSA:iec958:{ AES0 0x2} ... )
>
> I was a bit puzzled as to whether the changed control word bitmask
> (<http://en.wikipedia.org/wiki/S/PDIF#Channel_status_bit>) would make any
> difference.  AES0=0x02 used to work with my receiver, and there would be 6
> channels of audio rather than 4 anyway...
>
>> if using updated version of 0.24
>> Output device: ALSA:myfancymixer_i_created_in_asoundrc
>> AC3 = DTS = check
>> Speakers 5.1
>> upmixer: uncheck
>> advanced: check
>> override passthrough: check
>> passthrough device: ALSA:iec958:AES0=6 (can probably use the default
>> entry: ALSA:iec958:{ AES0 0x2} ... )
>> StereoPCM: check
>
> Thank you for your patience and perseverance. I think I probably understand
> what's going on enough to get it working fully, and document it for others.
> We'll see...

OK, I've just spent the last 3 hours meticulously trying out all the
combinations based upon what Jean-Yves wrote.

Firstly, I upgraded to vanilla 0.24-fixes out of GIT. Next I started with
the .asoundrc from <http://mythtv.org/wiki/Configuring_Digital_Sound>
(both pieces). My complete .asoundrc follows:

=== CUT HERE ===

#from <http://mythtv.org/wiki/Configuring_Digital_Sound>
#see also <http://www.gossamer-threads.com/lists/mythtv/users/61265#61265>
#AJB20110113

# ~/.asoundrc or /etc/asound.conf
# ALSA configuration file

##### USAGE #####
# Save this file as "~/.asoundrc" (for user-specific sound configuration) or
# "/etc/asound.conf" (for system-wide sound configuration) and specify ALSA
# device names ad described in the next section.


##### DEVICE NAMES #####
# This configuration file defines four devices for use by the user.  Those
# devices are "analog", "mixed-analog", "digital", and "mixed-digital".  The
# user may also re-define "default" to be identical to one of the above-named
# devices (i.e. to send all sound output to the digital output unless otherwise
# specified).  Use the device names as described below:
#  - "analog" outputs to the analog output directly and (at least on software
#  sound cards) blocks other audio output.  After playback completes, "queued"
#  sounds are output in sequence.
#  - "mixed-analog" mixes audio output from multiple programs into the analog
#  output (so you can hear beeps, alerts, and other noises while playing back
#  an audio stream).
#  - "digital" outputs to the digital output directly.  Since most (all?)
#  digital outputs expect 48kHz PCM audio, this may not work for some playback
#  (i.e. CD's--which are 44.1kHz PCM audio--or 32kHz audio streams from TV
#  recordings, etc.).
#  - "mixed-digital"

# All other devices created within this file are used only by the configuration
# file itself and should /not/ be used directly.  In other words, do not use
# the devices "analog-hw", "dmix-analog", "digital-hw", or "dmix-digital".


##### IMPORTANT #####
# To make this ALSA configuration file work with your sound card, you will need
# to define the appropriate card and device information for the "analog-hw" and
# "digital-hw" devices below.  You can find the card and device information
# using "aplay -l".


##### Configuration File #####

# Override the default output used by ALSA.  If you do not override the
# default, your default device is identical to the (unmixed) "analog" device
# shown below.  If you prefer mixed and/or digital output, uncomment the
# appropriate four lines below (only one slave.pcm line).
#
# Note, also, that as of ALSA 1.0.9, "software" sound cards have been modified
# such that their default "default" device is identical to the "mixed-analog"
# device.  Whether using an ALSA version before or after 1.0.9, it does no harm
# and has no affect on performance to redefine the device (even if the
# redefinition does not change anything).  Also, by using this ALSA
# configuration file, you once again have access to unmixed analog output using
# the "analog" device.

pcm.!default {
   type plug
## Uncomment the following to use (unmixed) "analog" by default
#  slave.pcm "analog-hw"
## Uncomment the following to use "mixed-analog" by default

#AJB 20110113 was
#  slave.pcm "dmix-analog"
#make simultaneous analog and digital the default
slave.pcm "multi"

## Uncomment the following to use (unmixed) "digital" by default
#  slave.pcm "digital-hw"
## Uncomment the following to use "mixed-digital" by default
#  slave.pcm "dmix-digital"
}

# Control device (mixer, etc.) for the card
ctl.!default {
   type hw
   card 0
}

# Alias for (converted) analog output on the card
# - This is identical to the device named "default"--which always exists and
# refers to hw:0,0 (unless overridden)
# - Therefore, we can specify "hw:0,0", "default", or "analog" to access analog
# output on the card
# - Note that as of ALSA 1.0.9, "software" sound card definitions redefine
# "default" to do mixing, meaning this device is different from "default" and
# allows playback while blocking other sound sources (until playback
# completes).
pcm.analog {
   type plug
   slave.pcm "analog-hw"
   hint {
     show on
     description "Analog Output - Use analog outputs, converting samples, format, and rate as necessary."
   }
}

# Control device (mixer, etc.) for the card
ctl.analog {
   type hw
   card 0
}

# Alias for (converted) mixed analog output on the card
# - This will accept audio input--regardless of rate--and convert to the rate
# required for the dmix plugin (in this case 48000Hz)
# - Note that as of ALSA 1.0.9, "software" sound card definitions redefine
# "default" to do mixing, meaning this device is identical to "default" for
# "software" sound cards.
pcm.mixed-analog {
   type plug
   slave.pcm "dmix-analog"
   hint {
     show on
     description "Mixed Analog Output - Use analog outputs, converting samples, format, and rate as necessary. Allows mixing with system sounds."
   }
}

# Control device (mixer, etc.) for the card
ctl.mixed-analog {
   type hw
   card 0
}

# Alias for (converted) digital (S/PDIF) output on the card
# - This will accept audio input--regardless of rate--and convert to the rate
# required for the S/PDIF hardware (in this case 48000Hz)
pcm.digital {
   type plug
   slave.pcm "digital-hw"
   hint {
     show on
     description "Digital Output - Use digital outputs, converting samples, format, and rate as necessary."
   }
}

# Control device (mixer, etc.) for the card
ctl.digital {
   type hw
   card 0
}

# Alias for mixed (converted) digital (S/PDIF) output on the card
#  - This will accept audio input--regardless of rate--and convert to the rate
#  required for the S/PDIF hardware (in this case 48000Hz)
pcm.mixed-digital {
   type plug
   slave.pcm "dmix-digital"
   hint {
     show on
     description "Mixed Digital Output - Use digital outputs, converting samples, format, and rate as necessary. Allows mixing with system sounds."
   }
}

# Control device (mixer, etc.) for the card
ctl.mixed-digital {
   type hw
   card 0
}

# The following devices are not useful by themselves.  They require specific
# rates, channels, and formats.  Therefore, you probably do not want to use
# them directly.  Instead use of of the devices defined above.

# Alias for analog output on the card
# Do not use this directly--it requires specific rate, channels, and format
pcm.analog-hw {
   type hw
   card 0
   # The default value for device is 0, so no need to specify
#  - Uncomment one of the below or create a new "device N" line as appropriate
#    for your sound card
#  device 1
#  device 4
}

# Control device (mixer, etc.) for the card
ctl.analog-hw {
   type hw
   card 0
}

# Alias for digital (S/PDIF) output on the card
# Do not use this directly--it requires specific rate, channels, and format
pcm.digital-hw {
   type hw
   card 0
   device 1
#  - Comment out "device 1" above and uncomment one of the below or create a
#    new "device N" line as appropriate for your sound card
#  device 2
#  device 4
}

# Control device (mixer, etc.) for the card
ctl.digital-hw {
   type hw
   card 0
}

# Direct software mixing plugin for analog output on the card
# Do not use this directly--it requires specific rate, channels, and format
pcm.dmix-analog {
   type dmix
   ipc_key 1234
   slave {
     pcm "analog-hw"
     period_time 0
     period_size 1024
     buffer_size 4096
     rate 48000
   }
}

# Control device (mixer, etc.) for the card
ctl.dmix-analog {
   type hw
   card 0
}

# Direct software mixing plugin for digital (S/PDIF) output on the card
# Do not use this directly--it requires specific rate, channels, and format
pcm.dmix-digital {
   type dmix
   ipc_key 1235
   slave {
     pcm "digital-hw"
     period_time 0
     period_size 1024
     buffer_size 4096
     rate 48000
   }
}

# Control device (mixer, etc.) for the card
ctl.dmix-digital {
   type hw
   card 0
}

pcm.!default {
   type plug
   slave {
     pcm multi
     rate 48000
   }
   hint {
     show on
     description "Multiple Output - Use analog and digital outputs simultaneously"
   }
   ttable.0.0 1.0
   ttable.1.1 1.0
   ttable.0.2 1.0
   ttable.1.3 1.0
}

pcm.ajb {
   type plug
   slave {
     pcm multi
     rate 48000
   }
   hint {
     show on
     description "AJB Multiple Output - Use analog and digital outputs simultaneously"
   }
   ttable.0.0 1.0
   ttable.1.1 1.0
   ttable.0.2 1.0
   ttable.1.3 1.0
}

pcm.stereo {
   type plug
   slave {
     pcm multi
     rate 48000
   }
   hint {
     show on
     description "Multiple Stereo Output - Use analog and digital outputs simultaneously"
   }
   ttable.0.0 1.0
   ttable.1.1 1.0
   ttable.0.2 1.0
   ttable.1.3 1.0
}

ctl.stereo {
   type hw
   card 0
}

pcm.multi {
   type multi
   slaves.a.pcm "analog-hw"
   slaves.a.channels 2
   slaves.b.pcm "digital-hw"
   slaves.b.channels 2
   bindings.0.slave a
   bindings.0.channel 0
   bindings.1.slave a
   bindings.1.channel 1
   bindings.2.slave b
   bindings.2.channel 0
   bindings.3.slave b
   bindings.3.channel 1
   hint {
     show on
     description "Multiple Output - Use analog and digital outputs simultaneously"
   }
}

ctl.multi {
   type hw
   card 0
}

=== CUT HERE ===

I added some hint { show on } sections so those devices show up in the
output of aplay -L and in MythTV settings after a scan. I set pcm.default to
so that the 'multi' device defined therein is used as the default.

I eventually settled on the following combination of MythTV settings:

| AC3PassThru            | 0
| DTSPassThru            | 0
| PassThruOutputDevice   | ALSA:iec958:AES0=6
| PassThruDeviceOverride | 1
| MaxChannels            | 6
| StereoPCM              | 1
| AudioOutputDevice      | ALSA:ajb
| MythControlsVolume     | 1
| MixerDevice            | ALSA:default
| MixerControl           | PCM

Together, this provides simultaneous stereo output on both the S/PDIF and
the analogue front channels from my (stereo) UK DVB-T recordings and from
DD2.0/DD5.1/DTS DVD sources. :-)

Because StereoPCM is set to 1 (enabled), multi-channel audio (e.g.  from
Dolby Digital 5.1/DTS DVDs) is re-encoded to stereo.  Ah well, I've got a
real DVD player for when I want surround sound from DVDs.  Setting
AC3PassThru and/or DTSPassThru to 1 (enabled) silences the analogue output. 
:-(

If I unset StereoPCM and set AC3PassThru and DTSPassThru, I merely get
distorted versions of the DD5.1 and DTS soundtracks on both S/PDIF and the
analogue outputs.  More importantly, the analogue outputs are still silent. 
:-( Setting StereoPCM leaves the analogue outputs silent.  :-C

If I set StereoPCM, AC3PassThru and DTSPassThru to 1 (enabled) and unset
MythControlsVolume, thereby disabling MythTV's internal volume controls,
i.e.  completely to Jean-Yves' recommendations, then the analogue outputs
remain silent, but the AC3 and DTS passthru seems to work correctly apart
from no LFE output.  Maybe that's the source DVD I was using, but I don't
think so. I'd rather have analogue output and only 2.0 digital output from
DD5.1/DTS sources.

Maybe there's a tweak someone can suggest to my .asoundrc that will allow
AC3 and DTS passthru to work with >2 channel output, without silencing the
output to the analogue channels, but unless that happens, I think I've had
enough of fiddling with ALSA for the forseeable future.  Or maybe it's just
a bug in 0.24-fixes and the StereoPCM stuff. I'll let others pick through
that.

I hope this message helps save at least one person some of their time.

Best Regards,
Alex


More information about the mythtv-users mailing list