audio: use qapi AudioFormat instead of audfmt_e
[qemu/ericb.git] / audio / audio.h
blob02f29a3b3ef7dafed8a040bdb348ebb4c76a6fd3
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.
25 #ifndef QEMU_AUDIO_H
26 #define QEMU_AUDIO_H
28 #include "qemu/queue.h"
29 #include "qapi/qapi-types-audio.h"
31 typedef void (*audio_callback_fn) (void *opaque, int avail);
33 #ifdef HOST_WORDS_BIGENDIAN
34 #define AUDIO_HOST_ENDIANNESS 1
35 #else
36 #define AUDIO_HOST_ENDIANNESS 0
37 #endif
39 struct audsettings {
40 int freq;
41 int nchannels;
42 AudioFormat fmt;
43 int endianness;
46 typedef enum {
47 AUD_CNOTIFY_ENABLE,
48 AUD_CNOTIFY_DISABLE
49 } audcnotification_e;
51 struct audio_capture_ops {
52 void (*notify) (void *opaque, audcnotification_e cmd);
53 void (*capture) (void *opaque, void *buf, int size);
54 void (*destroy) (void *opaque);
57 struct capture_ops {
58 void (*info) (void *opaque);
59 void (*destroy) (void *opaque);
62 typedef struct CaptureState {
63 void *opaque;
64 struct capture_ops ops;
65 QLIST_ENTRY (CaptureState) entries;
66 } CaptureState;
68 typedef struct SWVoiceOut SWVoiceOut;
69 typedef struct CaptureVoiceOut CaptureVoiceOut;
70 typedef struct SWVoiceIn SWVoiceIn;
72 typedef struct QEMUSoundCard {
73 char *name;
74 QLIST_ENTRY (QEMUSoundCard) entries;
75 } QEMUSoundCard;
77 typedef struct QEMUAudioTimeStamp {
78 uint64_t old_ts;
79 } QEMUAudioTimeStamp;
81 void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
82 void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
84 void AUD_help (void);
85 void AUD_register_card (const char *name, QEMUSoundCard *card);
86 void AUD_remove_card (QEMUSoundCard *card);
87 CaptureVoiceOut *AUD_add_capture (
88 struct audsettings *as,
89 struct audio_capture_ops *ops,
90 void *opaque
92 void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
94 SWVoiceOut *AUD_open_out (
95 QEMUSoundCard *card,
96 SWVoiceOut *sw,
97 const char *name,
98 void *callback_opaque,
99 audio_callback_fn callback_fn,
100 struct audsettings *settings
103 void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
104 int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
105 int AUD_get_buffer_size_out (SWVoiceOut *sw);
106 void AUD_set_active_out (SWVoiceOut *sw, int on);
107 int AUD_is_active_out (SWVoiceOut *sw);
109 void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
110 uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
112 void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol);
113 void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol);
115 SWVoiceIn *AUD_open_in (
116 QEMUSoundCard *card,
117 SWVoiceIn *sw,
118 const char *name,
119 void *callback_opaque,
120 audio_callback_fn callback_fn,
121 struct audsettings *settings
124 void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
125 int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
126 void AUD_set_active_in (SWVoiceIn *sw, int on);
127 int AUD_is_active_in (SWVoiceIn *sw);
129 void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
130 uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
132 static inline void *advance (void *p, int incr)
134 uint8_t *d = p;
135 return (d + incr);
138 #ifdef __GNUC__
139 #define audio_MIN(a, b) ( __extension__ ({ \
140 __typeof (a) ta = a; \
141 __typeof (b) tb = b; \
142 ((ta)>(tb)?(tb):(ta)); \
145 #define audio_MAX(a, b) ( __extension__ ({ \
146 __typeof (a) ta = a; \
147 __typeof (b) tb = b; \
148 ((ta)<(tb)?(tb):(ta)); \
150 #else
151 #define audio_MIN(a, b) ((a)>(b)?(b):(a))
152 #define audio_MAX(a, b) ((a)<(b)?(b):(a))
153 #endif
155 int wav_start_capture (CaptureState *s, const char *path, int freq,
156 int bits, int nchannels);
158 bool audio_is_cleaning_up(void);
159 void audio_cleanup(void);
161 void audio_sample_to_uint64(void *samples, int pos,
162 uint64_t *left, uint64_t *right);
163 void audio_sample_from_uint64(void *samples, int pos,
164 uint64_t left, uint64_t right);
166 #endif /* QEMU_AUDIO_H */