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
28 #include "sys-queue.h"
30 typedef void (*audio_callback_fn_t
) (void *opaque
, int avail
);
39 #ifdef WORDS_BIGENDIAN
40 #define AUDIO_HOST_ENDIANNESS 1
42 #define AUDIO_HOST_ENDIANNESS 0
57 struct audio_capture_ops
{
58 void (*notify
) (void *opaque
, audcnotification_e cmd
);
59 void (*capture
) (void *opaque
, void *buf
, int size
);
60 void (*destroy
) (void *opaque
);
64 void (*info
) (void *opaque
);
65 void (*destroy
) (void *opaque
);
68 typedef struct CaptureState
{
70 struct capture_ops ops
;
71 LIST_ENTRY (CaptureState
) entries
;
74 typedef struct AudioState AudioState
;
75 typedef struct SWVoiceOut SWVoiceOut
;
76 typedef struct CaptureVoiceOut CaptureVoiceOut
;
77 typedef struct SWVoiceIn SWVoiceIn
;
79 typedef struct QEMUSoundCard
{
82 LIST_ENTRY (QEMUSoundCard
) entries
;
85 typedef struct QEMUAudioTimeStamp
{
89 void AUD_vlog (const char *cap
, const char *fmt
, va_list ap
);
90 void AUD_log (const char *cap
, const char *fmt
, ...)
92 __attribute__ ((__format__ (__printf__
, 2, 3)))
96 AudioState
*AUD_init (void);
98 void AUD_register_card (AudioState
*s
, const char *name
, QEMUSoundCard
*card
);
99 void AUD_remove_card (QEMUSoundCard
*card
);
100 CaptureVoiceOut
*AUD_add_capture (
103 struct audio_capture_ops
*ops
,
106 void AUD_del_capture (CaptureVoiceOut
*cap
, void *cb_opaque
);
108 SWVoiceOut
*AUD_open_out (
112 void *callback_opaque
,
113 audio_callback_fn_t callback_fn
,
114 audsettings_t
*settings
117 void AUD_close_out (QEMUSoundCard
*card
, SWVoiceOut
*sw
);
118 int AUD_write (SWVoiceOut
*sw
, void *pcm_buf
, int size
);
119 int AUD_get_buffer_size_out (SWVoiceOut
*sw
);
120 void AUD_set_active_out (SWVoiceOut
*sw
, int on
);
121 int AUD_is_active_out (SWVoiceOut
*sw
);
123 void AUD_init_time_stamp_out (SWVoiceOut
*sw
, QEMUAudioTimeStamp
*ts
);
124 uint64_t AUD_get_elapsed_usec_out (SWVoiceOut
*sw
, QEMUAudioTimeStamp
*ts
);
126 SWVoiceIn
*AUD_open_in (
130 void *callback_opaque
,
131 audio_callback_fn_t callback_fn
,
132 audsettings_t
*settings
135 void AUD_close_in (QEMUSoundCard
*card
, SWVoiceIn
*sw
);
136 int AUD_read (SWVoiceIn
*sw
, void *pcm_buf
, int size
);
137 void AUD_set_active_in (SWVoiceIn
*sw
, int on
);
138 int AUD_is_active_in (SWVoiceIn
*sw
);
140 void AUD_init_time_stamp_in (SWVoiceIn
*sw
, QEMUAudioTimeStamp
*ts
);
141 uint64_t AUD_get_elapsed_usec_in (SWVoiceIn
*sw
, QEMUAudioTimeStamp
*ts
);
143 static inline void *advance (void *p
, int incr
)
149 uint32_t popcount (uint32_t u
);
150 uint32_t lsbindex (uint32_t u
);
153 #define audio_MIN(a, b) ( __extension__ ({ \
154 __typeof (a) ta = a; \
155 __typeof (b) tb = b; \
156 ((ta)>(tb)?(tb):(ta)); \
159 #define audio_MAX(a, b) ( __extension__ ({ \
160 __typeof (a) ta = a; \
161 __typeof (b) tb = b; \
162 ((ta)<(tb)?(tb):(ta)); \
165 #define audio_MIN(a, b) ((a)>(b)?(b):(a))
166 #define audio_MAX(a, b) ((a)<(b)?(b):(a))