]> git.proxmox.com Git - qemu.git/blame - audio/audio.h
fixed QEMU_TOOL tests
[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
d929eba5 27#include "config.h"
c0fe3827
FB
28#include "sys-queue.h"
29
1d14ffa9 30typedef void (*audio_callback_fn_t) (void *opaque, int avail);
85571bc7 31
85571bc7 32typedef enum {
c0fe3827
FB
33 AUD_FMT_U8,
34 AUD_FMT_S8,
35 AUD_FMT_U16,
f941aa25
TS
36 AUD_FMT_S16,
37 AUD_FMT_U32,
38 AUD_FMT_S32
85571bc7
FB
39} audfmt_e;
40
d929eba5
FB
41#ifdef WORDS_BIGENDIAN
42#define AUDIO_HOST_ENDIANNESS 1
43#else
44#define AUDIO_HOST_ENDIANNESS 0
45#endif
46
c0fe3827
FB
47typedef struct {
48 int freq;
49 int nchannels;
50 audfmt_e fmt;
d929eba5 51 int endianness;
c0fe3827
FB
52} audsettings_t;
53
ec36b695
FB
54typedef enum {
55 AUD_CNOTIFY_ENABLE,
56 AUD_CNOTIFY_DISABLE
57} audcnotification_e;
58
8ead62cf 59struct audio_capture_ops {
ec36b695 60 void (*notify) (void *opaque, audcnotification_e cmd);
8ead62cf 61 void (*capture) (void *opaque, void *buf, int size);
ec36b695 62 void (*destroy) (void *opaque);
8ead62cf
FB
63};
64
ec36b695
FB
65struct capture_ops {
66 void (*info) (void *opaque);
67 void (*destroy) (void *opaque);
68};
69
70typedef struct CaptureState {
71 void *opaque;
72 struct capture_ops ops;
73 LIST_ENTRY (CaptureState) entries;
74} CaptureState;
75
c0fe3827 76typedef struct AudioState AudioState;
1d14ffa9 77typedef struct SWVoiceOut SWVoiceOut;
ec36b695 78typedef struct CaptureVoiceOut CaptureVoiceOut;
1d14ffa9
FB
79typedef struct SWVoiceIn SWVoiceIn;
80
c0fe3827
FB
81typedef struct QEMUSoundCard {
82 AudioState *audio;
83 char *name;
84 LIST_ENTRY (QEMUSoundCard) entries;
85} QEMUSoundCard;
86
1d14ffa9
FB
87typedef struct QEMUAudioTimeStamp {
88 uint64_t old_ts;
89} QEMUAudioTimeStamp;
90
91void AUD_vlog (const char *cap, const char *fmt, va_list ap);
92void AUD_log (const char *cap, const char *fmt, ...)
93#ifdef __GNUC__
94 __attribute__ ((__format__ (__printf__, 2, 3)))
95#endif
96 ;
85571bc7 97
c0fe3827 98AudioState *AUD_init (void);
1d14ffa9 99void AUD_help (void);
c0fe3827
FB
100void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card);
101void AUD_remove_card (QEMUSoundCard *card);
ec36b695 102CaptureVoiceOut *AUD_add_capture (
8ead62cf
FB
103 AudioState *s,
104 audsettings_t *as,
8ead62cf
FB
105 struct audio_capture_ops *ops,
106 void *opaque
107 );
ec36b695 108void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
1d14ffa9 109
c0fe3827
FB
110SWVoiceOut *AUD_open_out (
111 QEMUSoundCard *card,
1d14ffa9
FB
112 SWVoiceOut *sw,
113 const char *name,
114 void *callback_opaque,
115 audio_callback_fn_t callback_fn,
d929eba5 116 audsettings_t *settings
1d14ffa9 117 );
c0fe3827
FB
118
119void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
120int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
121int AUD_get_buffer_size_out (SWVoiceOut *sw);
122void AUD_set_active_out (SWVoiceOut *sw, int on);
123int AUD_is_active_out (SWVoiceOut *sw);
124
125void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
126uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
127
128SWVoiceIn *AUD_open_in (
129 QEMUSoundCard *card,
1d14ffa9
FB
130 SWVoiceIn *sw,
131 const char *name,
132 void *callback_opaque,
133 audio_callback_fn_t callback_fn,
d929eba5 134 audsettings_t *settings
1d14ffa9 135 );
c0fe3827
FB
136
137void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
138int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
139void AUD_set_active_in (SWVoiceIn *sw, int on);
140int AUD_is_active_in (SWVoiceIn *sw);
141
142void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
143uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
85571bc7
FB
144
145static inline void *advance (void *p, int incr)
146{
147 uint8_t *d = p;
148 return (d + incr);
149}
150
151uint32_t popcount (uint32_t u);
8ead62cf 152uint32_t lsbindex (uint32_t u);
85571bc7 153
1d14ffa9
FB
154#ifdef __GNUC__
155#define audio_MIN(a, b) ( __extension__ ({ \
156 __typeof (a) ta = a; \
157 __typeof (b) tb = b; \
158 ((ta)>(tb)?(tb):(ta)); \
159}))
160
161#define audio_MAX(a, b) ( __extension__ ({ \
162 __typeof (a) ta = a; \
163 __typeof (b) tb = b; \
164 ((ta)<(tb)?(tb):(ta)); \
165}))
166#else
85571bc7
FB
167#define audio_MIN(a, b) ((a)>(b)?(b):(a))
168#define audio_MAX(a, b) ((a)<(b)?(b):(a))
1d14ffa9 169#endif
85571bc7
FB
170
171#endif /* audio.h */