2004-11-07 21:04:02 +03:00
|
|
|
/*
|
|
|
|
* QEMU Audio subsystem header
|
2005-10-30 21:58:22 +03:00
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2005 Vassili Karpov (malc)
|
|
|
|
*
|
2004-11-07 21:04:02 +03:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2016-06-29 16:29:06 +03:00
|
|
|
|
2004-11-07 21:04:02 +03:00
|
|
|
#ifndef QEMU_AUDIO_H
|
|
|
|
#define QEMU_AUDIO_H
|
|
|
|
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/queue.h"
|
2019-03-09 01:34:13 +03:00
|
|
|
#include "qapi/qapi-types-audio.h"
|
2019-08-19 02:06:49 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2020-12-12 01:05:12 +03:00
|
|
|
#include "hw/qdev-properties-system.h"
|
2005-11-05 21:55:28 +03:00
|
|
|
|
2009-10-15 02:40:17 +04:00
|
|
|
typedef void (*audio_callback_fn) (void *opaque, int avail);
|
2004-11-07 21:04:02 +03:00
|
|
|
|
2009-07-27 18:13:06 +04:00
|
|
|
#ifdef HOST_WORDS_BIGENDIAN
|
2006-07-05 01:47:22 +04:00
|
|
|
#define AUDIO_HOST_ENDIANNESS 1
|
|
|
|
#else
|
|
|
|
#define AUDIO_HOST_ENDIANNESS 0
|
|
|
|
#endif
|
|
|
|
|
2019-03-09 01:34:15 +03:00
|
|
|
typedef struct audsettings {
|
2005-11-05 21:55:28 +03:00
|
|
|
int freq;
|
|
|
|
int nchannels;
|
2019-03-09 01:34:13 +03:00
|
|
|
AudioFormat fmt;
|
2006-07-05 01:47:22 +04:00
|
|
|
int endianness;
|
2019-03-09 01:34:15 +03:00
|
|
|
} audsettings;
|
|
|
|
|
|
|
|
audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo);
|
|
|
|
int audioformat_bytes_per_sample(AudioFormat fmt);
|
|
|
|
int audio_buffer_frames(AudiodevPerDirectionOptions *pdo,
|
|
|
|
audsettings *as, int def_usecs);
|
|
|
|
int audio_buffer_samples(AudiodevPerDirectionOptions *pdo,
|
|
|
|
audsettings *as, int def_usecs);
|
|
|
|
int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
|
|
|
|
audsettings *as, int def_usecs);
|
2005-11-05 21:55:28 +03:00
|
|
|
|
2006-07-16 22:57:03 +04:00
|
|
|
typedef enum {
|
|
|
|
AUD_CNOTIFY_ENABLE,
|
|
|
|
AUD_CNOTIFY_DISABLE
|
|
|
|
} audcnotification_e;
|
|
|
|
|
2006-07-04 20:51:32 +04:00
|
|
|
struct audio_capture_ops {
|
2006-07-16 22:57:03 +04:00
|
|
|
void (*notify) (void *opaque, audcnotification_e cmd);
|
2020-05-05 16:25:58 +03:00
|
|
|
void (*capture) (void *opaque, const void *buf, int size);
|
2006-07-16 22:57:03 +04:00
|
|
|
void (*destroy) (void *opaque);
|
2006-07-04 20:51:32 +04:00
|
|
|
};
|
|
|
|
|
2006-07-16 22:57:03 +04:00
|
|
|
struct capture_ops {
|
|
|
|
void (*info) (void *opaque);
|
|
|
|
void (*destroy) (void *opaque);
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct CaptureState {
|
|
|
|
void *opaque;
|
|
|
|
struct capture_ops ops;
|
2009-09-12 11:36:22 +04:00
|
|
|
QLIST_ENTRY (CaptureState) entries;
|
2006-07-16 22:57:03 +04:00
|
|
|
} CaptureState;
|
|
|
|
|
2005-10-30 21:58:22 +03:00
|
|
|
typedef struct SWVoiceOut SWVoiceOut;
|
2006-07-16 22:57:03 +04:00
|
|
|
typedef struct CaptureVoiceOut CaptureVoiceOut;
|
2005-10-30 21:58:22 +03:00
|
|
|
typedef struct SWVoiceIn SWVoiceIn;
|
|
|
|
|
2019-08-19 02:06:47 +03:00
|
|
|
typedef struct AudioState AudioState;
|
2005-11-05 21:55:28 +03:00
|
|
|
typedef struct QEMUSoundCard {
|
|
|
|
char *name;
|
2019-08-19 02:06:47 +03:00
|
|
|
AudioState *state;
|
2009-09-12 11:36:22 +04:00
|
|
|
QLIST_ENTRY (QEMUSoundCard) entries;
|
2005-11-05 21:55:28 +03:00
|
|
|
} QEMUSoundCard;
|
|
|
|
|
2005-10-30 21:58:22 +03:00
|
|
|
typedef struct QEMUAudioTimeStamp {
|
|
|
|
uint64_t old_ts;
|
|
|
|
} QEMUAudioTimeStamp;
|
|
|
|
|
2010-09-23 23:28:05 +04:00
|
|
|
void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
|
2010-09-23 23:28:03 +04:00
|
|
|
void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
|
2004-11-07 21:04:02 +03:00
|
|
|
|
2009-05-14 03:11:35 +04:00
|
|
|
void AUD_register_card (const char *name, QEMUSoundCard *card);
|
2005-11-05 21:55:28 +03:00
|
|
|
void AUD_remove_card (QEMUSoundCard *card);
|
2019-08-19 02:06:47 +03:00
|
|
|
CaptureVoiceOut *AUD_add_capture(
|
|
|
|
AudioState *s,
|
2008-12-04 01:48:44 +03:00
|
|
|
struct audsettings *as,
|
2006-07-04 20:51:32 +04:00
|
|
|
struct audio_capture_ops *ops,
|
|
|
|
void *opaque
|
|
|
|
);
|
2006-07-16 22:57:03 +04:00
|
|
|
void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2005-11-05 21:55:28 +03:00
|
|
|
SWVoiceOut *AUD_open_out (
|
|
|
|
QEMUSoundCard *card,
|
2005-10-30 21:58:22 +03:00
|
|
|
SWVoiceOut *sw,
|
|
|
|
const char *name,
|
|
|
|
void *callback_opaque,
|
2009-10-15 02:40:17 +04:00
|
|
|
audio_callback_fn callback_fn,
|
2008-12-04 01:48:44 +03:00
|
|
|
struct audsettings *settings
|
2005-10-30 21:58:22 +03:00
|
|
|
);
|
2005-11-05 21:55:28 +03:00
|
|
|
|
|
|
|
void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
|
2019-08-19 02:06:58 +03:00
|
|
|
size_t AUD_write (SWVoiceOut *sw, void *pcm_buf, size_t size);
|
2005-11-05 21:55:28 +03:00
|
|
|
int AUD_get_buffer_size_out (SWVoiceOut *sw);
|
|
|
|
void AUD_set_active_out (SWVoiceOut *sw, int on);
|
|
|
|
int AUD_is_active_out (SWVoiceOut *sw);
|
|
|
|
|
|
|
|
void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
|
|
|
|
uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
|
|
|
|
|
2008-05-04 14:21:03 +04:00
|
|
|
void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol);
|
|
|
|
void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol);
|
|
|
|
|
2019-10-13 22:58:01 +03:00
|
|
|
#define AUDIO_MAX_CHANNELS 16
|
|
|
|
typedef struct Volume {
|
|
|
|
bool mute;
|
|
|
|
int channels;
|
|
|
|
uint8_t vol[AUDIO_MAX_CHANNELS];
|
|
|
|
} Volume;
|
|
|
|
|
|
|
|
void audio_set_volume_out(SWVoiceOut *sw, Volume *vol);
|
|
|
|
void audio_set_volume_in(SWVoiceIn *sw, Volume *vol);
|
|
|
|
|
2005-11-05 21:55:28 +03:00
|
|
|
SWVoiceIn *AUD_open_in (
|
|
|
|
QEMUSoundCard *card,
|
2005-10-30 21:58:22 +03:00
|
|
|
SWVoiceIn *sw,
|
|
|
|
const char *name,
|
|
|
|
void *callback_opaque,
|
2009-10-15 02:40:17 +04:00
|
|
|
audio_callback_fn callback_fn,
|
2008-12-04 01:48:44 +03:00
|
|
|
struct audsettings *settings
|
2005-10-30 21:58:22 +03:00
|
|
|
);
|
2005-11-05 21:55:28 +03:00
|
|
|
|
|
|
|
void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
|
2019-08-19 02:06:58 +03:00
|
|
|
size_t AUD_read (SWVoiceIn *sw, void *pcm_buf, size_t size);
|
2005-11-05 21:55:28 +03:00
|
|
|
void AUD_set_active_in (SWVoiceIn *sw, int on);
|
|
|
|
int AUD_is_active_in (SWVoiceIn *sw);
|
|
|
|
|
|
|
|
void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
|
|
|
|
uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
|
2004-11-07 21:04:02 +03:00
|
|
|
|
|
|
|
static inline void *advance (void *p, int incr)
|
|
|
|
{
|
|
|
|
uint8_t *d = p;
|
|
|
|
return (d + incr);
|
|
|
|
}
|
|
|
|
|
2019-08-19 02:06:47 +03:00
|
|
|
int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
|
|
|
|
int freq, int bits, int nchannels);
|
2008-10-05 14:30:43 +04:00
|
|
|
|
2016-08-01 14:23:43 +03:00
|
|
|
void audio_cleanup(void);
|
|
|
|
|
2020-05-05 16:25:57 +03:00
|
|
|
void audio_sample_to_uint64(const void *samples, int pos,
|
2017-02-02 08:50:54 +03:00
|
|
|
uint64_t *left, uint64_t *right);
|
|
|
|
void audio_sample_from_uint64(void *samples, int pos,
|
|
|
|
uint64_t left, uint64_t right);
|
|
|
|
|
2019-03-09 01:34:15 +03:00
|
|
|
void audio_parse_option(const char *opt);
|
|
|
|
void audio_init_audiodevs(void);
|
|
|
|
void audio_legacy_help(void);
|
|
|
|
|
2019-08-19 02:06:47 +03:00
|
|
|
AudioState *audio_state_by_name(const char *name);
|
|
|
|
const char *audio_get_id(QEMUSoundCard *card);
|
|
|
|
|
2019-08-19 02:06:49 +03:00
|
|
|
#define DEFINE_AUDIO_PROPERTIES(_s, _f) \
|
|
|
|
DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
|
|
|
|
|
2016-06-29 16:29:06 +03:00
|
|
|
#endif /* QEMU_AUDIO_H */
|