blob: 13fc7cc2a6d07a5727eafd68b19c66211e3319ee [file] [log] [blame]
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001/*
2 * QEMU Audio subsystem header
3 *
4 * Copyright (c) 2003-2005 Vassili Karpov (malc)
5 *
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
David 'Digit' Turnera5d41202010-05-10 18:37:10 -070027#include "config-host.h"
28#include "qemu-queue.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080029
David 'Digit' Turnera5d41202010-05-10 18:37:10 -070030typedef void (*audio_callback_fn) (void *opaque, int avail);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080031
32typedef enum {
33 AUD_FMT_U8,
34 AUD_FMT_S8,
35 AUD_FMT_U16,
36 AUD_FMT_S16,
37 AUD_FMT_U32,
38 AUD_FMT_S32
39} audfmt_e;
40
David 'Digit' Turner20894ae2010-05-10 17:07:36 -070041#ifdef HOST_WORDS_BIGENDIAN
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080042#define AUDIO_HOST_ENDIANNESS 1
43#else
44#define AUDIO_HOST_ENDIANNESS 0
45#endif
46
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070047struct audsettings {
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080048 int freq;
49 int nchannels;
50 audfmt_e fmt;
51 int endianness;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070052};
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080053
54typedef enum {
55 AUD_CNOTIFY_ENABLE,
56 AUD_CNOTIFY_DISABLE
57} audcnotification_e;
58
59struct audio_capture_ops {
60 void (*notify) (void *opaque, audcnotification_e cmd);
61 void (*capture) (void *opaque, void *buf, int size);
62 void (*destroy) (void *opaque);
63};
64
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;
David 'Digit' Turnera5d41202010-05-10 18:37:10 -070073 QLIST_ENTRY (CaptureState) entries;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080074} CaptureState;
75
76typedef struct SWVoiceOut SWVoiceOut;
77typedef struct CaptureVoiceOut CaptureVoiceOut;
78typedef struct SWVoiceIn SWVoiceIn;
79
80typedef struct QEMUSoundCard {
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080081 char *name;
David 'Digit' Turnera5d41202010-05-10 18:37:10 -070082 QLIST_ENTRY (QEMUSoundCard) entries;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080083} QEMUSoundCard;
84
85typedef struct QEMUAudioTimeStamp {
86 uint64_t old_ts;
87} QEMUAudioTimeStamp;
88
89void AUD_vlog (const char *cap, const char *fmt, va_list ap);
90void AUD_log (const char *cap, const char *fmt, ...)
91#ifdef __GNUC__
92 __attribute__ ((__format__ (__printf__, 2, 3)))
93#endif
94 ;
95
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080096void AUD_help (void);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070097void AUD_register_card (const char *name, QEMUSoundCard *card);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080098void AUD_remove_card (QEMUSoundCard *card);
99CaptureVoiceOut *AUD_add_capture (
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700100 struct audsettings *as,
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800101 struct audio_capture_ops *ops,
102 void *opaque
103 );
104void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
105
106SWVoiceOut *AUD_open_out (
107 QEMUSoundCard *card,
108 SWVoiceOut *sw,
109 const char *name,
110 void *callback_opaque,
David 'Digit' Turnera5d41202010-05-10 18:37:10 -0700111 audio_callback_fn callback_fn,
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700112 struct audsettings *settings
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800113 );
114
115void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
116int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
117int AUD_get_buffer_size_out (SWVoiceOut *sw);
118void AUD_set_active_out (SWVoiceOut *sw, int on);
119int AUD_is_active_out (SWVoiceOut *sw);
120
121void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
122uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
123
124void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol);
125void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol);
126
127SWVoiceIn *AUD_open_in (
128 QEMUSoundCard *card,
129 SWVoiceIn *sw,
130 const char *name,
131 void *callback_opaque,
David 'Digit' Turnera5d41202010-05-10 18:37:10 -0700132 audio_callback_fn callback_fn,
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700133 struct audsettings *settings
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800134 );
135
136void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
137int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
138void AUD_set_active_in (SWVoiceIn *sw, int on);
139int AUD_is_active_in (SWVoiceIn *sw);
140
141void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
142uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
143
144static inline void *advance (void *p, int incr)
145{
146 uint8_t *d = p;
147 return (d + incr);
148}
149
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800150#ifdef __GNUC__
151#define audio_MIN(a, b) ( __extension__ ({ \
152 __typeof (a) ta = a; \
153 __typeof (b) tb = b; \
154 ((ta)>(tb)?(tb):(ta)); \
155}))
156
157#define audio_MAX(a, b) ( __extension__ ({ \
158 __typeof (a) ta = a; \
159 __typeof (b) tb = b; \
160 ((ta)<(tb)?(tb):(ta)); \
161}))
162#else
163#define audio_MIN(a, b) ((a)>(b)?(b):(a))
164#define audio_MAX(a, b) ((a)<(b)?(b):(a))
165#endif
166
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700167int wav_start_capture (CaptureState *s, const char *path, int freq,
168 int bits, int nchannels);
169
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800170extern int
171audio_get_backend_count( int is_input );
172
173extern const char*
174audio_get_backend_name( int is_input, int index, const char* *pinfo );
175
176extern int
177audio_check_backend_name( int is_input, const char* name );
178
179#endif /* audio.h */