qemu/audio/audio.h
<<
>>
Prefs
   1/*
   2 * QEMU Audio subsystem header
   3 *
   4 * Copyright (c) 2003-2005 Vassili Karpov (malc)
   5 *
   6 * 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
  27#include "qemu/queue.h"
  28
  29typedef void (*audio_callback_fn) (void *opaque, int avail);
  30
  31typedef enum {
  32    AUD_FMT_U8,
  33    AUD_FMT_S8,
  34    AUD_FMT_U16,
  35    AUD_FMT_S16,
  36    AUD_FMT_U32,
  37    AUD_FMT_S32
  38} audfmt_e;
  39
  40#ifdef HOST_WORDS_BIGENDIAN
  41#define AUDIO_HOST_ENDIANNESS 1
  42#else
  43#define AUDIO_HOST_ENDIANNESS 0
  44#endif
  45
  46struct audsettings {
  47    int freq;
  48    int nchannels;
  49    audfmt_e fmt;
  50    int endianness;
  51};
  52
  53typedef enum {
  54    AUD_CNOTIFY_ENABLE,
  55    AUD_CNOTIFY_DISABLE
  56} audcnotification_e;
  57
  58struct audio_capture_ops {
  59    void (*notify) (void *opaque, audcnotification_e cmd);
  60    void (*capture) (void *opaque, void *buf, int size);
  61    void (*destroy) (void *opaque);
  62};
  63
  64struct capture_ops {
  65    void (*info) (void *opaque);
  66    void (*destroy) (void *opaque);
  67};
  68
  69typedef struct CaptureState {
  70    void *opaque;
  71    struct capture_ops ops;
  72    QLIST_ENTRY (CaptureState) entries;
  73} CaptureState;
  74
  75typedef struct SWVoiceOut SWVoiceOut;
  76typedef struct CaptureVoiceOut CaptureVoiceOut;
  77typedef struct SWVoiceIn SWVoiceIn;
  78
  79typedef struct QEMUSoundCard {
  80    char *name;
  81    QLIST_ENTRY (QEMUSoundCard) entries;
  82} QEMUSoundCard;
  83
  84typedef struct QEMUAudioTimeStamp {
  85    uint64_t old_ts;
  86} QEMUAudioTimeStamp;
  87
  88void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
  89void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
  90
  91void AUD_help (void);
  92void AUD_register_card (const char *name, QEMUSoundCard *card);
  93void AUD_remove_card (QEMUSoundCard *card);
  94CaptureVoiceOut *AUD_add_capture (
  95    struct audsettings *as,
  96    struct audio_capture_ops *ops,
  97    void *opaque
  98    );
  99void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
 100
 101SWVoiceOut *AUD_open_out (
 102    QEMUSoundCard *card,
 103    SWVoiceOut *sw,
 104    const char *name,
 105    void *callback_opaque,
 106    audio_callback_fn callback_fn,
 107    struct audsettings *settings
 108    );
 109
 110void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
 111int  AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
 112int  AUD_get_buffer_size_out (SWVoiceOut *sw);
 113void AUD_set_active_out (SWVoiceOut *sw, int on);
 114int  AUD_is_active_out (SWVoiceOut *sw);
 115
 116void     AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
 117uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
 118
 119void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol);
 120void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol);
 121
 122SWVoiceIn *AUD_open_in (
 123    QEMUSoundCard *card,
 124    SWVoiceIn *sw,
 125    const char *name,
 126    void *callback_opaque,
 127    audio_callback_fn callback_fn,
 128    struct audsettings *settings
 129    );
 130
 131void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
 132int  AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
 133void AUD_set_active_in (SWVoiceIn *sw, int on);
 134int  AUD_is_active_in (SWVoiceIn *sw);
 135
 136void     AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
 137uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
 138
 139static inline void *advance (void *p, int incr)
 140{
 141    uint8_t *d = p;
 142    return (d + incr);
 143}
 144
 145#ifdef __GNUC__
 146#define audio_MIN(a, b) ( __extension__ ({      \
 147    __typeof (a) ta = a;                        \
 148    __typeof (b) tb = b;                        \
 149    ((ta)>(tb)?(tb):(ta));                      \
 150}))
 151
 152#define audio_MAX(a, b) ( __extension__ ({      \
 153    __typeof (a) ta = a;                        \
 154    __typeof (b) tb = b;                        \
 155    ((ta)<(tb)?(tb):(ta));                      \
 156}))
 157#else
 158#define audio_MIN(a, b) ((a)>(b)?(b):(a))
 159#define audio_MAX(a, b) ((a)<(b)?(b):(a))
 160#endif
 161
 162int wav_start_capture (CaptureState *s, const char *path, int freq,
 163                       int bits, int nchannels);
 164
 165#endif  /* audio.h */
 166