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