slirp: Factorizing tcpiphdr structure with an union
[qemu/ar7.git] / audio / audio.h
blobb41a97053d9bc8868bf7a1fc661b331bfa806201
1 /*
2 * QEMU Audio subsystem header
4 * Copyright (c) 2003-2005 Vassili Karpov (malc)
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
24 #ifndef QEMU_AUDIO_H
25 #define QEMU_AUDIO_H
27 #include "qemu/queue.h"
29 typedef void (*audio_callback_fn) (void *opaque, int avail);
31 typedef enum {
32 AUD_FMT_U8,
33 AUD_FMT_S8,
34 AUD_FMT_U16,
35 AUD_FMT_S16,
36 AUD_FMT_U32,
37 AUD_FMT_S32
38 } audfmt_e;
40 #ifdef HOST_WORDS_BIGENDIAN
41 #define AUDIO_HOST_ENDIANNESS 1
42 #else
43 #define AUDIO_HOST_ENDIANNESS 0
44 #endif
46 struct audsettings {
47 int freq;
48 int nchannels;
49 audfmt_e fmt;
50 int endianness;
53 typedef enum {
54 AUD_CNOTIFY_ENABLE,
55 AUD_CNOTIFY_DISABLE
56 } audcnotification_e;
58 struct audio_capture_ops {
59 void (*notify) (void *opaque, audcnotification_e cmd);
60 void (*capture) (void *opaque, void *buf, int size);
61 void (*destroy) (void *opaque);
64 struct capture_ops {
65 void (*info) (void *opaque);
66 void (*destroy) (void *opaque);
69 typedef struct CaptureState {
70 void *opaque;
71 struct capture_ops ops;
72 QLIST_ENTRY (CaptureState) entries;
73 } CaptureState;
75 typedef struct SWVoiceOut SWVoiceOut;
76 typedef struct CaptureVoiceOut CaptureVoiceOut;
77 typedef struct SWVoiceIn SWVoiceIn;
79 typedef struct QEMUSoundCard {
80 char *name;
81 QLIST_ENTRY (QEMUSoundCard) entries;
82 } QEMUSoundCard;
84 typedef struct QEMUAudioTimeStamp {
85 uint64_t old_ts;
86 } QEMUAudioTimeStamp;
88 void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
89 void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
91 void AUD_help (void);
92 void AUD_register_card (const char *name, QEMUSoundCard *card);
93 void AUD_remove_card (QEMUSoundCard *card);
94 CaptureVoiceOut *AUD_add_capture (
95 struct audsettings *as,
96 struct audio_capture_ops *ops,
97 void *opaque
99 void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
101 SWVoiceOut *AUD_open_out (
102 QEMUSoundCard *card,
103 SWVoiceOut *sw,
104 const char *name,
105 void *callback_opaque,
106 audio_callback_fn callback_fn,
107 struct audsettings *settings
110 void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
111 int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
112 int AUD_get_buffer_size_out (SWVoiceOut *sw);
113 void AUD_set_active_out (SWVoiceOut *sw, int on);
114 int AUD_is_active_out (SWVoiceOut *sw);
116 void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
117 uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
119 void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol);
120 void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol);
122 SWVoiceIn *AUD_open_in (
123 QEMUSoundCard *card,
124 SWVoiceIn *sw,
125 const char *name,
126 void *callback_opaque,
127 audio_callback_fn callback_fn,
128 struct audsettings *settings
131 void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
132 int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
133 void AUD_set_active_in (SWVoiceIn *sw, int on);
134 int AUD_is_active_in (SWVoiceIn *sw);
136 void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
137 uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
139 static inline void *advance (void *p, int incr)
141 uint8_t *d = p;
142 return (d + incr);
145 #ifdef __GNUC__
146 #define audio_MIN(a, b) ( __extension__ ({ \
147 __typeof (a) ta = a; \
148 __typeof (b) tb = b; \
149 ((ta)>(tb)?(tb):(ta)); \
152 #define audio_MAX(a, b) ( __extension__ ({ \
153 __typeof (a) ta = a; \
154 __typeof (b) tb = b; \
155 ((ta)<(tb)?(tb):(ta)); \
157 #else
158 #define audio_MIN(a, b) ((a)>(b)?(b):(a))
159 #define audio_MAX(a, b) ((a)<(b)?(b):(a))
160 #endif
162 int wav_start_capture (CaptureState *s, const char *path, int freq,
163 int bits, int nchannels);
165 #endif /* audio.h */