Channel-Mapping-API.txt 5.7 KB

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