mixer.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /**
  2. * \file include/mixer.h
  3. * \brief Application interface library for the ALSA driver
  4. * \author Jaroslav Kysela <perex@perex.cz>
  5. * \author Abramo Bagnara <abramo@alsa-project.org>
  6. * \author Takashi Iwai <tiwai@suse.de>
  7. * \date 1998-2001
  8. *
  9. * Application interface library for the ALSA driver
  10. */
  11. /*
  12. * This library is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU Lesser General Public License as
  14. * published by the Free Software Foundation; either version 2.1 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public
  23. * License along with this library; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. *
  26. */
  27. #ifndef __ALSA_MIXER_H
  28. #define __ALSA_MIXER_H
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /**
  33. * \defgroup Mixer Mixer Interface
  34. * The mixer interface.
  35. * \{
  36. */
  37. /** Mixer handle */
  38. typedef struct _snd_mixer snd_mixer_t;
  39. /** Mixer elements class handle */
  40. typedef struct _snd_mixer_class snd_mixer_class_t;
  41. /** Mixer element handle */
  42. typedef struct _snd_mixer_elem snd_mixer_elem_t;
  43. /**
  44. * \brief Mixer callback function
  45. * \param mixer Mixer handle
  46. * \param mask event mask
  47. * \param elem related mixer element (if any)
  48. * \return 0 on success otherwise a negative error code
  49. */
  50. typedef int (*snd_mixer_callback_t)(snd_mixer_t *ctl,
  51. unsigned int mask,
  52. snd_mixer_elem_t *elem);
  53. /**
  54. * \brief Mixer element callback function
  55. * \param elem Mixer element
  56. * \param mask event mask
  57. * \return 0 on success otherwise a negative error code
  58. */
  59. typedef int (*snd_mixer_elem_callback_t)(snd_mixer_elem_t *elem,
  60. unsigned int mask);
  61. /**
  62. * \brief Compare function for sorting mixer elements
  63. * \param e1 First element
  64. * \param e2 Second element
  65. * \return -1 if e1 < e2, 0 if e1 == e2, 1 if e1 > e2
  66. */
  67. typedef int (*snd_mixer_compare_t)(const snd_mixer_elem_t *e1,
  68. const snd_mixer_elem_t *e2);
  69. /**
  70. * \brief Event callback for the mixer class
  71. * \param class_ Mixer class
  72. * \param mask Event mask (SND_CTL_EVENT_*)
  73. * \param helem HCTL element which invoked the event
  74. * \param melem Mixer element associated to HCTL element
  75. * \return zero if success, otherwise a negative error value
  76. */
  77. typedef int (*snd_mixer_event_t)(snd_mixer_class_t *class_, unsigned int mask,
  78. snd_hctl_elem_t *helem, snd_mixer_elem_t *melem);
  79. /** Mixer element type */
  80. typedef enum _snd_mixer_elem_type {
  81. /* Simple mixer elements */
  82. SND_MIXER_ELEM_SIMPLE,
  83. SND_MIXER_ELEM_LAST = SND_MIXER_ELEM_SIMPLE
  84. } snd_mixer_elem_type_t;
  85. int snd_mixer_open(snd_mixer_t **mixer, int mode);
  86. int snd_mixer_close(snd_mixer_t *mixer);
  87. snd_mixer_elem_t *snd_mixer_first_elem(snd_mixer_t *mixer);
  88. snd_mixer_elem_t *snd_mixer_last_elem(snd_mixer_t *mixer);
  89. int snd_mixer_handle_events(snd_mixer_t *mixer);
  90. int snd_mixer_attach(snd_mixer_t *mixer, const char *name);
  91. int snd_mixer_attach_hctl(snd_mixer_t *mixer, snd_hctl_t *hctl);
  92. int snd_mixer_detach(snd_mixer_t *mixer, const char *name);
  93. int snd_mixer_detach_hctl(snd_mixer_t *mixer, snd_hctl_t *hctl);
  94. int snd_mixer_get_hctl(snd_mixer_t *mixer, const char *name, snd_hctl_t **hctl);
  95. int snd_mixer_poll_descriptors_count(snd_mixer_t *mixer);
  96. int snd_mixer_poll_descriptors(snd_mixer_t *mixer, struct pollfd *pfds, unsigned int space);
  97. int snd_mixer_poll_descriptors_revents(snd_mixer_t *mixer, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
  98. int snd_mixer_load(snd_mixer_t *mixer);
  99. void snd_mixer_free(snd_mixer_t *mixer);
  100. int snd_mixer_wait(snd_mixer_t *mixer, int timeout);
  101. int snd_mixer_set_compare(snd_mixer_t *mixer, snd_mixer_compare_t msort);
  102. void snd_mixer_set_callback(snd_mixer_t *obj, snd_mixer_callback_t val);
  103. void * snd_mixer_get_callback_private(const snd_mixer_t *obj);
  104. void snd_mixer_set_callback_private(snd_mixer_t *obj, void * val);
  105. unsigned int snd_mixer_get_count(const snd_mixer_t *obj);
  106. int snd_mixer_class_unregister(snd_mixer_class_t *clss);
  107. snd_mixer_elem_t *snd_mixer_elem_next(snd_mixer_elem_t *elem);
  108. snd_mixer_elem_t *snd_mixer_elem_prev(snd_mixer_elem_t *elem);
  109. void snd_mixer_elem_set_callback(snd_mixer_elem_t *obj, snd_mixer_elem_callback_t val);
  110. void * snd_mixer_elem_get_callback_private(const snd_mixer_elem_t *obj);
  111. void snd_mixer_elem_set_callback_private(snd_mixer_elem_t *obj, void * val);
  112. snd_mixer_elem_type_t snd_mixer_elem_get_type(const snd_mixer_elem_t *obj);
  113. int snd_mixer_class_register(snd_mixer_class_t *class_, snd_mixer_t *mixer);
  114. int snd_mixer_elem_new(snd_mixer_elem_t **elem,
  115. snd_mixer_elem_type_t type,
  116. int compare_weight,
  117. void *private_data,
  118. void (*private_free)(snd_mixer_elem_t *elem));
  119. int snd_mixer_elem_add(snd_mixer_elem_t *elem, snd_mixer_class_t *class_);
  120. int snd_mixer_elem_remove(snd_mixer_elem_t *elem);
  121. void snd_mixer_elem_free(snd_mixer_elem_t *elem);
  122. int snd_mixer_elem_info(snd_mixer_elem_t *elem);
  123. int snd_mixer_elem_value(snd_mixer_elem_t *elem);
  124. int snd_mixer_elem_attach(snd_mixer_elem_t *melem, snd_hctl_elem_t *helem);
  125. int snd_mixer_elem_detach(snd_mixer_elem_t *melem, snd_hctl_elem_t *helem);
  126. int snd_mixer_elem_empty(snd_mixer_elem_t *melem);
  127. void *snd_mixer_elem_get_private(const snd_mixer_elem_t *melem);
  128. size_t snd_mixer_class_sizeof(void);
  129. /** \hideinitializer
  130. * \brief allocate an invalid #snd_mixer_class_t using standard alloca
  131. * \param ptr returned pointer
  132. */
  133. #define snd_mixer_class_alloca(ptr) __snd_alloca(ptr, snd_mixer_class)
  134. int snd_mixer_class_malloc(snd_mixer_class_t **ptr);
  135. void snd_mixer_class_free(snd_mixer_class_t *obj);
  136. void snd_mixer_class_copy(snd_mixer_class_t *dst, const snd_mixer_class_t *src);
  137. snd_mixer_t *snd_mixer_class_get_mixer(const snd_mixer_class_t *class_);
  138. snd_mixer_event_t snd_mixer_class_get_event(const snd_mixer_class_t *class_);
  139. void *snd_mixer_class_get_private(const snd_mixer_class_t *class_);
  140. snd_mixer_compare_t snd_mixer_class_get_compare(const snd_mixer_class_t *class_);
  141. int snd_mixer_class_set_event(snd_mixer_class_t *class_, snd_mixer_event_t event);
  142. int snd_mixer_class_set_private(snd_mixer_class_t *class_, void *private_data);
  143. int snd_mixer_class_set_private_free(snd_mixer_class_t *class_, void (*private_free)(snd_mixer_class_t *));
  144. int snd_mixer_class_set_compare(snd_mixer_class_t *class_, snd_mixer_compare_t compare);
  145. /**
  146. * \defgroup SimpleMixer Simple Mixer Interface
  147. * \ingroup Mixer
  148. * The simple mixer interface.
  149. * \{
  150. */
  151. /* Simple mixer elements API */
  152. /** Mixer simple element channel identifier */
  153. typedef enum _snd_mixer_selem_channel_id {
  154. /** Unknown */
  155. SND_MIXER_SCHN_UNKNOWN = -1,
  156. /** Front left */
  157. SND_MIXER_SCHN_FRONT_LEFT = 0,
  158. /** Front right */
  159. SND_MIXER_SCHN_FRONT_RIGHT,
  160. /** Rear left */
  161. SND_MIXER_SCHN_REAR_LEFT,
  162. /** Rear right */
  163. SND_MIXER_SCHN_REAR_RIGHT,
  164. /** Front center */
  165. SND_MIXER_SCHN_FRONT_CENTER,
  166. /** Woofer */
  167. SND_MIXER_SCHN_WOOFER,
  168. /** Side Left */
  169. SND_MIXER_SCHN_SIDE_LEFT,
  170. /** Side Right */
  171. SND_MIXER_SCHN_SIDE_RIGHT,
  172. /** Rear Center */
  173. SND_MIXER_SCHN_REAR_CENTER,
  174. SND_MIXER_SCHN_LAST = 31,
  175. /** Mono (Front left alias) */
  176. SND_MIXER_SCHN_MONO = SND_MIXER_SCHN_FRONT_LEFT
  177. } snd_mixer_selem_channel_id_t;
  178. /** Mixer simple element - register options - abstraction level */
  179. enum snd_mixer_selem_regopt_abstract {
  180. /** no abstraction - try use all universal controls from driver */
  181. SND_MIXER_SABSTRACT_NONE = 0,
  182. /** basic abstraction - Master,PCM,CD,Aux,Record-Gain etc. */
  183. SND_MIXER_SABSTRACT_BASIC,
  184. };
  185. /** Mixer simple element - register options */
  186. struct snd_mixer_selem_regopt {
  187. /** structure version */
  188. int ver;
  189. /** v1: abstract layer selection */
  190. enum snd_mixer_selem_regopt_abstract abstract;
  191. /** v1: device name (must be NULL when playback_pcm or capture_pcm != NULL) */
  192. const char *device;
  193. /** v1: playback PCM connected to mixer device (NULL == none) */
  194. snd_pcm_t *playback_pcm;
  195. /** v1: capture PCM connected to mixer device (NULL == none) */
  196. snd_pcm_t *capture_pcm;
  197. };
  198. /** Mixer simple element identifier */
  199. typedef struct _snd_mixer_selem_id snd_mixer_selem_id_t;
  200. const char *snd_mixer_selem_channel_name(snd_mixer_selem_channel_id_t channel);
  201. int snd_mixer_selem_register(snd_mixer_t *mixer,
  202. struct snd_mixer_selem_regopt *options,
  203. snd_mixer_class_t **classp);
  204. void snd_mixer_selem_get_id(snd_mixer_elem_t *element,
  205. snd_mixer_selem_id_t *id);
  206. const char *snd_mixer_selem_get_name(snd_mixer_elem_t *elem);
  207. unsigned int snd_mixer_selem_get_index(snd_mixer_elem_t *elem);
  208. snd_mixer_elem_t *snd_mixer_find_selem(snd_mixer_t *mixer,
  209. const snd_mixer_selem_id_t *id);
  210. int snd_mixer_selem_is_active(snd_mixer_elem_t *elem);
  211. int snd_mixer_selem_is_playback_mono(snd_mixer_elem_t *elem);
  212. int snd_mixer_selem_has_playback_channel(snd_mixer_elem_t *obj, snd_mixer_selem_channel_id_t channel);
  213. int snd_mixer_selem_is_capture_mono(snd_mixer_elem_t *elem);
  214. int snd_mixer_selem_has_capture_channel(snd_mixer_elem_t *obj, snd_mixer_selem_channel_id_t channel);
  215. int snd_mixer_selem_get_capture_group(snd_mixer_elem_t *elem);
  216. int snd_mixer_selem_has_common_volume(snd_mixer_elem_t *elem);
  217. int snd_mixer_selem_has_playback_volume(snd_mixer_elem_t *elem);
  218. int snd_mixer_selem_has_playback_volume_joined(snd_mixer_elem_t *elem);
  219. int snd_mixer_selem_has_capture_volume(snd_mixer_elem_t *elem);
  220. int snd_mixer_selem_has_capture_volume_joined(snd_mixer_elem_t *elem);
  221. int snd_mixer_selem_has_common_switch(snd_mixer_elem_t *elem);
  222. int snd_mixer_selem_has_playback_switch(snd_mixer_elem_t *elem);
  223. int snd_mixer_selem_has_playback_switch_joined(snd_mixer_elem_t *elem);
  224. int snd_mixer_selem_has_capture_switch(snd_mixer_elem_t *elem);
  225. int snd_mixer_selem_has_capture_switch_joined(snd_mixer_elem_t *elem);
  226. int snd_mixer_selem_has_capture_switch_exclusive(snd_mixer_elem_t *elem);
  227. int snd_mixer_selem_ask_playback_vol_dB(snd_mixer_elem_t *elem, long value, long *dBvalue);
  228. int snd_mixer_selem_ask_capture_vol_dB(snd_mixer_elem_t *elem, long value, long *dBvalue);
  229. int snd_mixer_selem_ask_playback_dB_vol(snd_mixer_elem_t *elem, long dBvalue, int dir, long *value);
  230. int snd_mixer_selem_ask_capture_dB_vol(snd_mixer_elem_t *elem, long dBvalue, int dir, long *value);
  231. int snd_mixer_selem_get_playback_volume(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long *value);
  232. int snd_mixer_selem_get_capture_volume(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long *value);
  233. int snd_mixer_selem_get_playback_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long *value);
  234. int snd_mixer_selem_get_capture_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long *value);
  235. int snd_mixer_selem_get_playback_switch(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, int *value);
  236. int snd_mixer_selem_get_capture_switch(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, int *value);
  237. int snd_mixer_selem_set_playback_volume(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value);
  238. int snd_mixer_selem_set_capture_volume(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value);
  239. int snd_mixer_selem_set_playback_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value, int dir);
  240. int snd_mixer_selem_set_capture_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value, int dir);
  241. int snd_mixer_selem_set_playback_volume_all(snd_mixer_elem_t *elem, long value);
  242. int snd_mixer_selem_set_capture_volume_all(snd_mixer_elem_t *elem, long value);
  243. int snd_mixer_selem_set_playback_dB_all(snd_mixer_elem_t *elem, long value, int dir);
  244. int snd_mixer_selem_set_capture_dB_all(snd_mixer_elem_t *elem, long value, int dir);
  245. int snd_mixer_selem_set_playback_switch(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, int value);
  246. int snd_mixer_selem_set_capture_switch(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, int value);
  247. int snd_mixer_selem_set_playback_switch_all(snd_mixer_elem_t *elem, int value);
  248. int snd_mixer_selem_set_capture_switch_all(snd_mixer_elem_t *elem, int value);
  249. int snd_mixer_selem_get_playback_volume_range(snd_mixer_elem_t *elem,
  250. long *min, long *max);
  251. int snd_mixer_selem_get_playback_dB_range(snd_mixer_elem_t *elem,
  252. long *min, long *max);
  253. int snd_mixer_selem_set_playback_volume_range(snd_mixer_elem_t *elem,
  254. long min, long max);
  255. int snd_mixer_selem_get_capture_volume_range(snd_mixer_elem_t *elem,
  256. long *min, long *max);
  257. int snd_mixer_selem_get_capture_dB_range(snd_mixer_elem_t *elem,
  258. long *min, long *max);
  259. int snd_mixer_selem_set_capture_volume_range(snd_mixer_elem_t *elem,
  260. long min, long max);
  261. int snd_mixer_selem_is_enumerated(snd_mixer_elem_t *elem);
  262. int snd_mixer_selem_is_enum_playback(snd_mixer_elem_t *elem);
  263. int snd_mixer_selem_is_enum_capture(snd_mixer_elem_t *elem);
  264. int snd_mixer_selem_get_enum_items(snd_mixer_elem_t *elem);
  265. int snd_mixer_selem_get_enum_item_name(snd_mixer_elem_t *elem, unsigned int idx, size_t maxlen, char *str);
  266. int snd_mixer_selem_get_enum_item(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, unsigned int *idxp);
  267. int snd_mixer_selem_set_enum_item(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, unsigned int idx);
  268. size_t snd_mixer_selem_id_sizeof(void);
  269. /** \hideinitializer
  270. * \brief allocate an invalid #snd_mixer_selem_id_t using standard alloca
  271. * \param ptr returned pointer
  272. */
  273. #define snd_mixer_selem_id_alloca(ptr) __snd_alloca(ptr, snd_mixer_selem_id)
  274. int snd_mixer_selem_id_malloc(snd_mixer_selem_id_t **ptr);
  275. void snd_mixer_selem_id_free(snd_mixer_selem_id_t *obj);
  276. void snd_mixer_selem_id_copy(snd_mixer_selem_id_t *dst, const snd_mixer_selem_id_t *src);
  277. const char *snd_mixer_selem_id_get_name(const snd_mixer_selem_id_t *obj);
  278. unsigned int snd_mixer_selem_id_get_index(const snd_mixer_selem_id_t *obj);
  279. void snd_mixer_selem_id_set_name(snd_mixer_selem_id_t *obj, const char *val);
  280. void snd_mixer_selem_id_set_index(snd_mixer_selem_id_t *obj, unsigned int val);
  281. /** \} */
  282. /** \} */
  283. #ifdef __cplusplus
  284. }
  285. #endif
  286. #endif /* __ALSA_MIXER_H */