blob: f234ad0f54d3ef9d4c57e0010354b835839185b1 [file] [log] [blame]
bellard85571bc2004-11-07 18:04:02 +00001/*
2 * QEMU Audio subsystem header
bellard1d14ffa2005-10-30 18:58:22 +00003 *
4 * Copyright (c) 2003-2005 Vassili Karpov (malc)
5 *
bellard85571bc2004-11-07 18:04:02 +00006 * 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
bellard5fa0ab82007-11-07 19:27:18 +000027#include "config-host.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +000028#include "qemu-queue.h"
bellardc0fe3822005-11-05 18:55:28 +000029
bellard1d14ffa2005-10-30 18:58:22 +000030typedef void (*audio_callback_fn_t) (void *opaque, int avail);
bellard85571bc2004-11-07 18:04:02 +000031
bellard85571bc2004-11-07 18:04:02 +000032typedef enum {
bellardc0fe3822005-11-05 18:55:28 +000033 AUD_FMT_U8,
34 AUD_FMT_S8,
35 AUD_FMT_U16,
thsf941aa22007-02-17 22:19:29 +000036 AUD_FMT_S16,
37 AUD_FMT_U32,
38 AUD_FMT_S32
bellard85571bc2004-11-07 18:04:02 +000039} audfmt_e;
40
Juan Quintelae2542fe2009-07-27 16:13:06 +020041#ifdef HOST_WORDS_BIGENDIAN
bellardd929eba2006-07-04 21:47:22 +000042#define AUDIO_HOST_ENDIANNESS 1
43#else
44#define AUDIO_HOST_ENDIANNESS 0
45#endif
46
malc1ea879e2008-12-03 22:48:44 +000047struct audsettings {
bellardc0fe3822005-11-05 18:55:28 +000048 int freq;
49 int nchannels;
50 audfmt_e fmt;
bellardd929eba2006-07-04 21:47:22 +000051 int endianness;
malc1ea879e2008-12-03 22:48:44 +000052};
bellardc0fe3822005-11-05 18:55:28 +000053
bellardec36b692006-07-16 18:57:03 +000054typedef enum {
55 AUD_CNOTIFY_ENABLE,
56 AUD_CNOTIFY_DISABLE
57} audcnotification_e;
58
bellard8ead62c2006-07-04 16:51:32 +000059struct audio_capture_ops {
bellardec36b692006-07-16 18:57:03 +000060 void (*notify) (void *opaque, audcnotification_e cmd);
bellard8ead62c2006-07-04 16:51:32 +000061 void (*capture) (void *opaque, void *buf, int size);
bellardec36b692006-07-16 18:57:03 +000062 void (*destroy) (void *opaque);
bellard8ead62c2006-07-04 16:51:32 +000063};
64
bellardec36b692006-07-16 18:57:03 +000065struct 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;
Blue Swirl72cf2d42009-09-12 07:36:22 +000073 QLIST_ENTRY (CaptureState) entries;
bellardec36b692006-07-16 18:57:03 +000074} CaptureState;
75
bellard1d14ffa2005-10-30 18:58:22 +000076typedef struct SWVoiceOut SWVoiceOut;
bellardec36b692006-07-16 18:57:03 +000077typedef struct CaptureVoiceOut CaptureVoiceOut;
bellard1d14ffa2005-10-30 18:58:22 +000078typedef struct SWVoiceIn SWVoiceIn;
bellard85571bc2004-11-07 18:04:02 +000079
bellardc0fe3822005-11-05 18:55:28 +000080typedef struct QEMUSoundCard {
bellardc0fe3822005-11-05 18:55:28 +000081 char *name;
Blue Swirl72cf2d42009-09-12 07:36:22 +000082 QLIST_ENTRY (QEMUSoundCard) entries;
bellardc0fe3822005-11-05 18:55:28 +000083} QEMUSoundCard;
84
bellard1d14ffa2005-10-30 18:58:22 +000085typedef 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
bellard1d14ffa2005-10-30 18:58:22 +000096void AUD_help (void);
malc1a7dafc2009-05-14 03:11:35 +040097void AUD_register_card (const char *name, QEMUSoundCard *card);
bellardc0fe3822005-11-05 18:55:28 +000098void AUD_remove_card (QEMUSoundCard *card);
bellardec36b692006-07-16 18:57:03 +000099CaptureVoiceOut *AUD_add_capture (
malc1ea879e2008-12-03 22:48:44 +0000100 struct audsettings *as,
bellard8ead62c2006-07-04 16:51:32 +0000101 struct audio_capture_ops *ops,
102 void *opaque
103 );
bellardec36b692006-07-16 18:57:03 +0000104void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
bellard1d14ffa2005-10-30 18:58:22 +0000105
bellardc0fe3822005-11-05 18:55:28 +0000106SWVoiceOut *AUD_open_out (
107 QEMUSoundCard *card,
bellard1d14ffa2005-10-30 18:58:22 +0000108 SWVoiceOut *sw,
109 const char *name,
110 void *callback_opaque,
111 audio_callback_fn_t callback_fn,
malc1ea879e2008-12-03 22:48:44 +0000112 struct audsettings *settings
bellard1d14ffa2005-10-30 18:58:22 +0000113 );
bellard1d14ffa2005-10-30 18:58:22 +0000114
bellardc0fe3822005-11-05 18:55:28 +0000115void 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
balrog683efdc2008-05-04 10:21:03 +0000124void 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
bellardc0fe3822005-11-05 18:55:28 +0000127SWVoiceIn *AUD_open_in (
128 QEMUSoundCard *card,
bellard1d14ffa2005-10-30 18:58:22 +0000129 SWVoiceIn *sw,
130 const char *name,
131 void *callback_opaque,
132 audio_callback_fn_t callback_fn,
malc1ea879e2008-12-03 22:48:44 +0000133 struct audsettings *settings
bellard1d14ffa2005-10-30 18:58:22 +0000134 );
bellardc0fe3822005-11-05 18:55:28 +0000135
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);
bellard85571bc2004-11-07 18:04:02 +0000143
144static inline void *advance (void *p, int incr)
145{
146 uint8_t *d = p;
147 return (d + incr);
148}
149
bellard1d14ffa2005-10-30 18:58:22 +0000150#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
bellard85571bc2004-11-07 18:04:02 +0000163#define audio_MIN(a, b) ((a)>(b)?(b):(a))
164#define audio_MAX(a, b) ((a)<(b)?(b):(a))
bellard1d14ffa2005-10-30 18:58:22 +0000165#endif
bellard85571bc2004-11-07 18:04:02 +0000166
blueswir1295e3902008-10-05 10:30:43 +0000167int wav_start_capture (CaptureState *s, const char *path, int freq,
168 int bits, int nchannels);
169
bellard85571bc2004-11-07 18:04:02 +0000170#endif /* audio.h */