2004-11-08 02:04:02 +08:00
|
|
|
/*
|
|
|
|
* QEMU Audio subsystem header
|
2005-10-31 02:58:22 +08:00
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2005 Vassili Karpov (malc)
|
|
|
|
*
|
2004-11-08 02:04:02 +08: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 21:29:06 +08:00
|
|
|
|
2004-11-08 02:04:02 +08:00
|
|
|
#ifndef QEMU_AUDIO_H
|
|
|
|
#define QEMU_AUDIO_H
|
|
|
|
|
2012-12-18 01:20:00 +08:00
|
|
|
#include "qemu/queue.h"
|
2005-11-06 02:55:28 +08:00
|
|
|
|
2009-10-15 06:40:17 +08:00
|
|
|
typedef void (*audio_callback_fn) (void *opaque, int avail);
|
2004-11-08 02:04:02 +08:00
|
|
|
|
|
|
|
typedef enum {
|
2005-11-06 02:55:28 +08:00
|
|
|
AUD_FMT_U8,
|
|
|
|
AUD_FMT_S8,
|
|
|
|
AUD_FMT_U16,
|
2007-02-18 06:19:29 +08:00
|
|
|
AUD_FMT_S16,
|
|
|
|
AUD_FMT_U32,
|
|
|
|
AUD_FMT_S32
|
2004-11-08 02:04:02 +08:00
|
|
|
} audfmt_e;
|
|
|
|
|
2009-07-27 22:13:06 +08:00
|
|
|
#ifdef HOST_WORDS_BIGENDIAN
|
2006-07-05 05:47:22 +08:00
|
|
|
#define AUDIO_HOST_ENDIANNESS 1
|
|
|
|
#else
|
|
|
|
#define AUDIO_HOST_ENDIANNESS 0
|
|
|
|
#endif
|
|
|
|
|
2008-12-04 06:48:44 +08:00
|
|
|
struct audsettings {
|
2005-11-06 02:55:28 +08:00
|
|
|
int freq;
|
|
|
|
int nchannels;
|
|
|
|
audfmt_e fmt;
|
2006-07-05 05:47:22 +08:00
|
|
|
int endianness;
|
2008-12-04 06:48:44 +08:00
|
|
|
};
|
2005-11-06 02:55:28 +08:00
|
|
|
|
2006-07-17 02:57:03 +08:00
|
|
|
typedef enum {
|
|
|
|
AUD_CNOTIFY_ENABLE,
|
|
|
|
AUD_CNOTIFY_DISABLE
|
|
|
|
} audcnotification_e;
|
|
|
|
|
2006-07-05 00:51:32 +08:00
|
|
|
struct audio_capture_ops {
|
2006-07-17 02:57:03 +08:00
|
|
|
void (*notify) (void *opaque, audcnotification_e cmd);
|
2006-07-05 00:51:32 +08:00
|
|
|
void (*capture) (void *opaque, void *buf, int size);
|
2006-07-17 02:57:03 +08:00
|
|
|
void (*destroy) (void *opaque);
|
2006-07-05 00:51:32 +08:00
|
|
|
};
|
|
|
|
|
2006-07-17 02:57:03 +08:00
|
|
|
struct capture_ops {
|
|
|
|
void (*info) (void *opaque);
|
|
|
|
void (*destroy) (void *opaque);
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct CaptureState {
|
|
|
|
void *opaque;
|
|
|
|
struct capture_ops ops;
|
2009-09-12 15:36:22 +08:00
|
|
|
QLIST_ENTRY (CaptureState) entries;
|
2006-07-17 02:57:03 +08:00
|
|
|
} CaptureState;
|
|
|
|
|
2005-10-31 02:58:22 +08:00
|
|
|
typedef struct SWVoiceOut SWVoiceOut;
|
2006-07-17 02:57:03 +08:00
|
|
|
typedef struct CaptureVoiceOut CaptureVoiceOut;
|
2005-10-31 02:58:22 +08:00
|
|
|
typedef struct SWVoiceIn SWVoiceIn;
|
|
|
|
|
2005-11-06 02:55:28 +08:00
|
|
|
typedef struct QEMUSoundCard {
|
|
|
|
char *name;
|
2009-09-12 15:36:22 +08:00
|
|
|
QLIST_ENTRY (QEMUSoundCard) entries;
|
2005-11-06 02:55:28 +08:00
|
|
|
} QEMUSoundCard;
|
|
|
|
|
2005-10-31 02:58:22 +08:00
|
|
|
typedef struct QEMUAudioTimeStamp {
|
|
|
|
uint64_t old_ts;
|
|
|
|
} QEMUAudioTimeStamp;
|
|
|
|
|
2010-09-24 03:28:05 +08:00
|
|
|
void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
|
2010-09-24 03:28:03 +08:00
|
|
|
void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
|
2004-11-08 02:04:02 +08:00
|
|
|
|
2005-10-31 02:58:22 +08:00
|
|
|
void AUD_help (void);
|
2009-05-14 07:11:35 +08:00
|
|
|
void AUD_register_card (const char *name, QEMUSoundCard *card);
|
2005-11-06 02:55:28 +08:00
|
|
|
void AUD_remove_card (QEMUSoundCard *card);
|
2006-07-17 02:57:03 +08:00
|
|
|
CaptureVoiceOut *AUD_add_capture (
|
2008-12-04 06:48:44 +08:00
|
|
|
struct audsettings *as,
|
2006-07-05 00:51:32 +08:00
|
|
|
struct audio_capture_ops *ops,
|
|
|
|
void *opaque
|
|
|
|
);
|
2006-07-17 02:57:03 +08:00
|
|
|
void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
|
2005-10-31 02:58:22 +08:00
|
|
|
|
2005-11-06 02:55:28 +08:00
|
|
|
SWVoiceOut *AUD_open_out (
|
|
|
|
QEMUSoundCard *card,
|
2005-10-31 02:58:22 +08:00
|
|
|
SWVoiceOut *sw,
|
|
|
|
const char *name,
|
|
|
|
void *callback_opaque,
|
2009-10-15 06:40:17 +08:00
|
|
|
audio_callback_fn callback_fn,
|
2008-12-04 06:48:44 +08:00
|
|
|
struct audsettings *settings
|
2005-10-31 02:58:22 +08:00
|
|
|
);
|
2005-11-06 02:55:28 +08:00
|
|
|
|
|
|
|
void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
|
|
|
|
int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
|
|
|
|
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 18:21:03 +08: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);
|
|
|
|
|
2005-11-06 02:55:28 +08:00
|
|
|
SWVoiceIn *AUD_open_in (
|
|
|
|
QEMUSoundCard *card,
|
2005-10-31 02:58:22 +08:00
|
|
|
SWVoiceIn *sw,
|
|
|
|
const char *name,
|
|
|
|
void *callback_opaque,
|
2009-10-15 06:40:17 +08:00
|
|
|
audio_callback_fn callback_fn,
|
2008-12-04 06:48:44 +08:00
|
|
|
struct audsettings *settings
|
2005-10-31 02:58:22 +08:00
|
|
|
);
|
2005-11-06 02:55:28 +08:00
|
|
|
|
|
|
|
void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
|
|
|
|
int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
|
|
|
|
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-08 02:04:02 +08:00
|
|
|
|
|
|
|
static inline void *advance (void *p, int incr)
|
|
|
|
{
|
|
|
|
uint8_t *d = p;
|
|
|
|
return (d + incr);
|
|
|
|
}
|
|
|
|
|
2005-10-31 02:58:22 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define audio_MIN(a, b) ( __extension__ ({ \
|
|
|
|
__typeof (a) ta = a; \
|
|
|
|
__typeof (b) tb = b; \
|
|
|
|
((ta)>(tb)?(tb):(ta)); \
|
|
|
|
}))
|
|
|
|
|
|
|
|
#define audio_MAX(a, b) ( __extension__ ({ \
|
|
|
|
__typeof (a) ta = a; \
|
|
|
|
__typeof (b) tb = b; \
|
|
|
|
((ta)<(tb)?(tb):(ta)); \
|
|
|
|
}))
|
|
|
|
#else
|
2004-11-08 02:04:02 +08:00
|
|
|
#define audio_MIN(a, b) ((a)>(b)?(b):(a))
|
|
|
|
#define audio_MAX(a, b) ((a)<(b)?(b):(a))
|
2005-10-31 02:58:22 +08:00
|
|
|
#endif
|
2004-11-08 02:04:02 +08:00
|
|
|
|
2008-10-05 18:30:43 +08:00
|
|
|
int wav_start_capture (CaptureState *s, const char *path, int freq,
|
|
|
|
int bits, int nchannels);
|
|
|
|
|
2016-08-01 19:23:43 +08:00
|
|
|
bool audio_is_cleaning_up(void);
|
|
|
|
void audio_cleanup(void);
|
|
|
|
|
2017-02-02 13:50:54 +08:00
|
|
|
void audio_sample_to_uint64(void *samples, int pos,
|
|
|
|
uint64_t *left, uint64_t *right);
|
|
|
|
void audio_sample_from_uint64(void *samples, int pos,
|
|
|
|
uint64_t left, uint64_t right);
|
|
|
|
|
2016-06-29 21:29:06 +08:00
|
|
|
#endif /* QEMU_AUDIO_H */
|