blob: 14fa3bce9692228bccc67c29fcec363f4c3383e7 [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
bellardd929eba2006-07-04 21:47:22 +000027#include "config.h"
bellardc0fe3822005-11-05 18:55:28 +000028#include "sys-queue.h"
29
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,
36 AUD_FMT_S16
bellard85571bc2004-11-07 18:04:02 +000037} audfmt_e;
38
bellardd929eba2006-07-04 21:47:22 +000039#ifdef WORDS_BIGENDIAN
40#define AUDIO_HOST_ENDIANNESS 1
41#else
42#define AUDIO_HOST_ENDIANNESS 0
43#endif
44
bellardc0fe3822005-11-05 18:55:28 +000045typedef struct {
46 int freq;
47 int nchannels;
48 audfmt_e fmt;
bellardd929eba2006-07-04 21:47:22 +000049 int endianness;
bellardc0fe3822005-11-05 18:55:28 +000050} audsettings_t;
51
bellard8ead62c2006-07-04 16:51:32 +000052struct audio_capture_ops {
53 void (*state) (void *opaque, int enabled);
54 void (*capture) (void *opaque, void *buf, int size);
55};
56
bellardc0fe3822005-11-05 18:55:28 +000057typedef struct AudioState AudioState;
bellard1d14ffa2005-10-30 18:58:22 +000058typedef struct SWVoiceOut SWVoiceOut;
59typedef struct SWVoiceIn SWVoiceIn;
bellard85571bc2004-11-07 18:04:02 +000060
bellardc0fe3822005-11-05 18:55:28 +000061typedef struct QEMUSoundCard {
62 AudioState *audio;
63 char *name;
64 LIST_ENTRY (QEMUSoundCard) entries;
65} QEMUSoundCard;
66
bellard1d14ffa2005-10-30 18:58:22 +000067typedef struct QEMUAudioTimeStamp {
68 uint64_t old_ts;
69} QEMUAudioTimeStamp;
70
71void AUD_vlog (const char *cap, const char *fmt, va_list ap);
72void AUD_log (const char *cap, const char *fmt, ...)
73#ifdef __GNUC__
74 __attribute__ ((__format__ (__printf__, 2, 3)))
75#endif
76 ;
77
bellardc0fe3822005-11-05 18:55:28 +000078AudioState *AUD_init (void);
bellard1d14ffa2005-10-30 18:58:22 +000079void AUD_help (void);
bellardc0fe3822005-11-05 18:55:28 +000080void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card);
81void AUD_remove_card (QEMUSoundCard *card);
bellard8ead62c2006-07-04 16:51:32 +000082int AUD_add_capture (
83 AudioState *s,
84 audsettings_t *as,
bellard8ead62c2006-07-04 16:51:32 +000085 struct audio_capture_ops *ops,
86 void *opaque
87 );
bellard1d14ffa2005-10-30 18:58:22 +000088
bellardc0fe3822005-11-05 18:55:28 +000089SWVoiceOut *AUD_open_out (
90 QEMUSoundCard *card,
bellard1d14ffa2005-10-30 18:58:22 +000091 SWVoiceOut *sw,
92 const char *name,
93 void *callback_opaque,
94 audio_callback_fn_t callback_fn,
bellardd929eba2006-07-04 21:47:22 +000095 audsettings_t *settings
bellard1d14ffa2005-10-30 18:58:22 +000096 );
bellard1d14ffa2005-10-30 18:58:22 +000097
bellardc0fe3822005-11-05 18:55:28 +000098void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
99int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
100int AUD_get_buffer_size_out (SWVoiceOut *sw);
101void AUD_set_active_out (SWVoiceOut *sw, int on);
102int AUD_is_active_out (SWVoiceOut *sw);
103
104void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
105uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
106
107SWVoiceIn *AUD_open_in (
108 QEMUSoundCard *card,
bellard1d14ffa2005-10-30 18:58:22 +0000109 SWVoiceIn *sw,
110 const char *name,
111 void *callback_opaque,
112 audio_callback_fn_t callback_fn,
bellardd929eba2006-07-04 21:47:22 +0000113 audsettings_t *settings
bellard1d14ffa2005-10-30 18:58:22 +0000114 );
bellardc0fe3822005-11-05 18:55:28 +0000115
116void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
117int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
118void AUD_set_active_in (SWVoiceIn *sw, int on);
119int AUD_is_active_in (SWVoiceIn *sw);
120
121void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
122uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
bellard85571bc2004-11-07 18:04:02 +0000123
124static inline void *advance (void *p, int incr)
125{
126 uint8_t *d = p;
127 return (d + incr);
128}
129
130uint32_t popcount (uint32_t u);
bellard8ead62c2006-07-04 16:51:32 +0000131uint32_t lsbindex (uint32_t u);
bellard85571bc2004-11-07 18:04:02 +0000132
bellard1d14ffa2005-10-30 18:58:22 +0000133#ifdef __GNUC__
134#define audio_MIN(a, b) ( __extension__ ({ \
135 __typeof (a) ta = a; \
136 __typeof (b) tb = b; \
137 ((ta)>(tb)?(tb):(ta)); \
138}))
139
140#define audio_MAX(a, b) ( __extension__ ({ \
141 __typeof (a) ta = a; \
142 __typeof (b) tb = b; \
143 ((ta)<(tb)?(tb):(ta)); \
144}))
145#else
bellard85571bc2004-11-07 18:04:02 +0000146#define audio_MIN(a, b) ((a)>(b)?(b):(a))
147#define audio_MAX(a, b) ((a)<(b)?(b):(a))
bellard1d14ffa2005-10-30 18:58:22 +0000148#endif
bellard85571bc2004-11-07 18:04:02 +0000149
150#endif /* audio.h */