obs-audio-controls.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. Copyright (C) 2014 by Leonhard Oelke <leonhard@in-verted.de>
  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 Peak meter types
  64. */
  65. enum obs_peak_meter_type {
  66. /**
  67. * @brief A simple peak meter measuring the maximum of all samples.
  68. *
  69. * This was a very common type of peak meter used for audio, but
  70. * is not very accurate with regards to further audio processing.
  71. */
  72. SAMPLE_PEAK_METER,
  73. /**
  74. * @brief An accurate peak meter measure the maximum of inter-samples.
  75. *
  76. * This meter is more computational intensive due to 4x oversampling
  77. * to determine the true peak to an accuracy of +/- 0.5 dB.
  78. */
  79. TRUE_PEAK_METER
  80. };
  81. /**
  82. * @brief Create a fader
  83. * @param type the type of the fader
  84. * @return pointer to the fader object
  85. *
  86. * A fader object is used to map input values from a gui element to dB and
  87. * subsequently multiplier values used by libobs to mix audio.
  88. * The current "position" of the fader is internally stored as dB value.
  89. */
  90. EXPORT obs_fader_t *obs_fader_create(enum obs_fader_type type);
  91. /**
  92. * @brief Destroy a fader
  93. * @param fader pointer to the fader object
  94. *
  95. * Destroy the fader and free all related data
  96. */
  97. EXPORT void obs_fader_destroy(obs_fader_t *fader);
  98. /**
  99. * @brief Set the fader dB value
  100. * @param fader pointer to the fader object
  101. * @param db new dB value
  102. * @return true if value was set without clamping
  103. */
  104. EXPORT bool obs_fader_set_db(obs_fader_t *fader, const float db);
  105. /**
  106. * @brief Get the current fader dB value
  107. * @param fader pointer to the fader object
  108. * @return current fader dB value
  109. */
  110. EXPORT float obs_fader_get_db(obs_fader_t *fader);
  111. /**
  112. * @brief Set the fader value from deflection
  113. * @param fader pointer to the fader object
  114. * @param def new deflection
  115. * @return true if value was set without clamping
  116. *
  117. * This sets the new fader value from the supplied deflection, in case the
  118. * resulting value was clamped due to limits this function will return false.
  119. * The deflection is typically in the range [0.0, 1.0] but may be higher in
  120. * order to provide some amplification. In order for this to work the high dB
  121. * limit has to be set.
  122. */
  123. EXPORT bool obs_fader_set_deflection(obs_fader_t *fader, const float def);
  124. /**
  125. * @brief Get the current fader deflection
  126. * @param fader pointer to the fader object
  127. * @return current fader deflection
  128. */
  129. EXPORT float obs_fader_get_deflection(obs_fader_t *fader);
  130. /**
  131. * @brief Set the fader value from multiplier
  132. * @param fader pointer to the fader object
  133. * @return true if the value was set without clamping
  134. */
  135. EXPORT bool obs_fader_set_mul(obs_fader_t *fader, const float mul);
  136. /**
  137. * @brief Get the current fader multiplier value
  138. * @param fader pointer to the fader object
  139. * @return current fader multiplier
  140. */
  141. EXPORT float obs_fader_get_mul(obs_fader_t *fader);
  142. /**
  143. * @brief Attach the fader to a source
  144. * @param fader pointer to the fader object
  145. * @param source pointer to the source object
  146. * @return true on success
  147. *
  148. * When the fader is attached to a source it will automatically sync it's state
  149. * to the volume of the source.
  150. */
  151. EXPORT bool obs_fader_attach_source(obs_fader_t *fader, obs_source_t *source);
  152. /**
  153. * @brief Detach the fader from the currently attached source
  154. * @param fader pointer to the fader object
  155. */
  156. EXPORT void obs_fader_detach_source(obs_fader_t *fader);
  157. typedef void (*obs_fader_changed_t)(void *param, float db);
  158. EXPORT void obs_fader_add_callback(obs_fader_t *fader, obs_fader_changed_t callback, void *param);
  159. EXPORT void obs_fader_remove_callback(obs_fader_t *fader, obs_fader_changed_t callback, void *param);
  160. /**
  161. * @brief Create a volume meter
  162. * @param type the mapping type to use for the volume meter
  163. * @return pointer to the volume meter object
  164. *
  165. * A volume meter object is used to prepare the sound levels reported by audio
  166. * sources for display in a GUI.
  167. * It will automatically take source volume into account and map the levels
  168. * to a range [0.0f, 1.0f].
  169. */
  170. EXPORT obs_volmeter_t *obs_volmeter_create(enum obs_fader_type type);
  171. /**
  172. * @brief Destroy a volume meter
  173. * @param volmeter pointer to the volmeter object
  174. *
  175. * Destroy the volume meter and free all related data
  176. */
  177. EXPORT void obs_volmeter_destroy(obs_volmeter_t *volmeter);
  178. /**
  179. * @brief Attach the volume meter to a source
  180. * @param volmeter pointer to the volume meter object
  181. * @param source pointer to the source object
  182. * @return true on success
  183. *
  184. * When the volume meter is attached to a source it will start to listen to
  185. * volume updates on the source and after preparing the data emit its own
  186. * signal.
  187. */
  188. EXPORT bool obs_volmeter_attach_source(obs_volmeter_t *volmeter, obs_source_t *source);
  189. /**
  190. * @brief Detach the volume meter from the currently attached source
  191. * @param volmeter pointer to the volume meter object
  192. */
  193. EXPORT void obs_volmeter_detach_source(obs_volmeter_t *volmeter);
  194. /**
  195. * @brief Set the peak meter type for the volume meter
  196. * @param volmeter pointer to the volume meter object
  197. * @param peak_meter_type set if true-peak needs to be measured.
  198. */
  199. EXPORT void obs_volmeter_set_peak_meter_type(obs_volmeter_t *volmeter, enum obs_peak_meter_type peak_meter_type);
  200. /**
  201. * @brief Get the number of channels which are configured for this source.
  202. * @param volmeter pointer to the volume meter object
  203. */
  204. EXPORT int obs_volmeter_get_nr_channels(obs_volmeter_t *volmeter);
  205. typedef void (*obs_volmeter_updated_t)(void *param, const float magnitude[MAX_AUDIO_CHANNELS],
  206. const float peak[MAX_AUDIO_CHANNELS],
  207. const float input_peak[MAX_AUDIO_CHANNELS]);
  208. EXPORT void obs_volmeter_add_callback(obs_volmeter_t *volmeter, obs_volmeter_updated_t callback, void *param);
  209. EXPORT void obs_volmeter_remove_callback(obs_volmeter_t *volmeter, obs_volmeter_updated_t callback, void *param);
  210. EXPORT float obs_mul_to_db(float mul);
  211. EXPORT float obs_db_to_mul(float db);
  212. typedef float (*obs_fader_conversion_t)(const float val);
  213. EXPORT obs_fader_conversion_t obs_fader_db_to_def(obs_fader_t *fader);
  214. #ifdef __cplusplus
  215. }
  216. #endif