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 | */ |
Markus Armbruster | 175de52 | 2016-06-29 15:29:06 +0200 | [diff] [blame] | 24 | |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 25 | #ifndef QEMU_AUDIO_H |
| 26 | #define QEMU_AUDIO_H |
| 27 | |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 28 | #include "qemu/queue.h" |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 29 | #include "qapi/qapi-types-audio.h" |
Kővágó, Zoltán | 88e47b9 | 2019-08-19 01:06:49 +0200 | [diff] [blame] | 30 | #include "hw/qdev-properties.h" |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 31 | |
malc | cb4f03e | 2009-10-15 02:40:17 +0400 | [diff] [blame] | 32 | typedef void (*audio_callback_fn) (void *opaque, int avail); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 33 | |
Juan Quintela | e2542fe | 2009-07-27 16:13:06 +0200 | [diff] [blame] | 34 | #ifdef HOST_WORDS_BIGENDIAN |
bellard | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame] | 35 | #define AUDIO_HOST_ENDIANNESS 1 |
| 36 | #else |
| 37 | #define AUDIO_HOST_ENDIANNESS 0 |
| 38 | #endif |
| 39 | |
Kővágó, Zoltán | 7183022 | 2019-03-08 23:34:15 +0100 | [diff] [blame] | 40 | typedef struct audsettings { |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 41 | int freq; |
| 42 | int nchannels; |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 43 | AudioFormat fmt; |
bellard | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame] | 44 | int endianness; |
Kővágó, Zoltán | 7183022 | 2019-03-08 23:34:15 +0100 | [diff] [blame] | 45 | } audsettings; |
| 46 | |
| 47 | audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo); |
| 48 | int audioformat_bytes_per_sample(AudioFormat fmt); |
| 49 | int audio_buffer_frames(AudiodevPerDirectionOptions *pdo, |
| 50 | audsettings *as, int def_usecs); |
| 51 | int audio_buffer_samples(AudiodevPerDirectionOptions *pdo, |
| 52 | audsettings *as, int def_usecs); |
| 53 | int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo, |
| 54 | audsettings *as, int def_usecs); |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 55 | |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 56 | typedef enum { |
| 57 | AUD_CNOTIFY_ENABLE, |
| 58 | AUD_CNOTIFY_DISABLE |
| 59 | } audcnotification_e; |
| 60 | |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 61 | struct audio_capture_ops { |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 62 | void (*notify) (void *opaque, audcnotification_e cmd); |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 63 | void (*capture) (void *opaque, void *buf, int size); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 64 | void (*destroy) (void *opaque); |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 67 | struct capture_ops { |
| 68 | void (*info) (void *opaque); |
| 69 | void (*destroy) (void *opaque); |
| 70 | }; |
| 71 | |
| 72 | typedef struct CaptureState { |
| 73 | void *opaque; |
| 74 | struct capture_ops ops; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 75 | QLIST_ENTRY (CaptureState) entries; |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 76 | } CaptureState; |
| 77 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 78 | typedef struct SWVoiceOut SWVoiceOut; |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 79 | typedef struct CaptureVoiceOut CaptureVoiceOut; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 80 | typedef struct SWVoiceIn SWVoiceIn; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 81 | |
Kővágó, Zoltán | ecd97e9 | 2019-08-19 01:06:47 +0200 | [diff] [blame] | 82 | typedef struct AudioState AudioState; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 83 | typedef struct QEMUSoundCard { |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 84 | char *name; |
Kővágó, Zoltán | ecd97e9 | 2019-08-19 01:06:47 +0200 | [diff] [blame] | 85 | AudioState *state; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 86 | QLIST_ENTRY (QEMUSoundCard) entries; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 87 | } QEMUSoundCard; |
| 88 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 89 | typedef struct QEMUAudioTimeStamp { |
| 90 | uint64_t old_ts; |
| 91 | } QEMUAudioTimeStamp; |
| 92 | |
Stefan Weil | 8b7968f | 2010-09-23 21:28:05 +0200 | [diff] [blame] | 93 | 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] | 94 | 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] | 95 | |
malc | 1a7dafc | 2009-05-14 03:11:35 +0400 | [diff] [blame] | 96 | void AUD_register_card (const char *name, QEMUSoundCard *card); |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 97 | void AUD_remove_card (QEMUSoundCard *card); |
Kővágó, Zoltán | ecd97e9 | 2019-08-19 01:06:47 +0200 | [diff] [blame] | 98 | CaptureVoiceOut *AUD_add_capture( |
| 99 | AudioState *s, |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 100 | struct audsettings *as, |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 101 | struct audio_capture_ops *ops, |
| 102 | void *opaque |
| 103 | ); |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 104 | void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 105 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 106 | SWVoiceOut *AUD_open_out ( |
| 107 | QEMUSoundCard *card, |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 108 | SWVoiceOut *sw, |
| 109 | const char *name, |
| 110 | void *callback_opaque, |
malc | cb4f03e | 2009-10-15 02:40:17 +0400 | [diff] [blame] | 111 | audio_callback_fn callback_fn, |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 112 | struct audsettings *settings |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 113 | ); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 114 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 115 | void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw); |
Kővágó, Zoltán | 7520462 | 2019-08-19 01:06:58 +0200 | [diff] [blame] | 116 | size_t AUD_write (SWVoiceOut *sw, void *pcm_buf, size_t size); |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 117 | int AUD_get_buffer_size_out (SWVoiceOut *sw); |
| 118 | void AUD_set_active_out (SWVoiceOut *sw, int on); |
| 119 | int AUD_is_active_out (SWVoiceOut *sw); |
| 120 | |
| 121 | void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); |
| 122 | uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); |
| 123 | |
balrog | 683efdc | 2008-05-04 10:21:03 +0000 | [diff] [blame] | 124 | void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol); |
| 125 | void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol); |
| 126 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 127 | SWVoiceIn *AUD_open_in ( |
| 128 | QEMUSoundCard *card, |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 129 | SWVoiceIn *sw, |
| 130 | const char *name, |
| 131 | void *callback_opaque, |
malc | cb4f03e | 2009-10-15 02:40:17 +0400 | [diff] [blame] | 132 | audio_callback_fn callback_fn, |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 133 | struct audsettings *settings |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 134 | ); |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 135 | |
| 136 | void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw); |
Kővágó, Zoltán | 7520462 | 2019-08-19 01:06:58 +0200 | [diff] [blame] | 137 | size_t AUD_read (SWVoiceIn *sw, void *pcm_buf, size_t size); |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 138 | void AUD_set_active_in (SWVoiceIn *sw, int on); |
| 139 | int AUD_is_active_in (SWVoiceIn *sw); |
| 140 | |
| 141 | void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); |
| 142 | uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 143 | |
| 144 | static inline void *advance (void *p, int incr) |
| 145 | { |
| 146 | uint8_t *d = p; |
| 147 | return (d + incr); |
| 148 | } |
| 149 | |
Kővágó, Zoltán | ecd97e9 | 2019-08-19 01:06:47 +0200 | [diff] [blame] | 150 | int wav_start_capture(AudioState *state, CaptureState *s, const char *path, |
| 151 | int freq, int bits, int nchannels); |
blueswir1 | 295e390 | 2008-10-05 10:30:43 +0000 | [diff] [blame] | 152 | |
Marc-André Lureau | a384c20 | 2016-08-01 15:23:43 +0400 | [diff] [blame] | 153 | bool audio_is_cleaning_up(void); |
| 154 | void audio_cleanup(void); |
| 155 | |
Pavel Dovgalyuk | 3d4d16f | 2017-02-02 08:50:54 +0300 | [diff] [blame] | 156 | void audio_sample_to_uint64(void *samples, int pos, |
| 157 | uint64_t *left, uint64_t *right); |
| 158 | void audio_sample_from_uint64(void *samples, int pos, |
| 159 | uint64_t left, uint64_t right); |
| 160 | |
Kővágó, Zoltán | 7183022 | 2019-03-08 23:34:15 +0100 | [diff] [blame] | 161 | void audio_parse_option(const char *opt); |
| 162 | void audio_init_audiodevs(void); |
| 163 | void audio_legacy_help(void); |
| 164 | |
Kővágó, Zoltán | ecd97e9 | 2019-08-19 01:06:47 +0200 | [diff] [blame] | 165 | AudioState *audio_state_by_name(const char *name); |
| 166 | const char *audio_get_id(QEMUSoundCard *card); |
| 167 | |
Kővágó, Zoltán | 88e47b9 | 2019-08-19 01:06:49 +0200 | [diff] [blame] | 168 | #define DEFINE_AUDIO_PROPERTIES(_s, _f) \ |
| 169 | DEFINE_PROP_AUDIODEV("audiodev", _s, _f) |
| 170 | |
Markus Armbruster | 175de52 | 2016-06-29 15:29:06 +0200 | [diff] [blame] | 171 | #endif /* QEMU_AUDIO_H */ |