]> git.proxmox.com Git - mirror_qemu.git/blame - audio/audio.h
vmstate: check subsection_found is enough
[mirror_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 */
175de524 24
85571bc7
FB
25#ifndef QEMU_AUDIO_H
26#define QEMU_AUDIO_H
27
1de7afc9 28#include "qemu/queue.h"
85bc5852 29#include "qapi/qapi-types-audio.h"
c0fe3827 30
cb4f03e8 31typedef void (*audio_callback_fn) (void *opaque, int avail);
85571bc7 32
e2542fe2 33#ifdef HOST_WORDS_BIGENDIAN
d929eba5
FB
34#define AUDIO_HOST_ENDIANNESS 1
35#else
36#define AUDIO_HOST_ENDIANNESS 0
37#endif
38
71830221 39typedef struct audsettings {
c0fe3827
FB
40 int freq;
41 int nchannels;
85bc5852 42 AudioFormat fmt;
d929eba5 43 int endianness;
71830221
KZ
44} audsettings;
45
46audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo);
47int audioformat_bytes_per_sample(AudioFormat fmt);
48int audio_buffer_frames(AudiodevPerDirectionOptions *pdo,
49 audsettings *as, int def_usecs);
50int audio_buffer_samples(AudiodevPerDirectionOptions *pdo,
51 audsettings *as, int def_usecs);
52int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
53 audsettings *as, int def_usecs);
c0fe3827 54
ec36b695
FB
55typedef enum {
56 AUD_CNOTIFY_ENABLE,
57 AUD_CNOTIFY_DISABLE
58} audcnotification_e;
59
8ead62cf 60struct audio_capture_ops {
ec36b695 61 void (*notify) (void *opaque, audcnotification_e cmd);
8ead62cf 62 void (*capture) (void *opaque, void *buf, int size);
ec36b695 63 void (*destroy) (void *opaque);
8ead62cf
FB
64};
65
ec36b695
FB
66struct capture_ops {
67 void (*info) (void *opaque);
68 void (*destroy) (void *opaque);
69};
70
71typedef struct CaptureState {
72 void *opaque;
73 struct capture_ops ops;
72cf2d4f 74 QLIST_ENTRY (CaptureState) entries;
ec36b695
FB
75} CaptureState;
76
1d14ffa9 77typedef struct SWVoiceOut SWVoiceOut;
ec36b695 78typedef struct CaptureVoiceOut CaptureVoiceOut;
1d14ffa9
FB
79typedef struct SWVoiceIn SWVoiceIn;
80
c0fe3827 81typedef struct QEMUSoundCard {
c0fe3827 82 char *name;
72cf2d4f 83 QLIST_ENTRY (QEMUSoundCard) entries;
c0fe3827
FB
84} QEMUSoundCard;
85
1d14ffa9
FB
86typedef struct QEMUAudioTimeStamp {
87 uint64_t old_ts;
88} QEMUAudioTimeStamp;
89
8b7968f7 90void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
e5924d89 91void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
85571bc7 92
1a7dafce 93void AUD_register_card (const char *name, QEMUSoundCard *card);
c0fe3827 94void AUD_remove_card (QEMUSoundCard *card);
ec36b695 95CaptureVoiceOut *AUD_add_capture (
1ea879e5 96 struct audsettings *as,
8ead62cf
FB
97 struct audio_capture_ops *ops,
98 void *opaque
99 );
ec36b695 100void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
1d14ffa9 101
c0fe3827
FB
102SWVoiceOut *AUD_open_out (
103 QEMUSoundCard *card,
1d14ffa9
FB
104 SWVoiceOut *sw,
105 const char *name,
106 void *callback_opaque,
cb4f03e8 107 audio_callback_fn callback_fn,
1ea879e5 108 struct audsettings *settings
1d14ffa9 109 );
c0fe3827
FB
110
111void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
112int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
113int AUD_get_buffer_size_out (SWVoiceOut *sw);
114void AUD_set_active_out (SWVoiceOut *sw, int on);
115int AUD_is_active_out (SWVoiceOut *sw);
116
117void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
118uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
119
683efdcb
AZ
120void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol);
121void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol);
122
c0fe3827
FB
123SWVoiceIn *AUD_open_in (
124 QEMUSoundCard *card,
1d14ffa9
FB
125 SWVoiceIn *sw,
126 const char *name,
127 void *callback_opaque,
cb4f03e8 128 audio_callback_fn callback_fn,
1ea879e5 129 struct audsettings *settings
1d14ffa9 130 );
c0fe3827
FB
131
132void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
133int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
134void AUD_set_active_in (SWVoiceIn *sw, int on);
135int AUD_is_active_in (SWVoiceIn *sw);
136
137void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
138uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
85571bc7
FB
139
140static inline void *advance (void *p, int incr)
141{
142 uint8_t *d = p;
143 return (d + incr);
144}
145
1d14ffa9
FB
146#ifdef __GNUC__
147#define audio_MIN(a, b) ( __extension__ ({ \
148 __typeof (a) ta = a; \
149 __typeof (b) tb = b; \
150 ((ta)>(tb)?(tb):(ta)); \
151}))
152
153#define audio_MAX(a, b) ( __extension__ ({ \
154 __typeof (a) ta = a; \
155 __typeof (b) tb = b; \
156 ((ta)<(tb)?(tb):(ta)); \
157}))
158#else
85571bc7
FB
159#define audio_MIN(a, b) ((a)>(b)?(b):(a))
160#define audio_MAX(a, b) ((a)<(b)?(b):(a))
1d14ffa9 161#endif
85571bc7 162
295e390f
BS
163int wav_start_capture (CaptureState *s, const char *path, int freq,
164 int bits, int nchannels);
165
a384c205
MAL
166bool audio_is_cleaning_up(void);
167void audio_cleanup(void);
168
3d4d16f4
PD
169void audio_sample_to_uint64(void *samples, int pos,
170 uint64_t *left, uint64_t *right);
171void audio_sample_from_uint64(void *samples, int pos,
172 uint64_t left, uint64_t right);
173
71830221
KZ
174void audio_parse_option(const char *opt);
175void audio_init_audiodevs(void);
176void audio_legacy_help(void);
177
175de524 178#endif /* QEMU_AUDIO_H */