blob: cde7cca648112b7fc1f5c3be7a6b0350e3d74a07 [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"
David 'Digit' Turner031d6552013-12-15 00:52:36 +010028#include "qemu/queue.h"
David 'Digit' Turner9d6baf02010-05-11 16:27:37 -070029#include "qemu-common.h" /* For QEMUTimer */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080030
David 'Digit' Turnera5d41202010-05-10 18:37:10 -070031typedef void (*audio_callback_fn) (void *opaque, int avail);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080032
33typedef enum {
34 AUD_FMT_U8,
35 AUD_FMT_S8,
36 AUD_FMT_U16,
37 AUD_FMT_S16,
38 AUD_FMT_U32,
39 AUD_FMT_S32
40} audfmt_e;
41
David 'Digit' Turner20894ae2010-05-10 17:07:36 -070042#ifdef HOST_WORDS_BIGENDIAN
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080043#define AUDIO_HOST_ENDIANNESS 1
44#else
45#define AUDIO_HOST_ENDIANNESS 0
46#endif
47
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070048struct audsettings {
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080049 int freq;
50 int nchannels;
51 audfmt_e fmt;
52 int endianness;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070053};
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080054
55typedef enum {
56 AUD_CNOTIFY_ENABLE,
57 AUD_CNOTIFY_DISABLE
58} audcnotification_e;
59
60struct audio_capture_ops {
61 void (*notify) (void *opaque, audcnotification_e cmd);
62 void (*capture) (void *opaque, void *buf, int size);
63 void (*destroy) (void *opaque);
64};
65
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;
David 'Digit' Turnera5d41202010-05-10 18:37:10 -070074 QLIST_ENTRY (CaptureState) entries;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080075} CaptureState;
76
77typedef struct SWVoiceOut SWVoiceOut;
78typedef struct CaptureVoiceOut CaptureVoiceOut;
79typedef struct SWVoiceIn SWVoiceIn;
80
81typedef struct QEMUSoundCard {
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080082 char *name;
David 'Digit' Turnera5d41202010-05-10 18:37:10 -070083 QLIST_ENTRY (QEMUSoundCard) entries;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080084} QEMUSoundCard;
85
86typedef struct QEMUAudioTimeStamp {
87 uint64_t old_ts;
88} QEMUAudioTimeStamp;
89
90void AUD_vlog (const char *cap, const char *fmt, va_list ap);
91void AUD_log (const char *cap, const char *fmt, ...)
92#ifdef __GNUC__
93 __attribute__ ((__format__ (__printf__, 2, 3)))
94#endif
95 ;
96
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080097void AUD_help (void);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070098void AUD_register_card (const char *name, QEMUSoundCard *card);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080099void AUD_remove_card (QEMUSoundCard *card);
100CaptureVoiceOut *AUD_add_capture (
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700101 struct audsettings *as,
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800102 struct audio_capture_ops *ops,
103 void *opaque
104 );
105void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
106
107SWVoiceOut *AUD_open_out (
108 QEMUSoundCard *card,
109 SWVoiceOut *sw,
110 const char *name,
111 void *callback_opaque,
David 'Digit' Turnera5d41202010-05-10 18:37:10 -0700112 audio_callback_fn callback_fn,
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700113 struct audsettings *settings
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800114 );
115
116void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
117int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
118int AUD_get_buffer_size_out (SWVoiceOut *sw);
119void AUD_set_active_out (SWVoiceOut *sw, int on);
120int AUD_is_active_out (SWVoiceOut *sw);
121
122void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
123uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
124
125void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol);
126void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol);
127
128SWVoiceIn *AUD_open_in (
129 QEMUSoundCard *card,
130 SWVoiceIn *sw,
131 const char *name,
132 void *callback_opaque,
David 'Digit' Turnera5d41202010-05-10 18:37:10 -0700133 audio_callback_fn callback_fn,
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700134 struct audsettings *settings
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800135 );
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);
144
145static inline void *advance (void *p, int incr)
146{
147 uint8_t *d = p;
148 return (d + incr);
149}
150
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800151#ifdef __GNUC__
152#define audio_MIN(a, b) ( __extension__ ({ \
153 __typeof (a) ta = a; \
154 __typeof (b) tb = b; \
155 ((ta)>(tb)?(tb):(ta)); \
156}))
157
158#define audio_MAX(a, b) ( __extension__ ({ \
159 __typeof (a) ta = a; \
160 __typeof (b) tb = b; \
161 ((ta)<(tb)?(tb):(ta)); \
162}))
163#else
164#define audio_MIN(a, b) ((a)>(b)?(b):(a))
165#define audio_MAX(a, b) ((a)<(b)?(b):(a))
166#endif
167
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700168int wav_start_capture (CaptureState *s, const char *path, int freq,
169 int bits, int nchannels);
170
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800171extern int
172audio_get_backend_count( int is_input );
173
174extern const char*
175audio_get_backend_name( int is_input, int index, const char* *pinfo );
176
177extern int
178audio_check_backend_name( int is_input, const char* name );
179
180#endif /* audio.h */