Statistics
| Branch: | Revision:

root / audio / audio.h @ cbeb0857

History | View | Annotate | Download (4.8 kB)

1 85571bc7 bellard
/*
2 85571bc7 bellard
 * QEMU Audio subsystem header
3 1d14ffa9 bellard
 *
4 1d14ffa9 bellard
 * Copyright (c) 2003-2005 Vassili Karpov (malc)
5 1d14ffa9 bellard
 *
6 85571bc7 bellard
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 85571bc7 bellard
 * of this software and associated documentation files (the "Software"), to deal
8 85571bc7 bellard
 * in the Software without restriction, including without limitation the rights
9 85571bc7 bellard
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 85571bc7 bellard
 * copies of the Software, and to permit persons to whom the Software is
11 85571bc7 bellard
 * furnished to do so, subject to the following conditions:
12 85571bc7 bellard
 *
13 85571bc7 bellard
 * The above copyright notice and this permission notice shall be included in
14 85571bc7 bellard
 * all copies or substantial portions of the Software.
15 85571bc7 bellard
 *
16 85571bc7 bellard
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 85571bc7 bellard
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 85571bc7 bellard
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 85571bc7 bellard
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 85571bc7 bellard
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 85571bc7 bellard
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 85571bc7 bellard
 * THE SOFTWARE.
23 85571bc7 bellard
 */
24 85571bc7 bellard
#ifndef QEMU_AUDIO_H
25 85571bc7 bellard
#define QEMU_AUDIO_H
26 85571bc7 bellard
27 d929eba5 bellard
#include "config.h"
28 c0fe3827 bellard
#include "sys-queue.h"
29 c0fe3827 bellard
30 1d14ffa9 bellard
typedef void (*audio_callback_fn_t) (void *opaque, int avail);
31 85571bc7 bellard
32 85571bc7 bellard
typedef enum {
33 c0fe3827 bellard
    AUD_FMT_U8,
34 c0fe3827 bellard
    AUD_FMT_S8,
35 c0fe3827 bellard
    AUD_FMT_U16,
36 f941aa25 ths
    AUD_FMT_S16,
37 f941aa25 ths
    AUD_FMT_U32,
38 f941aa25 ths
    AUD_FMT_S32
39 85571bc7 bellard
} audfmt_e;
40 85571bc7 bellard
41 d929eba5 bellard
#ifdef WORDS_BIGENDIAN
42 d929eba5 bellard
#define AUDIO_HOST_ENDIANNESS 1
43 d929eba5 bellard
#else
44 d929eba5 bellard
#define AUDIO_HOST_ENDIANNESS 0
45 d929eba5 bellard
#endif
46 d929eba5 bellard
47 c0fe3827 bellard
typedef struct {
48 c0fe3827 bellard
    int freq;
49 c0fe3827 bellard
    int nchannels;
50 c0fe3827 bellard
    audfmt_e fmt;
51 d929eba5 bellard
    int endianness;
52 c0fe3827 bellard
} audsettings_t;
53 c0fe3827 bellard
54 ec36b695 bellard
typedef enum {
55 ec36b695 bellard
    AUD_CNOTIFY_ENABLE,
56 ec36b695 bellard
    AUD_CNOTIFY_DISABLE
57 ec36b695 bellard
} audcnotification_e;
58 ec36b695 bellard
59 8ead62cf bellard
struct audio_capture_ops {
60 ec36b695 bellard
    void (*notify) (void *opaque, audcnotification_e cmd);
61 8ead62cf bellard
    void (*capture) (void *opaque, void *buf, int size);
62 ec36b695 bellard
    void (*destroy) (void *opaque);
63 8ead62cf bellard
};
64 8ead62cf bellard
65 ec36b695 bellard
struct capture_ops {
66 ec36b695 bellard
    void (*info) (void *opaque);
67 ec36b695 bellard
    void (*destroy) (void *opaque);
68 ec36b695 bellard
};
69 ec36b695 bellard
70 ec36b695 bellard
typedef struct CaptureState {
71 ec36b695 bellard
    void *opaque;
72 ec36b695 bellard
    struct capture_ops ops;
73 ec36b695 bellard
    LIST_ENTRY (CaptureState) entries;
74 ec36b695 bellard
} CaptureState;
75 ec36b695 bellard
76 c0fe3827 bellard
typedef struct AudioState AudioState;
77 1d14ffa9 bellard
typedef struct SWVoiceOut SWVoiceOut;
78 ec36b695 bellard
typedef struct CaptureVoiceOut CaptureVoiceOut;
79 1d14ffa9 bellard
typedef struct SWVoiceIn SWVoiceIn;
80 1d14ffa9 bellard
81 c0fe3827 bellard
typedef struct QEMUSoundCard {
82 c0fe3827 bellard
    AudioState *audio;
83 c0fe3827 bellard
    char *name;
84 c0fe3827 bellard
    LIST_ENTRY (QEMUSoundCard) entries;
85 c0fe3827 bellard
} QEMUSoundCard;
86 c0fe3827 bellard
87 1d14ffa9 bellard
typedef struct QEMUAudioTimeStamp {
88 1d14ffa9 bellard
    uint64_t old_ts;
89 1d14ffa9 bellard
} QEMUAudioTimeStamp;
90 1d14ffa9 bellard
91 1d14ffa9 bellard
void AUD_vlog (const char *cap, const char *fmt, va_list ap);
92 1d14ffa9 bellard
void AUD_log (const char *cap, const char *fmt, ...)
93 1d14ffa9 bellard
#ifdef __GNUC__
94 1d14ffa9 bellard
    __attribute__ ((__format__ (__printf__, 2, 3)))
95 1d14ffa9 bellard
#endif
96 1d14ffa9 bellard
    ;
97 85571bc7 bellard
98 c0fe3827 bellard
AudioState *AUD_init (void);
99 1d14ffa9 bellard
void AUD_help (void);
100 c0fe3827 bellard
void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card);
101 c0fe3827 bellard
void AUD_remove_card (QEMUSoundCard *card);
102 ec36b695 bellard
CaptureVoiceOut *AUD_add_capture (
103 8ead62cf bellard
    AudioState *s,
104 8ead62cf bellard
    audsettings_t *as,
105 8ead62cf bellard
    struct audio_capture_ops *ops,
106 8ead62cf bellard
    void *opaque
107 8ead62cf bellard
    );
108 ec36b695 bellard
void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
109 1d14ffa9 bellard
110 c0fe3827 bellard
SWVoiceOut *AUD_open_out (
111 c0fe3827 bellard
    QEMUSoundCard *card,
112 1d14ffa9 bellard
    SWVoiceOut *sw,
113 1d14ffa9 bellard
    const char *name,
114 1d14ffa9 bellard
    void *callback_opaque,
115 1d14ffa9 bellard
    audio_callback_fn_t callback_fn,
116 d929eba5 bellard
    audsettings_t *settings
117 1d14ffa9 bellard
    );
118 c0fe3827 bellard
119 c0fe3827 bellard
void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
120 c0fe3827 bellard
int  AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
121 c0fe3827 bellard
int  AUD_get_buffer_size_out (SWVoiceOut *sw);
122 c0fe3827 bellard
void AUD_set_active_out (SWVoiceOut *sw, int on);
123 c0fe3827 bellard
int  AUD_is_active_out (SWVoiceOut *sw);
124 c0fe3827 bellard
125 c0fe3827 bellard
void     AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
126 c0fe3827 bellard
uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
127 c0fe3827 bellard
128 c0fe3827 bellard
SWVoiceIn *AUD_open_in (
129 c0fe3827 bellard
    QEMUSoundCard *card,
130 1d14ffa9 bellard
    SWVoiceIn *sw,
131 1d14ffa9 bellard
    const char *name,
132 1d14ffa9 bellard
    void *callback_opaque,
133 1d14ffa9 bellard
    audio_callback_fn_t callback_fn,
134 d929eba5 bellard
    audsettings_t *settings
135 1d14ffa9 bellard
    );
136 c0fe3827 bellard
137 c0fe3827 bellard
void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
138 c0fe3827 bellard
int  AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
139 c0fe3827 bellard
void AUD_set_active_in (SWVoiceIn *sw, int on);
140 c0fe3827 bellard
int  AUD_is_active_in (SWVoiceIn *sw);
141 c0fe3827 bellard
142 c0fe3827 bellard
void     AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
143 c0fe3827 bellard
uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
144 85571bc7 bellard
145 85571bc7 bellard
static inline void *advance (void *p, int incr)
146 85571bc7 bellard
{
147 85571bc7 bellard
    uint8_t *d = p;
148 85571bc7 bellard
    return (d + incr);
149 85571bc7 bellard
}
150 85571bc7 bellard
151 85571bc7 bellard
uint32_t popcount (uint32_t u);
152 8ead62cf bellard
uint32_t lsbindex (uint32_t u);
153 85571bc7 bellard
154 1d14ffa9 bellard
#ifdef __GNUC__
155 1d14ffa9 bellard
#define audio_MIN(a, b) ( __extension__ ({      \
156 1d14ffa9 bellard
    __typeof (a) ta = a;                        \
157 1d14ffa9 bellard
    __typeof (b) tb = b;                        \
158 1d14ffa9 bellard
    ((ta)>(tb)?(tb):(ta));                      \
159 1d14ffa9 bellard
}))
160 1d14ffa9 bellard
161 1d14ffa9 bellard
#define audio_MAX(a, b) ( __extension__ ({      \
162 1d14ffa9 bellard
    __typeof (a) ta = a;                        \
163 1d14ffa9 bellard
    __typeof (b) tb = b;                        \
164 1d14ffa9 bellard
    ((ta)<(tb)?(tb):(ta));                      \
165 1d14ffa9 bellard
}))
166 1d14ffa9 bellard
#else
167 85571bc7 bellard
#define audio_MIN(a, b) ((a)>(b)?(b):(a))
168 85571bc7 bellard
#define audio_MAX(a, b) ((a)<(b)?(b):(a))
169 1d14ffa9 bellard
#endif
170 85571bc7 bellard
171 85571bc7 bellard
#endif  /* audio.h */