]> Git Repo - qemu.git/blame - audio/audio.h
xics: report errors with the QEMU Error API
[qemu.git] / audio / audio.h
CommitLineData
85571bc7
FB
1/*
2 * QEMU Audio subsystem header
1d14ffa9
FB
3 *
4 * Copyright (c) 2003-2005 Vassili Karpov (malc)
5 *
85571bc7
FB
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
1de7afc9 27#include "qemu/queue.h"
c0fe3827 28
cb4f03e8 29typedef void (*audio_callback_fn) (void *opaque, int avail);
85571bc7 30
85571bc7 31typedef enum {
c0fe3827
FB
32 AUD_FMT_U8,
33 AUD_FMT_S8,
34 AUD_FMT_U16,
f941aa25
TS
35 AUD_FMT_S16,
36 AUD_FMT_U32,
37 AUD_FMT_S32
85571bc7
FB
38} audfmt_e;
39
e2542fe2 40#ifdef HOST_WORDS_BIGENDIAN
d929eba5
FB
41#define AUDIO_HOST_ENDIANNESS 1
42#else
43#define AUDIO_HOST_ENDIANNESS 0
44#endif
45
1ea879e5 46struct audsettings {
c0fe3827
FB
47 int freq;
48 int nchannels;
49 audfmt_e fmt;
d929eba5 50 int endianness;
1ea879e5 51};
c0fe3827 52
ec36b695
FB
53typedef enum {
54 AUD_CNOTIFY_ENABLE,
55 AUD_CNOTIFY_DISABLE
56} audcnotification_e;
57
8ead62cf 58struct audio_capture_ops {
ec36b695 59 void (*notify) (void *opaque, audcnotification_e cmd);
8ead62cf 60 void (*capture) (void *opaque, void *buf, int size);
ec36b695 61 void (*destroy) (void *opaque);
8ead62cf
FB
62};
63
ec36b695
FB
64struct capture_ops {
65 void (*info) (void *opaque);
66 void (*destroy) (void *opaque);
67};
68
69typedef struct CaptureState {
70 void *opaque;
71 struct capture_ops ops;
72cf2d4f 72 QLIST_ENTRY (CaptureState) entries;
ec36b695
FB
73} CaptureState;
74
1d14ffa9 75typedef struct SWVoiceOut SWVoiceOut;
ec36b695 76typedef struct CaptureVoiceOut CaptureVoiceOut;
1d14ffa9
FB
77typedef struct SWVoiceIn SWVoiceIn;
78
c0fe3827 79typedef struct QEMUSoundCard {
c0fe3827 80 char *name;
72cf2d4f 81 QLIST_ENTRY (QEMUSoundCard) entries;
c0fe3827
FB
82} QEMUSoundCard;
83
1d14ffa9
FB
84typedef struct QEMUAudioTimeStamp {
85 uint64_t old_ts;
86} QEMUAudioTimeStamp;
87
8b7968f7 88void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
e5924d89 89void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
85571bc7 90
1d14ffa9 91void AUD_help (void);
1a7dafce 92void AUD_register_card (const char *name, QEMUSoundCard *card);
c0fe3827 93void AUD_remove_card (QEMUSoundCard *card);
ec36b695 94CaptureVoiceOut *AUD_add_capture (
1ea879e5 95 struct audsettings *as,
8ead62cf
FB
96 struct audio_capture_ops *ops,
97 void *opaque
98 );
ec36b695 99void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
1d14ffa9 100
c0fe3827
FB
101SWVoiceOut *AUD_open_out (
102 QEMUSoundCard *card,
1d14ffa9
FB
103 SWVoiceOut *sw,
104 const char *name,
105 void *callback_opaque,
cb4f03e8 106 audio_callback_fn callback_fn,
1ea879e5 107 struct audsettings *settings
1d14ffa9 108 );
c0fe3827
FB
109
110void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
111int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
112int AUD_get_buffer_size_out (SWVoiceOut *sw);
113void AUD_set_active_out (SWVoiceOut *sw, int on);
114int AUD_is_active_out (SWVoiceOut *sw);
115
116void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
117uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
118
683efdcb
AZ
119void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol);
120void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol);
121
c0fe3827
FB
122SWVoiceIn *AUD_open_in (
123 QEMUSoundCard *card,
1d14ffa9
FB
124 SWVoiceIn *sw,
125 const char *name,
126 void *callback_opaque,
cb4f03e8 127 audio_callback_fn callback_fn,
1ea879e5 128 struct audsettings *settings
1d14ffa9 129 );
c0fe3827
FB
130
131void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
132int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
133void AUD_set_active_in (SWVoiceIn *sw, int on);
134int AUD_is_active_in (SWVoiceIn *sw);
135
136void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
137uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
85571bc7
FB
138
139static inline void *advance (void *p, int incr)
140{
141 uint8_t *d = p;
142 return (d + incr);
143}
144
1d14ffa9
FB
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)); \
150}))
151
152#define audio_MAX(a, b) ( __extension__ ({ \
153 __typeof (a) ta = a; \
154 __typeof (b) tb = b; \
155 ((ta)<(tb)?(tb):(ta)); \
156}))
157#else
85571bc7
FB
158#define audio_MIN(a, b) ((a)>(b)?(b):(a))
159#define audio_MAX(a, b) ((a)<(b)?(b):(a))
1d14ffa9 160#endif
85571bc7 161
295e390f
BS
162int wav_start_capture (CaptureState *s, const char *path, int freq,
163 int bits, int nchannels);
164
85571bc7 165#endif /* audio.h */
This page took 0.517464 seconds and 4 git commands to generate.