audio.h 4.9 KB
Newer Older
B
bellard 已提交
1 2
/*
 * QEMU Audio subsystem header
3 4 5
 *
 * Copyright (c) 2003-2005 Vassili Karpov (malc)
 *
B
bellard 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 * 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.
 */
#ifndef QEMU_AUDIO_H
#define QEMU_AUDIO_H

B
bellard 已提交
27
#include "config-host.h"
B
Blue Swirl 已提交
28
#include "qemu-queue.h"
B
bellard 已提交
29

M
malc 已提交
30
typedef void (*audio_callback_fn) (void *opaque, int avail);
B
bellard 已提交
31 32

typedef enum {
B
bellard 已提交
33 34 35
    AUD_FMT_U8,
    AUD_FMT_S8,
    AUD_FMT_U16,
36 37 38
    AUD_FMT_S16,
    AUD_FMT_U32,
    AUD_FMT_S32
B
bellard 已提交
39 40
} audfmt_e;

41
#ifdef HOST_WORDS_BIGENDIAN
B
bellard 已提交
42 43 44 45 46
#define AUDIO_HOST_ENDIANNESS 1
#else
#define AUDIO_HOST_ENDIANNESS 0
#endif

M
malc 已提交
47
struct audsettings {
B
bellard 已提交
48 49 50
    int freq;
    int nchannels;
    audfmt_e fmt;
B
bellard 已提交
51
    int endianness;
M
malc 已提交
52
};
B
bellard 已提交
53

B
bellard 已提交
54 55 56 57 58
typedef enum {
    AUD_CNOTIFY_ENABLE,
    AUD_CNOTIFY_DISABLE
} audcnotification_e;

59
struct audio_capture_ops {
B
bellard 已提交
60
    void (*notify) (void *opaque, audcnotification_e cmd);
61
    void (*capture) (void *opaque, void *buf, int size);
B
bellard 已提交
62
    void (*destroy) (void *opaque);
63 64
};

B
bellard 已提交
65 66 67 68 69 70 71 72
struct capture_ops {
    void (*info) (void *opaque);
    void (*destroy) (void *opaque);
};

typedef struct CaptureState {
    void *opaque;
    struct capture_ops ops;
B
Blue Swirl 已提交
73
    QLIST_ENTRY (CaptureState) entries;
B
bellard 已提交
74 75
} CaptureState;

76
typedef struct SWVoiceOut SWVoiceOut;
B
bellard 已提交
77
typedef struct CaptureVoiceOut CaptureVoiceOut;
78 79
typedef struct SWVoiceIn SWVoiceIn;

B
bellard 已提交
80 81
typedef struct QEMUSoundCard {
    char *name;
B
Blue Swirl 已提交
82
    QLIST_ENTRY (QEMUSoundCard) entries;
B
bellard 已提交
83 84
} QEMUSoundCard;

85 86 87 88 89 90 91 92 93 94
typedef struct QEMUAudioTimeStamp {
    uint64_t old_ts;
} QEMUAudioTimeStamp;

void AUD_vlog (const char *cap, const char *fmt, va_list ap);
void AUD_log (const char *cap, const char *fmt, ...)
#ifdef __GNUC__
    __attribute__ ((__format__ (__printf__, 2, 3)))
#endif
    ;
B
bellard 已提交
95

96
void AUD_help (void);
97
void AUD_register_card (const char *name, QEMUSoundCard *card);
B
bellard 已提交
98
void AUD_remove_card (QEMUSoundCard *card);
B
bellard 已提交
99
CaptureVoiceOut *AUD_add_capture (
M
malc 已提交
100
    struct audsettings *as,
101 102 103
    struct audio_capture_ops *ops,
    void *opaque
    );
B
bellard 已提交
104
void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
105

B
bellard 已提交
106 107
SWVoiceOut *AUD_open_out (
    QEMUSoundCard *card,
108 109 110
    SWVoiceOut *sw,
    const char *name,
    void *callback_opaque,
M
malc 已提交
111
    audio_callback_fn callback_fn,
M
malc 已提交
112
    struct audsettings *settings
113
    );
B
bellard 已提交
114 115 116 117 118 119 120 121 122 123

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);

124 125 126
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);

B
bellard 已提交
127 128
SWVoiceIn *AUD_open_in (
    QEMUSoundCard *card,
129 130 131
    SWVoiceIn *sw,
    const char *name,
    void *callback_opaque,
M
malc 已提交
132
    audio_callback_fn callback_fn,
M
malc 已提交
133
    struct audsettings *settings
134
    );
B
bellard 已提交
135 136 137 138 139 140 141 142

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);
B
bellard 已提交
143 144 145 146 147 148 149

static inline void *advance (void *p, int incr)
{
    uint8_t *d = p;
    return (d + incr);
}

150 151 152 153 154 155 156 157 158 159 160 161 162
#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
B
bellard 已提交
163 164
#define audio_MIN(a, b) ((a)>(b)?(b):(a))
#define audio_MAX(a, b) ((a)<(b)?(b):(a))
165
#endif
B
bellard 已提交
166

167 168 169
int wav_start_capture (CaptureState *s, const char *path, int freq,
                       int bits, int nchannels);

B
bellard 已提交
170
#endif  /* audio.h */