channel-mapping-api.rst 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. ============================
  2. ALSA PCM channel-mapping API
  3. ============================
  4. Takashi Iwai <[email protected]>
  5. General
  6. =======
  7. The channel mapping API allows user to query the possible channel maps
  8. and the current channel map, also optionally to modify the channel map
  9. of the current stream.
  10. A channel map is an array of position for each PCM channel.
  11. Typically, a stereo PCM stream has a channel map of
  12. ``{ front_left, front_right }``
  13. while a 4.0 surround PCM stream has a channel map of
  14. ``{ front left, front right, rear left, rear right }.``
  15. The problem, so far, was that we had no standard channel map
  16. explicitly, and applications had no way to know which channel
  17. corresponds to which (speaker) position. Thus, applications applied
  18. wrong channels for 5.1 outputs, and you hear suddenly strange sound
  19. from rear. Or, some devices secretly assume that center/LFE is the
  20. third/fourth channels while others that C/LFE as 5th/6th channels.
  21. Also, some devices such as HDMI are configurable for different speaker
  22. positions even with the same number of total channels. However, there
  23. was no way to specify this because of lack of channel map
  24. specification. These are the main motivations for the new channel
  25. mapping API.
  26. Design
  27. ======
  28. Actually, "the channel mapping API" doesn't introduce anything new in
  29. the kernel/user-space ABI perspective. It uses only the existing
  30. control element features.
  31. As a ground design, each PCM substream may contain a control element
  32. providing the channel mapping information and configuration. This
  33. element is specified by:
  34. * iface = SNDRV_CTL_ELEM_IFACE_PCM
  35. * name = "Playback Channel Map" or "Capture Channel Map"
  36. * device = the same device number for the assigned PCM substream
  37. * index = the same index number for the assigned PCM substream
  38. Note the name is different depending on the PCM substream direction.
  39. Each control element provides at least the TLV read operation and the
  40. read operation. Optionally, the write operation can be provided to
  41. allow user to change the channel map dynamically.
  42. TLV
  43. ---
  44. The TLV operation gives the list of available channel
  45. maps. A list item of a channel map is usually a TLV of
  46. ``type data-bytes ch0 ch1 ch2...``
  47. where type is the TLV type value, the second argument is the total
  48. bytes (not the numbers) of channel values, and the rest are the
  49. position value for each channel.
  50. As a TLV type, either ``SNDRV_CTL_TLVT_CHMAP_FIXED``,
  51. ``SNDRV_CTL_TLV_CHMAP_VAR`` or ``SNDRV_CTL_TLVT_CHMAP_PAIRED`` can be used.
  52. The ``_FIXED`` type is for a channel map with the fixed channel position
  53. while the latter two are for flexible channel positions. ``_VAR`` type is
  54. for a channel map where all channels are freely swappable and ``_PAIRED``
  55. type is where pair-wise channels are swappable. For example, when you
  56. have {FL/FR/RL/RR} channel map, ``_PAIRED`` type would allow you to swap
  57. only {RL/RR/FL/FR} while ``_VAR`` type would allow even swapping FL and
  58. RR.
  59. These new TLV types are defined in ``sound/tlv.h``.
  60. The available channel position values are defined in ``sound/asound.h``,
  61. here is a cut:
  62. ::
  63. /* channel positions */
  64. enum {
  65. SNDRV_CHMAP_UNKNOWN = 0,
  66. SNDRV_CHMAP_NA, /* N/A, silent */
  67. SNDRV_CHMAP_MONO, /* mono stream */
  68. /* this follows the alsa-lib mixer channel value + 3 */
  69. SNDRV_CHMAP_FL, /* front left */
  70. SNDRV_CHMAP_FR, /* front right */
  71. SNDRV_CHMAP_RL, /* rear left */
  72. SNDRV_CHMAP_RR, /* rear right */
  73. SNDRV_CHMAP_FC, /* front center */
  74. SNDRV_CHMAP_LFE, /* LFE */
  75. SNDRV_CHMAP_SL, /* side left */
  76. SNDRV_CHMAP_SR, /* side right */
  77. SNDRV_CHMAP_RC, /* rear center */
  78. /* new definitions */
  79. SNDRV_CHMAP_FLC, /* front left center */
  80. SNDRV_CHMAP_FRC, /* front right center */
  81. SNDRV_CHMAP_RLC, /* rear left center */
  82. SNDRV_CHMAP_RRC, /* rear right center */
  83. SNDRV_CHMAP_FLW, /* front left wide */
  84. SNDRV_CHMAP_FRW, /* front right wide */
  85. SNDRV_CHMAP_FLH, /* front left high */
  86. SNDRV_CHMAP_FCH, /* front center high */
  87. SNDRV_CHMAP_FRH, /* front right high */
  88. SNDRV_CHMAP_TC, /* top center */
  89. SNDRV_CHMAP_TFL, /* top front left */
  90. SNDRV_CHMAP_TFR, /* top front right */
  91. SNDRV_CHMAP_TFC, /* top front center */
  92. SNDRV_CHMAP_TRL, /* top rear left */
  93. SNDRV_CHMAP_TRR, /* top rear right */
  94. SNDRV_CHMAP_TRC, /* top rear center */
  95. SNDRV_CHMAP_LAST = SNDRV_CHMAP_TRC,
  96. };
  97. When a PCM stream can provide more than one channel map, you can
  98. provide multiple channel maps in a TLV container type. The TLV data
  99. to be returned will contain such as:
  100. ::
  101. SNDRV_CTL_TLVT_CONTAINER 96
  102. SNDRV_CTL_TLVT_CHMAP_FIXED 4 SNDRV_CHMAP_FC
  103. SNDRV_CTL_TLVT_CHMAP_FIXED 8 SNDRV_CHMAP_FL SNDRV_CHMAP_FR
  104. SNDRV_CTL_TLVT_CHMAP_FIXED 16 NDRV_CHMAP_FL SNDRV_CHMAP_FR \
  105. SNDRV_CHMAP_RL SNDRV_CHMAP_RR
  106. The channel position is provided in LSB 16bits. The upper bits are
  107. used for bit flags.
  108. ::
  109. #define SNDRV_CHMAP_POSITION_MASK 0xffff
  110. #define SNDRV_CHMAP_PHASE_INVERSE (0x01 << 16)
  111. #define SNDRV_CHMAP_DRIVER_SPEC (0x02 << 16)
  112. ``SNDRV_CHMAP_PHASE_INVERSE`` indicates the channel is phase inverted,
  113. (thus summing left and right channels would result in almost silence).
  114. Some digital mic devices have this.
  115. When ``SNDRV_CHMAP_DRIVER_SPEC`` is set, all the channel position values
  116. don't follow the standard definition above but driver-specific.
  117. Read Operation
  118. --------------
  119. The control read operation is for providing the current channel map of
  120. the given stream. The control element returns an integer array
  121. containing the position of each channel.
  122. When this is performed before the number of the channel is specified
  123. (i.e. hw_params is set), it should return all channels set to
  124. ``UNKNOWN``.
  125. Write Operation
  126. ---------------
  127. The control write operation is optional, and only for devices that can
  128. change the channel configuration on the fly, such as HDMI. User needs
  129. to pass an integer value containing the valid channel positions for
  130. all channels of the assigned PCM substream.
  131. This operation is allowed only at PCM PREPARED state. When called in
  132. other states, it shall return an error.