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_H 25 #define QEMU_AUDIO_H 26 27 #include "config.h" 28 #include "qemu-common.h" 29 #include "sys-queue.h" 30 31 typedef void (*audio_callback_fn_t) (void *opaque, int avail); 32 33 typedef enum { 34 AUD_FMT_U8, 35 AUD_FMT_S8, 36 AUD_FMT_U16, 37 AUD_FMT_S16, 38 AUD_FMT_U32, 39 AUD_FMT_S32 40 } audfmt_e; 41 42 #ifdef WORDS_BIGENDIAN 43 #define AUDIO_HOST_ENDIANNESS 1 44 #else 45 #define AUDIO_HOST_ENDIANNESS 0 46 #endif 47 48 struct audsettings { 49 int freq; 50 int nchannels; 51 audfmt_e fmt; 52 int endianness; 53 }; 54 55 typedef enum { 56 AUD_CNOTIFY_ENABLE, 57 AUD_CNOTIFY_DISABLE 58 } audcnotification_e; 59 60 struct audio_capture_ops { 61 void (*notify) (void *opaque, audcnotification_e cmd); 62 void (*capture) (void *opaque, void *buf, int size); 63 void (*destroy) (void *opaque); 64 }; 65 66 struct capture_ops { 67 void (*info) (void *opaque); 68 void (*destroy) (void *opaque); 69 }; 70 71 typedef struct CaptureState { 72 void *opaque; 73 struct capture_ops ops; 74 LIST_ENTRY (CaptureState) entries; 75 } CaptureState; 76 77 typedef struct SWVoiceOut SWVoiceOut; 78 typedef struct CaptureVoiceOut CaptureVoiceOut; 79 typedef struct SWVoiceIn SWVoiceIn; 80 81 typedef struct QEMUSoundCard { 82 char *name; 83 LIST_ENTRY (QEMUSoundCard) entries; 84 } QEMUSoundCard; 85 86 typedef struct QEMUAudioTimeStamp { 87 uint64_t old_ts; 88 } QEMUAudioTimeStamp; 89 90 void AUD_vlog (const char *cap, const char *fmt, va_list ap); 91 void AUD_log (const char *cap, const char *fmt, ...) 92 #ifdef __GNUC__ 93 __attribute__ ((__format__ (__printf__, 2, 3))) 94 #endif 95 ; 96 97 void AUD_help (void); 98 void AUD_register_card (const char *name, QEMUSoundCard *card); 99 void AUD_remove_card (QEMUSoundCard *card); 100 CaptureVoiceOut *AUD_add_capture ( 101 struct audsettings *as, 102 struct audio_capture_ops *ops, 103 void *opaque 104 ); 105 void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque); 106 107 SWVoiceOut *AUD_open_out ( 108 QEMUSoundCard *card, 109 SWVoiceOut *sw, 110 const char *name, 111 void *callback_opaque, 112 audio_callback_fn_t callback_fn, 113 struct audsettings *settings 114 ); 115 116 void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw); 117 int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size); 118 int AUD_get_buffer_size_out (SWVoiceOut *sw); 119 void AUD_set_active_out (SWVoiceOut *sw, int on); 120 int AUD_is_active_out (SWVoiceOut *sw); 121 122 void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); 123 uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); 124 125 void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol); 126 void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol); 127 128 SWVoiceIn *AUD_open_in ( 129 QEMUSoundCard *card, 130 SWVoiceIn *sw, 131 const char *name, 132 void *callback_opaque, 133 audio_callback_fn_t callback_fn, 134 struct audsettings *settings 135 ); 136 137 void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw); 138 int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size); 139 void AUD_set_active_in (SWVoiceIn *sw, int on); 140 int AUD_is_active_in (SWVoiceIn *sw); 141 142 void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); 143 uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); 144 145 static inline void *advance (void *p, int incr) 146 { 147 uint8_t *d = p; 148 return (d + incr); 149 } 150 151 uint32_t popcount (uint32_t u); 152 uint32_t lsbindex (uint32_t u); 153 154 #ifdef __GNUC__ 155 #define audio_MIN(a, b) ( __extension__ ({ \ 156 __typeof (a) ta = a; \ 157 __typeof (b) tb = b; \ 158 ((ta)>(tb)?(tb):(ta)); \ 159 })) 160 161 #define audio_MAX(a, b) ( __extension__ ({ \ 162 __typeof (a) ta = a; \ 163 __typeof (b) tb = b; \ 164 ((ta)<(tb)?(tb):(ta)); \ 165 })) 166 #else 167 #define audio_MIN(a, b) ((a)>(b)?(b):(a)) 168 #define audio_MAX(a, b) ((a)<(b)?(b):(a)) 169 #endif 170 171 int wav_start_capture (CaptureState *s, const char *path, int freq, 172 int bits, int nchannels); 173 174 extern int 175 audio_get_backend_count( int is_input ); 176 177 extern const char* 178 audio_get_backend_name( int is_input, int index, const char* *pinfo ); 179 180 extern int 181 audio_check_backend_name( int is_input, const char* name ); 182 183 #endif /* audio.h */ 184