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
  25#ifndef QEMU_AUDIO_H
  26#define QEMU_AUDIO_H
  27
  28#include "qemu/queue.h"
  29#include "qapi/qapi-types-audio.h"
  30#include "hw/qdev-properties.h"
  31#include "hw/qdev-properties-system.h"
  32
  33typedef void (*audio_callback_fn) (void *opaque, int avail);
  34
  35#ifdef HOST_WORDS_BIGENDIAN
  36#define AUDIO_HOST_ENDIANNESS 1
  37#else
  38#define AUDIO_HOST_ENDIANNESS 0
  39#endif
  40
  41typedef struct audsettings {
  42    int freq;
  43    int nchannels;
  44    AudioFormat fmt;
  45    int endianness;
  46} audsettings;
  47
  48audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo);
  49int audioformat_bytes_per_sample(AudioFormat fmt);
  50int audio_buffer_frames(AudiodevPerDirectionOptions *pdo,
  51                        audsettings *as, int def_usecs);
  52int audio_buffer_samples(AudiodevPerDirectionOptions *pdo,
  53                         audsettings *as, int def_usecs);
  54int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
  55                       audsettings *as, int def_usecs);
  56
  57typedef enum {
  58    AUD_CNOTIFY_ENABLE,
  59    AUD_CNOTIFY_DISABLE
  60} audcnotification_e;
  61
  62struct audio_capture_ops {
  63    void (*notify) (void *opaque, audcnotification_e cmd);
  64    void (*capture) (void *opaque, const void *buf, int size);
  65    void (*destroy) (void *opaque);
  66};
  67
  68struct capture_ops {
  69    void (*info) (void *opaque);
  70    void (*destroy) (void *opaque);
  71};
  72
  73typedef struct CaptureState {
  74    void *opaque;
  75    struct capture_ops ops;
  76    QLIST_ENTRY (CaptureState) entries;
  77} CaptureState;
  78
  79typedef struct SWVoiceOut SWVoiceOut;
  80typedef struct CaptureVoiceOut CaptureVoiceOut;
  81typedef struct SWVoiceIn SWVoiceIn;
  82
  83typedef struct AudioState AudioState;
  84typedef struct QEMUSoundCard {
  85    char *name;
  86    AudioState *state;
  87    QLIST_ENTRY (QEMUSoundCard) entries;
  88} QEMUSoundCard;
  89
  90typedef struct QEMUAudioTimeStamp {
  91    uint64_t old_ts;
  92} QEMUAudioTimeStamp;
  93
  94void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
  95void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
  96
  97void AUD_register_card (const char *name, QEMUSoundCard *card);
  98void AUD_remove_card (QEMUSoundCard *card);
  99CaptureVoiceOut *AUD_add_capture(
 100    AudioState *s,
 101    struct audsettings *as,
 102    struct audio_capture_ops *ops,
 103    void *opaque
 104    );
 105void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
 106
 107SWVoiceOut *AUD_open_out (
 108    QEMUSoundCard *card,
 109    SWVoiceOut *sw,
 110    const char *name,
 111    void *callback_opaque,
 112    audio_callback_fn callback_fn,
 113    struct audsettings *settings
 114    );
 115
 116void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
 117size_t AUD_write (SWVoiceOut *sw, void *pcm_buf, size_t size);
 118int  AUD_get_buffer_size_out (SWVoiceOut *sw);
 119void AUD_set_active_out (SWVoiceOut *sw, int on);
 120int  AUD_is_active_out (SWVoiceOut *sw);
 121
 122void     AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
 123uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
 124
 125void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol);
 126void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol);
 127
 128#define AUDIO_MAX_CHANNELS 16
 129typedef struct Volume {
 130    bool mute;
 131    int channels;
 132    uint8_t vol[AUDIO_MAX_CHANNELS];
 133} Volume;
 134
 135void audio_set_volume_out(SWVoiceOut *sw, Volume *vol);
 136void audio_set_volume_in(SWVoiceIn *sw, Volume *vol);
 137
 138SWVoiceIn *AUD_open_in (
 139    QEMUSoundCard *card,
 140    SWVoiceIn *sw,
 141    const char *name,
 142    void *callback_opaque,
 143    audio_callback_fn callback_fn,
 144    struct audsettings *settings
 145    );
 146
 147void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
 148size_t AUD_read (SWVoiceIn *sw, void *pcm_buf, size_t size);
 149void AUD_set_active_in (SWVoiceIn *sw, int on);
 150int  AUD_is_active_in (SWVoiceIn *sw);
 151
 152void     AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
 153uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
 154
 155static inline void *advance (void *p, int incr)
 156{
 157    uint8_t *d = p;
 158    return (d + incr);
 159}
 160
 161int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
 162                      int freq, int bits, int nchannels);
 163
 164void audio_cleanup(void);
 165
 166void audio_sample_to_uint64(const void *samples, int pos,
 167                            uint64_t *left, uint64_t *right);
 168void audio_sample_from_uint64(void *samples, int pos,
 169                            uint64_t left, uint64_t right);
 170
 171void audio_parse_option(const char *opt);
 172void audio_init_audiodevs(void);
 173void audio_legacy_help(void);
 174
 175AudioState *audio_state_by_name(const char *name);
 176const char *audio_get_id(QEMUSoundCard *card);
 177
 178#define DEFINE_AUDIO_PROPERTIES(_s, _f)         \
 179    DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
 180
 181#endif /* QEMU_AUDIO_H */
 182