audio_int.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * QEMU Audio subsystem header
  3. *
  4. * Copyright (c) 2003-2005 Vassili Karpov (malc)
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #ifndef QEMU_AUDIO_INT_H
  25. #define QEMU_AUDIO_INT_H
  26. #ifdef CONFIG_COREAUDIO
  27. #define FLOAT_MIXENG
  28. /* #define RECIPROCAL */
  29. #endif
  30. #include "mixeng.h"
  31. struct audio_pcm_ops;
  32. typedef enum {
  33. AUD_OPT_INT,
  34. AUD_OPT_FMT,
  35. AUD_OPT_STR,
  36. AUD_OPT_BOOL
  37. } audio_option_tag_e;
  38. struct audio_option {
  39. const char *name;
  40. audio_option_tag_e tag;
  41. void *valp;
  42. const char *descr;
  43. int *overriddenp;
  44. int overridden;
  45. };
  46. struct audio_callback {
  47. void *opaque;
  48. audio_callback_fn fn;
  49. };
  50. struct audio_pcm_info {
  51. int bits;
  52. int sign;
  53. int freq;
  54. int nchannels;
  55. int align;
  56. int shift;
  57. int bytes_per_second;
  58. int swap_endianness;
  59. };
  60. typedef struct SWVoiceCap SWVoiceCap;
  61. typedef struct HWVoiceOut {
  62. int enabled;
  63. int poll_mode;
  64. int pending_disable;
  65. struct audio_pcm_info info;
  66. f_sample *clip;
  67. int rpos;
  68. uint64_t ts_helper;
  69. struct st_sample *mix_buf;
  70. int samples;
  71. QLIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
  72. QLIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;
  73. int ctl_caps;
  74. struct audio_pcm_ops *pcm_ops;
  75. QLIST_ENTRY (HWVoiceOut) entries;
  76. } HWVoiceOut;
  77. typedef struct HWVoiceIn {
  78. int enabled;
  79. int poll_mode;
  80. struct audio_pcm_info info;
  81. t_sample *conv;
  82. int wpos;
  83. int total_samples_captured;
  84. uint64_t ts_helper;
  85. struct st_sample *conv_buf;
  86. int samples;
  87. QLIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
  88. int ctl_caps;
  89. struct audio_pcm_ops *pcm_ops;
  90. QLIST_ENTRY (HWVoiceIn) entries;
  91. } HWVoiceIn;
  92. struct SWVoiceOut {
  93. QEMUSoundCard *card;
  94. struct audio_pcm_info info;
  95. t_sample *conv;
  96. int64_t ratio;
  97. struct st_sample *buf;
  98. void *rate;
  99. int total_hw_samples_mixed;
  100. int active;
  101. int empty;
  102. HWVoiceOut *hw;
  103. char *name;
  104. struct mixeng_volume vol;
  105. struct audio_callback callback;
  106. QLIST_ENTRY (SWVoiceOut) entries;
  107. };
  108. struct SWVoiceIn {
  109. QEMUSoundCard *card;
  110. int active;
  111. struct audio_pcm_info info;
  112. int64_t ratio;
  113. void *rate;
  114. int total_hw_samples_acquired;
  115. struct st_sample *buf;
  116. f_sample *clip;
  117. HWVoiceIn *hw;
  118. char *name;
  119. struct mixeng_volume vol;
  120. struct audio_callback callback;
  121. QLIST_ENTRY (SWVoiceIn) entries;
  122. };
  123. struct audio_driver {
  124. const char *name;
  125. const char *descr;
  126. struct audio_option *options;
  127. void *(*init) (void);
  128. void (*fini) (void *);
  129. struct audio_pcm_ops *pcm_ops;
  130. int can_be_default;
  131. int max_voices_out;
  132. int max_voices_in;
  133. int voice_size_out;
  134. int voice_size_in;
  135. int ctl_caps;
  136. };
  137. struct audio_pcm_ops {
  138. int (*init_out)(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque);
  139. void (*fini_out)(HWVoiceOut *hw);
  140. int (*run_out) (HWVoiceOut *hw, int live);
  141. int (*write) (SWVoiceOut *sw, void *buf, int size);
  142. int (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
  143. int (*init_in) (HWVoiceIn *hw, struct audsettings *as, void *drv_opaque);
  144. void (*fini_in) (HWVoiceIn *hw);
  145. int (*run_in) (HWVoiceIn *hw);
  146. int (*read) (SWVoiceIn *sw, void *buf, int size);
  147. int (*ctl_in) (HWVoiceIn *hw, int cmd, ...);
  148. };
  149. struct capture_callback {
  150. struct audio_capture_ops ops;
  151. void *opaque;
  152. QLIST_ENTRY (capture_callback) entries;
  153. };
  154. struct CaptureVoiceOut {
  155. HWVoiceOut hw;
  156. void *buf;
  157. QLIST_HEAD (cb_listhead, capture_callback) cb_head;
  158. QLIST_ENTRY (CaptureVoiceOut) entries;
  159. };
  160. struct SWVoiceCap {
  161. SWVoiceOut sw;
  162. CaptureVoiceOut *cap;
  163. QLIST_ENTRY (SWVoiceCap) entries;
  164. };
  165. struct AudioState {
  166. struct audio_driver *drv;
  167. void *drv_opaque;
  168. QEMUTimer *ts;
  169. QLIST_HEAD (card_listhead, QEMUSoundCard) card_head;
  170. QLIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
  171. QLIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
  172. QLIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head;
  173. int nb_hw_voices_out;
  174. int nb_hw_voices_in;
  175. int vm_running;
  176. };
  177. extern struct audio_driver no_audio_driver;
  178. extern struct audio_driver oss_audio_driver;
  179. extern struct audio_driver sdl_audio_driver;
  180. extern struct audio_driver wav_audio_driver;
  181. extern struct audio_driver alsa_audio_driver;
  182. extern struct audio_driver coreaudio_audio_driver;
  183. extern struct audio_driver dsound_audio_driver;
  184. extern struct audio_driver pa_audio_driver;
  185. extern struct audio_driver spice_audio_driver;
  186. extern const struct mixeng_volume nominal_volume;
  187. void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as);
  188. void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
  189. int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
  190. int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
  191. int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
  192. int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf,
  193. int live, int pending);
  194. int audio_bug (const char *funcname, int cond);
  195. void *audio_calloc (const char *funcname, int nmemb, size_t size);
  196. void audio_run (const char *msg);
  197. #define VOICE_ENABLE 1
  198. #define VOICE_DISABLE 2
  199. #define VOICE_VOLUME 3
  200. #define VOICE_VOLUME_CAP (1 << VOICE_VOLUME)
  201. static inline int audio_ring_dist (int dst, int src, int len)
  202. {
  203. return (dst >= src) ? (dst - src) : (len - src + dst);
  204. }
  205. #define dolog(fmt, ...) AUD_log(AUDIO_CAP, fmt, ## __VA_ARGS__)
  206. #ifdef DEBUG
  207. #define ldebug(fmt, ...) AUD_log(AUDIO_CAP, fmt, ## __VA_ARGS__)
  208. #else
  209. #define ldebug(fmt, ...) (void)0
  210. #endif
  211. #define AUDIO_STRINGIFY_(n) #n
  212. #define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
  213. #if defined _MSC_VER || defined __GNUC__
  214. #define AUDIO_FUNC __FUNCTION__
  215. #else
  216. #define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__)
  217. #endif
  218. #endif /* QEMU_AUDIO_INT_H */