Channel-Mapping-API.txt 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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_FL, /* front left */
  64. SNDRV_CHMAP_FC, /* front center */
  65. SNDRV_CHMAP_FR, /* front right */
  66. SNDRV_CHMAP_FLC, /* front left center */
  67. SNDRV_CHMAP_FRC, /* front right center */
  68. SNDRV_CHMAP_RL, /* rear left */
  69. SNDRV_CHMAP_RC, /* rear center */
  70. SNDRV_CHMAP_RR, /* rear right */
  71. SNDRV_CHMAP_RLC, /* rear left center */
  72. SNDRV_CHMAP_RRC, /* rear right center */
  73. SNDRV_CHMAP_SL, /* side left */
  74. SNDRV_CHMAP_SR, /* side right */
  75. SNDRV_CHMAP_LFE, /* LFE */
  76. SNDRV_CHMAP_FLW, /* front left wide */
  77. SNDRV_CHMAP_FRW, /* front right wide */
  78. SNDRV_CHMAP_FLH, /* front left high */
  79. SNDRV_CHMAP_FCH, /* front center high */
  80. SNDRV_CHMAP_FRH, /* front right high */
  81. SNDRV_CHMAP_TC, /* top center */
  82. SNDRV_CHMAP_NA, /* N/A, silent */
  83. SNDRV_CHMAP_LAST = SNDRV_CHMAP_NA,
  84. };
  85. When a PCM stream can provide more than one channel map, you can
  86. provide multiple channel maps in a TLV container type. The TLV data
  87. to be returned will contain such as:
  88. SNDRV_CTL_TLVT_CONTAINER 96
  89. SNDRV_CTL_TLVT_CHMAP_FIXED 4 SNDRV_CHMAP_FC
  90. SNDRV_CTL_TLVT_CHMAP_FIXED 8 SNDRV_CHMAP_FL SNDRV_CHMAP_FR
  91. SNDRV_CTL_TLVT_CHMAP_FIXED 16 NDRV_CHMAP_FL SNDRV_CHMAP_FR \
  92. SNDRV_CHMAP_RL SNDRV_CHMAP_RR
  93. The channel position is provided in LSB 16bits. The upper bits are
  94. used for bit flags.
  95. #define SNDRV_CHMAP_POSITION_MASK 0xffff
  96. #define SNDRV_CHMAP_PHASE_INVERSE (0x01 << 16)
  97. #define SNDRV_CHMAP_DRIVER_SPEC (0x02 << 16)
  98. SNDRV_CHMAP_PHASE_INVERSE indicates the channel is phase inverted,
  99. (thus summing left and right channels would result in almost silence).
  100. Some digital mic devices have this.
  101. When SNDRV_CHMAP_DRIVER_SPEC is set, all the channel position values
  102. don't follow the standard definition above but driver-specific.
  103. * READ OPERATION
  104. The control read operation is for providing the current channel map of
  105. the given stream. The control element returns an integer array
  106. containing the position of each channel.
  107. When this is performed before the number of the channel is specified
  108. (i.e. hw_params is set), it should return all channels set to
  109. UNKNOWN.
  110. * WRITE OPERATION
  111. The control write operation is optional, and only for devices that can
  112. change the channel configuration on the fly, such as HDMI. User needs
  113. to pass an integer value containing the valid channel positions for
  114. all channels of the assigned PCM substream.
  115. This operation is allowed only at PCM PREPARED state. When called in
  116. other states, it shall return an error.