bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU Audio subsystem header |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 2003-2005 Vassili Karpov (malc) |
| 5 | * |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 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 | |
bellard | 5fa0ab8 | 2007-11-07 19:27:18 +0000 | [diff] [blame] | 27 | #include "config-host.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 28 | #include "qemu/queue.h" |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 29 | |
malc | cb4f03e | 2009-10-15 02:40:17 +0400 | [diff] [blame] | 30 | typedef void (*audio_callback_fn) (void *opaque, int avail); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 31 | |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 32 | typedef enum { |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 33 | AUD_FMT_U8, |
| 34 | AUD_FMT_S8, |
| 35 | AUD_FMT_U16, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 36 | AUD_FMT_S16, |
| 37 | AUD_FMT_U32, |
| 38 | AUD_FMT_S32 |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 39 | } audfmt_e; |
| 40 | |
Juan Quintela | e2542fe | 2009-07-27 16:13:06 +0200 | [diff] [blame] | 41 | #ifdef HOST_WORDS_BIGENDIAN |
bellard | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame] | 42 | #define AUDIO_HOST_ENDIANNESS 1 |
| 43 | #else |
| 44 | #define AUDIO_HOST_ENDIANNESS 0 |
| 45 | #endif |
| 46 | |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 47 | struct audsettings { |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 48 | int freq; |
| 49 | int nchannels; |
| 50 | audfmt_e fmt; |
bellard | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame] | 51 | int endianness; |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 52 | }; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 53 | |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 54 | typedef enum { |
| 55 | AUD_CNOTIFY_ENABLE, |
| 56 | AUD_CNOTIFY_DISABLE |
| 57 | } audcnotification_e; |
| 58 | |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 59 | struct audio_capture_ops { |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 60 | void (*notify) (void *opaque, audcnotification_e cmd); |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 61 | void (*capture) (void *opaque, void *buf, int size); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 62 | void (*destroy) (void *opaque); |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 65 | struct capture_ops { |
| 66 | void (*info) (void *opaque); |
| 67 | void (*destroy) (void *opaque); |
| 68 | }; |
| 69 | |
| 70 | typedef struct CaptureState { |
| 71 | void *opaque; |
| 72 | struct capture_ops ops; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 73 | QLIST_ENTRY (CaptureState) entries; |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 74 | } CaptureState; |
| 75 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 76 | typedef struct SWVoiceOut SWVoiceOut; |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 77 | typedef struct CaptureVoiceOut CaptureVoiceOut; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 78 | typedef struct SWVoiceIn SWVoiceIn; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 79 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 80 | typedef struct QEMUSoundCard { |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 81 | char *name; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 82 | QLIST_ENTRY (QEMUSoundCard) entries; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 83 | } QEMUSoundCard; |
| 84 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 85 | typedef struct QEMUAudioTimeStamp { |
| 86 | uint64_t old_ts; |
| 87 | } QEMUAudioTimeStamp; |
| 88 | |
Stefan Weil | 8b7968f | 2010-09-23 21:28:05 +0200 | [diff] [blame] | 89 | void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0); |
Stefan Weil | e5924d8 | 2010-09-23 21:28:03 +0200 | [diff] [blame] | 90 | void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 91 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 92 | void AUD_help (void); |
malc | 1a7dafc | 2009-05-14 03:11:35 +0400 | [diff] [blame] | 93 | void AUD_register_card (const char *name, QEMUSoundCard *card); |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 94 | void AUD_remove_card (QEMUSoundCard *card); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 95 | CaptureVoiceOut *AUD_add_capture ( |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 96 | struct audsettings *as, |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 97 | struct audio_capture_ops *ops, |
| 98 | void *opaque |
| 99 | ); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 100 | void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 101 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 102 | SWVoiceOut *AUD_open_out ( |
| 103 | QEMUSoundCard *card, |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 104 | SWVoiceOut *sw, |
| 105 | const char *name, |
| 106 | void *callback_opaque, |
malc | cb4f03e | 2009-10-15 02:40:17 +0400 | [diff] [blame] | 107 | audio_callback_fn callback_fn, |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 108 | struct audsettings *settings |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 109 | ); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 110 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 111 | void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw); |
| 112 | int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size); |
| 113 | int AUD_get_buffer_size_out (SWVoiceOut *sw); |
| 114 | void AUD_set_active_out (SWVoiceOut *sw, int on); |
| 115 | int AUD_is_active_out (SWVoiceOut *sw); |
| 116 | |
| 117 | void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); |
| 118 | uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); |
| 119 | |
balrog | 683efdc | 2008-05-04 10:21:03 +0000 | [diff] [blame] | 120 | void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol); |
| 121 | void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol); |
| 122 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 123 | SWVoiceIn *AUD_open_in ( |
| 124 | QEMUSoundCard *card, |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 125 | SWVoiceIn *sw, |
| 126 | const char *name, |
| 127 | void *callback_opaque, |
malc | cb4f03e | 2009-10-15 02:40:17 +0400 | [diff] [blame] | 128 | audio_callback_fn callback_fn, |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 129 | struct audsettings *settings |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 130 | ); |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 131 | |
| 132 | void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw); |
| 133 | int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size); |
| 134 | void AUD_set_active_in (SWVoiceIn *sw, int on); |
| 135 | int AUD_is_active_in (SWVoiceIn *sw); |
| 136 | |
| 137 | void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); |
| 138 | uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 139 | |
| 140 | static inline void *advance (void *p, int incr) |
| 141 | { |
| 142 | uint8_t *d = p; |
| 143 | return (d + incr); |
| 144 | } |
| 145 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 146 | #ifdef __GNUC__ |
| 147 | #define audio_MIN(a, b) ( __extension__ ({ \ |
| 148 | __typeof (a) ta = a; \ |
| 149 | __typeof (b) tb = b; \ |
| 150 | ((ta)>(tb)?(tb):(ta)); \ |
| 151 | })) |
| 152 | |
| 153 | #define audio_MAX(a, b) ( __extension__ ({ \ |
| 154 | __typeof (a) ta = a; \ |
| 155 | __typeof (b) tb = b; \ |
| 156 | ((ta)<(tb)?(tb):(ta)); \ |
| 157 | })) |
| 158 | #else |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 159 | #define audio_MIN(a, b) ((a)>(b)?(b):(a)) |
| 160 | #define audio_MAX(a, b) ((a)<(b)?(b):(a)) |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 161 | #endif |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 162 | |
blueswir1 | 295e390 | 2008-10-05 10:30:43 +0000 | [diff] [blame] | 163 | int wav_start_capture (CaptureState *s, const char *path, int freq, |
| 164 | int bits, int nchannels); |
| 165 | |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 166 | #endif /* audio.h */ |