obs-audio-controls.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. Copyright (C) 2014 by Leonhard Oelke <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #pragma once
  15. #include "obs.h"
  16. /**
  17. * @file
  18. * @brief header for audio controls
  19. *
  20. * @brief Audio controls for use in GUIs
  21. */
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /**
  26. * @brief Fader types
  27. */
  28. enum obs_fader_type {
  29. /**
  30. * @brief A simple cubic fader for controlling audio levels
  31. *
  32. * This is a very common type of software fader since it yields good
  33. * results while being quite performant.
  34. * The input value is mapped to mul values with the simple formula x^3.
  35. */
  36. OBS_FADER_CUBIC,
  37. /**
  38. * @brief A fader compliant to IEC 60-268-18
  39. *
  40. * This type of fader has several segments with different slopes that
  41. * map deflection linearly to dB values. The segments are defined as
  42. * in the following table:
  43. *
  44. @code
  45. Deflection | Volume
  46. ------------------------------------------
  47. [ 100 %, 75 % ] | [ 0 dB, -9 dB ]
  48. [ 75 %, 50 % ] | [ -9 dB, -20 dB ]
  49. [ 50 %, 30 % ] | [ -20 dB, -30 dB ]
  50. [ 30 %, 15 % ] | [ -30 dB, -40 dB ]
  51. [ 15 %, 7.5 % ] | [ -40 dB, -50 dB ]
  52. [ 7.5 %, 2.5 % ] | [ -50 dB, -60 dB ]
  53. [ 2.5 %, 0 % ] | [ -60 dB, -inf dB ]
  54. @endcode
  55. */
  56. OBS_FADER_IEC,
  57. /**
  58. * @brief Logarithmic fader
  59. */
  60. OBS_FADER_LOG
  61. };
  62. /**
  63. * @brief Create a fader
  64. * @param type the type of the fader
  65. * @return pointer to the fader object
  66. *
  67. * A fader object is used to map input values from a gui element to dB and
  68. * subsequently multiplier values used by libobs to mix audio.
  69. * The current "position" of the fader is internally stored as dB value.
  70. */
  71. EXPORT obs_fader_t *obs_fader_create(enum obs_fader_type type);
  72. /**
  73. * @brief Destroy a fader
  74. * @param fader pointer to the fader object
  75. *
  76. * Destroy the fader and free all related data
  77. */
  78. EXPORT void obs_fader_destroy(obs_fader_t *fader);
  79. /**
  80. * @brief Set the fader dB value
  81. * @param fader pointer to the fader object
  82. * @param db new dB value
  83. * @return true if value was set without clamping
  84. */
  85. EXPORT bool obs_fader_set_db(obs_fader_t *fader, const float db);
  86. /**
  87. * @brief Get the current fader dB value
  88. * @param fader pointer to the fader object
  89. * @return current fader dB value
  90. */
  91. EXPORT float obs_fader_get_db(obs_fader_t *fader);
  92. /**
  93. * @brief Set the fader value from deflection
  94. * @param fader pointer to the fader object
  95. * @param def new deflection
  96. * @return true if value was set without clamping
  97. *
  98. * This sets the new fader value from the supplied deflection, in case the
  99. * resulting value was clamped due to limits this function will return false.
  100. * The deflection is typically in the range [0.0, 1.0] but may be higher in
  101. * order to provide some amplification. In order for this to work the high dB
  102. * limit has to be set.
  103. */
  104. EXPORT bool obs_fader_set_deflection(obs_fader_t *fader, const float def);
  105. /**
  106. * @brief Get the current fader deflection
  107. * @param fader pointer to the fader object
  108. * @return current fader deflection
  109. */
  110. EXPORT float obs_fader_get_deflection(obs_fader_t *fader);
  111. /**
  112. * @brief Set the fader value from multiplier
  113. * @param fader pointer to the fader object
  114. * @return true if the value was set without clamping
  115. */
  116. EXPORT bool obs_fader_set_mul(obs_fader_t *fader, const float mul);
  117. /**
  118. * @brief Get the current fader multiplier value
  119. * @param fader pointer to the fader object
  120. * @return current fader multiplier
  121. */
  122. EXPORT float obs_fader_get_mul(obs_fader_t *fader);
  123. /**
  124. * @brief Attach the fader to a source
  125. * @param fader pointer to the fader object
  126. * @param source pointer to the source object
  127. * @return true on success
  128. *
  129. * When the fader is attached to a source it will automatically sync it's state
  130. * to the volume of the source.
  131. */
  132. EXPORT bool obs_fader_attach_source(obs_fader_t *fader, obs_source_t *source);
  133. /**
  134. * @brief Detach the fader from the currently attached source
  135. * @param fader pointer to the fader object
  136. */
  137. EXPORT void obs_fader_detach_source(obs_fader_t *fader);
  138. typedef void (*obs_fader_changed_t)(void *param, float db);
  139. EXPORT void obs_fader_add_callback(obs_fader_t *fader,
  140. obs_fader_changed_t callback, void *param);
  141. EXPORT void obs_fader_remove_callback(obs_fader_t *fader,
  142. obs_fader_changed_t callback, void *param);
  143. /**
  144. * @brief Create a volume meter
  145. * @param type the mapping type to use for the volume meter
  146. * @return pointer to the volume meter object
  147. *
  148. * A volume meter object is used to prepare the sound levels reported by audio
  149. * sources for display in a GUI.
  150. * It will automatically take source volume into account and map the levels
  151. * to a range [0.0f, 1.0f].
  152. */
  153. EXPORT obs_volmeter_t *obs_volmeter_create(enum obs_fader_type type);
  154. /**
  155. * @brief Destroy a volume meter
  156. * @param volmeter pointer to the volmeter object
  157. *
  158. * Destroy the volume meter and free all related data
  159. */
  160. EXPORT void obs_volmeter_destroy(obs_volmeter_t *volmeter);
  161. /**
  162. * @brief Attach the volume meter to a source
  163. * @param volmeter pointer to the volume meter object
  164. * @param source pointer to the source object
  165. * @return true on success
  166. *
  167. * When the volume meter is attached to a source it will start to listen to
  168. * volume updates on the source and after preparing the data emit its own
  169. * signal.
  170. */
  171. EXPORT bool obs_volmeter_attach_source(obs_volmeter_t *volmeter,
  172. obs_source_t *source);
  173. /**
  174. * @brief Detach the volume meter from the currently attached source
  175. * @param volmeter pointer to the volume meter object
  176. */
  177. EXPORT void obs_volmeter_detach_source(obs_volmeter_t *volmeter);
  178. /**
  179. * @brief Set the update interval for the volume meter
  180. * @param volmeter pointer to the volume meter object
  181. * @param ms update interval in ms
  182. *
  183. * This sets the update interval in milliseconds that should be processed before
  184. * the resulting values are emitted by the levels_updated signal. The resulting
  185. * number of audio samples is rounded to an integer.
  186. *
  187. * Please note that due to way obs does receive audio data from the sources
  188. * this is no hard guarantee for the timing of the signal itself. When the
  189. * volume meter receives a chunk of data that is multiple the size of the sample
  190. * interval, all data will be sampled and the values updated accordingly, but
  191. * only the signal for the last segment is actually emitted.
  192. * On the other hand data might be received in a way that will cause the signal
  193. * to be emitted in shorter intervals than specified here under some
  194. * circumstances.
  195. */
  196. EXPORT void obs_volmeter_set_update_interval(obs_volmeter_t *volmeter,
  197. const unsigned int ms);
  198. /**
  199. * @brief Get the update interval currently used for the volume meter
  200. * @param volmeter pointer to the volume meter object
  201. * @return update interval in ms
  202. */
  203. EXPORT unsigned int obs_volmeter_get_update_interval(obs_volmeter_t *volmeter);
  204. /**
  205. * @brief Set the peak hold time for the volume meter
  206. * @param volmeter pointer to the volume meter object
  207. * @param ms peak hold time in ms
  208. */
  209. EXPORT void obs_volmeter_set_peak_hold(obs_volmeter_t *volmeter,
  210. const unsigned int ms);
  211. /**
  212. * @brief Get the peak hold time for the volume meter
  213. * @param volmeter pointer to the volume meter object
  214. * @return the peak hold time in ms
  215. */
  216. EXPORT unsigned int obs_volmeter_get_peak_hold(obs_volmeter_t *volmeter);
  217. typedef void (*obs_volmeter_updated_t)(void *param, float level,
  218. float magnitude, float peak, float muted);
  219. EXPORT void obs_volmeter_add_callback(obs_volmeter_t *volmeter,
  220. obs_volmeter_updated_t callback, void *param);
  221. EXPORT void obs_volmeter_remove_callback(obs_volmeter_t *volmeter,
  222. obs_volmeter_updated_t callback, void *param);
  223. EXPORT float obs_volmeter_get_cur_db(enum obs_fader_type type, const float def);
  224. #ifdef __cplusplus
  225. }
  226. #endif