blob: c74abb8c4718dd780afbf39b3598a5eb0e0fd7c4 [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 */
Markus Armbruster175de522016-06-29 15:29:06 +020024
bellard85571bc2004-11-07 18:04:02 +000025#ifndef QEMU_AUDIO_H
26#define QEMU_AUDIO_H
27
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010028#include "qemu/queue.h"
Kővágó, Zoltán85bc5852019-03-08 23:34:13 +010029#include "qapi/qapi-types-audio.h"
Kővágó, Zoltán88e47b92019-08-19 01:06:49 +020030#include "hw/qdev-properties.h"
bellardc0fe3822005-11-05 18:55:28 +000031
malccb4f03e2009-10-15 02:40:17 +040032typedef void (*audio_callback_fn) (void *opaque, int avail);
bellard85571bc2004-11-07 18:04:02 +000033
Juan Quintelae2542fe2009-07-27 16:13:06 +020034#ifdef HOST_WORDS_BIGENDIAN
bellardd929eba2006-07-04 21:47:22 +000035#define AUDIO_HOST_ENDIANNESS 1
36#else
37#define AUDIO_HOST_ENDIANNESS 0
38#endif
39
Kővágó, Zoltán71830222019-03-08 23:34:15 +010040typedef struct audsettings {
bellardc0fe3822005-11-05 18:55:28 +000041 int freq;
42 int nchannels;
Kővágó, Zoltán85bc5852019-03-08 23:34:13 +010043 AudioFormat fmt;
bellardd929eba2006-07-04 21:47:22 +000044 int endianness;
Kővágó, Zoltán71830222019-03-08 23:34:15 +010045} audsettings;
46
47audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo);
48int audioformat_bytes_per_sample(AudioFormat fmt);
49int audio_buffer_frames(AudiodevPerDirectionOptions *pdo,
50 audsettings *as, int def_usecs);
51int audio_buffer_samples(AudiodevPerDirectionOptions *pdo,
52 audsettings *as, int def_usecs);
53int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
54 audsettings *as, int def_usecs);
bellardc0fe3822005-11-05 18:55:28 +000055
bellardec36b692006-07-16 18:57:03 +000056typedef enum {
57 AUD_CNOTIFY_ENABLE,
58 AUD_CNOTIFY_DISABLE
59} audcnotification_e;
60
bellard8ead62c2006-07-04 16:51:32 +000061struct audio_capture_ops {
bellardec36b692006-07-16 18:57:03 +000062 void (*notify) (void *opaque, audcnotification_e cmd);
bellard8ead62c2006-07-04 16:51:32 +000063 void (*capture) (void *opaque, void *buf, int size);
bellardec36b692006-07-16 18:57:03 +000064 void (*destroy) (void *opaque);
bellard8ead62c2006-07-04 16:51:32 +000065};
66
bellardec36b692006-07-16 18:57:03 +000067struct capture_ops {
68 void (*info) (void *opaque);
69 void (*destroy) (void *opaque);
70};
71
72typedef struct CaptureState {
73 void *opaque;
74 struct capture_ops ops;
Blue Swirl72cf2d42009-09-12 07:36:22 +000075 QLIST_ENTRY (CaptureState) entries;
bellardec36b692006-07-16 18:57:03 +000076} CaptureState;
77
bellard1d14ffa2005-10-30 18:58:22 +000078typedef struct SWVoiceOut SWVoiceOut;
bellardec36b692006-07-16 18:57:03 +000079typedef struct CaptureVoiceOut CaptureVoiceOut;
bellard1d14ffa2005-10-30 18:58:22 +000080typedef struct SWVoiceIn SWVoiceIn;
bellard85571bc2004-11-07 18:04:02 +000081
Kővágó, Zoltánecd97e92019-08-19 01:06:47 +020082typedef struct AudioState AudioState;
bellardc0fe3822005-11-05 18:55:28 +000083typedef struct QEMUSoundCard {
bellardc0fe3822005-11-05 18:55:28 +000084 char *name;
Kővágó, Zoltánecd97e92019-08-19 01:06:47 +020085 AudioState *state;
Blue Swirl72cf2d42009-09-12 07:36:22 +000086 QLIST_ENTRY (QEMUSoundCard) entries;
bellardc0fe3822005-11-05 18:55:28 +000087} QEMUSoundCard;
88
bellard1d14ffa2005-10-30 18:58:22 +000089typedef struct QEMUAudioTimeStamp {
90 uint64_t old_ts;
91} QEMUAudioTimeStamp;
92
Stefan Weil8b7968f2010-09-23 21:28:05 +020093void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
Stefan Weile5924d82010-09-23 21:28:03 +020094void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
bellard1d14ffa2005-10-30 18:58:22 +000095
malc1a7dafc2009-05-14 03:11:35 +040096void AUD_register_card (const char *name, QEMUSoundCard *card);
bellardc0fe3822005-11-05 18:55:28 +000097void AUD_remove_card (QEMUSoundCard *card);
Kővágó, Zoltánecd97e92019-08-19 01:06:47 +020098CaptureVoiceOut *AUD_add_capture(
99 AudioState *s,
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,
malccb4f03e2009-10-15 02:40:17 +0400111 audio_callback_fn 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);
Kővágó, Zoltán75204622019-08-19 01:06:58 +0200116size_t AUD_write (SWVoiceOut *sw, void *pcm_buf, size_t size);
bellardc0fe3822005-11-05 18:55:28 +0000117int 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,
malccb4f03e2009-10-15 02:40:17 +0400132 audio_callback_fn 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);
Kővágó, Zoltán75204622019-08-19 01:06:58 +0200137size_t AUD_read (SWVoiceIn *sw, void *pcm_buf, size_t size);
bellardc0fe3822005-11-05 18:55:28 +0000138void 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
Kővágó, Zoltánecd97e92019-08-19 01:06:47 +0200150int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
151 int freq, int bits, int nchannels);
blueswir1295e3902008-10-05 10:30:43 +0000152
Marc-André Lureaua384c202016-08-01 15:23:43 +0400153bool audio_is_cleaning_up(void);
154void audio_cleanup(void);
155
Pavel Dovgalyuk3d4d16f2017-02-02 08:50:54 +0300156void audio_sample_to_uint64(void *samples, int pos,
157 uint64_t *left, uint64_t *right);
158void audio_sample_from_uint64(void *samples, int pos,
159 uint64_t left, uint64_t right);
160
Kővágó, Zoltán71830222019-03-08 23:34:15 +0100161void audio_parse_option(const char *opt);
162void audio_init_audiodevs(void);
163void audio_legacy_help(void);
164
Kővágó, Zoltánecd97e92019-08-19 01:06:47 +0200165AudioState *audio_state_by_name(const char *name);
166const char *audio_get_id(QEMUSoundCard *card);
167
Kővágó, Zoltán88e47b92019-08-19 01:06:49 +0200168#define DEFINE_AUDIO_PROPERTIES(_s, _f) \
169 DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
170
Markus Armbruster175de522016-06-29 15:29:06 +0200171#endif /* QEMU_AUDIO_H */