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 | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame^] | 27 | #include "config.h" |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 28 | #include "sys-queue.h" |
| 29 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 30 | typedef void (*audio_callback_fn_t) (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, |
| 36 | AUD_FMT_S16 |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 37 | } audfmt_e; |
| 38 | |
bellard | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame^] | 39 | #ifdef WORDS_BIGENDIAN |
| 40 | #define AUDIO_HOST_ENDIANNESS 1 |
| 41 | #else |
| 42 | #define AUDIO_HOST_ENDIANNESS 0 |
| 43 | #endif |
| 44 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 45 | typedef struct { |
| 46 | int freq; |
| 47 | int nchannels; |
| 48 | audfmt_e fmt; |
bellard | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame^] | 49 | int endianness; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 50 | } audsettings_t; |
| 51 | |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 52 | struct audio_capture_ops { |
| 53 | void (*state) (void *opaque, int enabled); |
| 54 | void (*capture) (void *opaque, void *buf, int size); |
| 55 | }; |
| 56 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 57 | typedef struct AudioState AudioState; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 58 | typedef struct SWVoiceOut SWVoiceOut; |
| 59 | typedef struct SWVoiceIn SWVoiceIn; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 60 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 61 | typedef struct QEMUSoundCard { |
| 62 | AudioState *audio; |
| 63 | char *name; |
| 64 | LIST_ENTRY (QEMUSoundCard) entries; |
| 65 | } QEMUSoundCard; |
| 66 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 67 | typedef struct QEMUAudioTimeStamp { |
| 68 | uint64_t old_ts; |
| 69 | } QEMUAudioTimeStamp; |
| 70 | |
| 71 | void AUD_vlog (const char *cap, const char *fmt, va_list ap); |
| 72 | void AUD_log (const char *cap, const char *fmt, ...) |
| 73 | #ifdef __GNUC__ |
| 74 | __attribute__ ((__format__ (__printf__, 2, 3))) |
| 75 | #endif |
| 76 | ; |
| 77 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 78 | AudioState *AUD_init (void); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 79 | void AUD_help (void); |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 80 | void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card); |
| 81 | void AUD_remove_card (QEMUSoundCard *card); |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 82 | int AUD_add_capture ( |
| 83 | AudioState *s, |
| 84 | audsettings_t *as, |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 85 | struct audio_capture_ops *ops, |
| 86 | void *opaque |
| 87 | ); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 88 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 89 | SWVoiceOut *AUD_open_out ( |
| 90 | QEMUSoundCard *card, |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 91 | SWVoiceOut *sw, |
| 92 | const char *name, |
| 93 | void *callback_opaque, |
| 94 | audio_callback_fn_t callback_fn, |
bellard | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame^] | 95 | audsettings_t *settings |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 96 | ); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 97 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 98 | void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw); |
| 99 | int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size); |
| 100 | int AUD_get_buffer_size_out (SWVoiceOut *sw); |
| 101 | void AUD_set_active_out (SWVoiceOut *sw, int on); |
| 102 | int AUD_is_active_out (SWVoiceOut *sw); |
| 103 | |
| 104 | void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); |
| 105 | uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); |
| 106 | |
| 107 | SWVoiceIn *AUD_open_in ( |
| 108 | QEMUSoundCard *card, |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 109 | SWVoiceIn *sw, |
| 110 | const char *name, |
| 111 | void *callback_opaque, |
| 112 | audio_callback_fn_t callback_fn, |
bellard | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame^] | 113 | audsettings_t *settings |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 114 | ); |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 115 | |
| 116 | void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw); |
| 117 | int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size); |
| 118 | void AUD_set_active_in (SWVoiceIn *sw, int on); |
| 119 | int AUD_is_active_in (SWVoiceIn *sw); |
| 120 | |
| 121 | void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); |
| 122 | uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 123 | |
| 124 | static inline void *advance (void *p, int incr) |
| 125 | { |
| 126 | uint8_t *d = p; |
| 127 | return (d + incr); |
| 128 | } |
| 129 | |
| 130 | uint32_t popcount (uint32_t u); |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 131 | uint32_t lsbindex (uint32_t u); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 132 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 133 | #ifdef __GNUC__ |
| 134 | #define audio_MIN(a, b) ( __extension__ ({ \ |
| 135 | __typeof (a) ta = a; \ |
| 136 | __typeof (b) tb = b; \ |
| 137 | ((ta)>(tb)?(tb):(ta)); \ |
| 138 | })) |
| 139 | |
| 140 | #define audio_MAX(a, b) ( __extension__ ({ \ |
| 141 | __typeof (a) ta = a; \ |
| 142 | __typeof (b) tb = b; \ |
| 143 | ((ta)<(tb)?(tb):(ta)); \ |
| 144 | })) |
| 145 | #else |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 146 | #define audio_MIN(a, b) ((a)>(b)?(b):(a)) |
| 147 | #define audio_MAX(a, b) ((a)<(b)?(b):(a)) |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 148 | #endif |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 149 | |
| 150 | #endif /* audio.h */ |