Statistics
| Branch: | Revision:

root / audio / audio.h @ 8b7968f7

History | View | Annotate | Download (4.9 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 5fa0ab8f bellard
#include "config-host.h"
28 72cf2d4f Blue Swirl
#include "qemu-queue.h"
29 c0fe3827 bellard
30 cb4f03e8 malc
typedef void (*audio_callback_fn) (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 e2542fe2 Juan Quintela
#ifdef HOST_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 1ea879e5 malc
struct audsettings {
48 c0fe3827 bellard
    int freq;
49 c0fe3827 bellard
    int nchannels;
50 c0fe3827 bellard
    audfmt_e fmt;
51 d929eba5 bellard
    int endianness;
52 1ea879e5 malc
};
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 72cf2d4f Blue Swirl
    QLIST_ENTRY (CaptureState) entries;
74 ec36b695 bellard
} CaptureState;
75 ec36b695 bellard
76 1d14ffa9 bellard
typedef struct SWVoiceOut SWVoiceOut;
77 ec36b695 bellard
typedef struct CaptureVoiceOut CaptureVoiceOut;
78 1d14ffa9 bellard
typedef struct SWVoiceIn SWVoiceIn;
79 1d14ffa9 bellard
80 c0fe3827 bellard
typedef struct QEMUSoundCard {
81 c0fe3827 bellard
    char *name;
82 72cf2d4f Blue Swirl
    QLIST_ENTRY (QEMUSoundCard) entries;
83 c0fe3827 bellard
} QEMUSoundCard;
84 c0fe3827 bellard
85 1d14ffa9 bellard
typedef struct QEMUAudioTimeStamp {
86 1d14ffa9 bellard
    uint64_t old_ts;
87 1d14ffa9 bellard
} QEMUAudioTimeStamp;
88 1d14ffa9 bellard
89 8b7968f7 Stefan Weil
void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
90 e5924d89 Stefan Weil
void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
91 85571bc7 bellard
92 1d14ffa9 bellard
void AUD_help (void);
93 1a7dafce malc
void AUD_register_card (const char *name, QEMUSoundCard *card);
94 c0fe3827 bellard
void AUD_remove_card (QEMUSoundCard *card);
95 ec36b695 bellard
CaptureVoiceOut *AUD_add_capture (
96 1ea879e5 malc
    struct audsettings *as,
97 8ead62cf bellard
    struct audio_capture_ops *ops,
98 8ead62cf bellard
    void *opaque
99 8ead62cf bellard
    );
100 ec36b695 bellard
void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
101 1d14ffa9 bellard
102 c0fe3827 bellard
SWVoiceOut *AUD_open_out (
103 c0fe3827 bellard
    QEMUSoundCard *card,
104 1d14ffa9 bellard
    SWVoiceOut *sw,
105 1d14ffa9 bellard
    const char *name,
106 1d14ffa9 bellard
    void *callback_opaque,
107 cb4f03e8 malc
    audio_callback_fn callback_fn,
108 1ea879e5 malc
    struct audsettings *settings
109 1d14ffa9 bellard
    );
110 c0fe3827 bellard
111 c0fe3827 bellard
void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
112 c0fe3827 bellard
int  AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
113 c0fe3827 bellard
int  AUD_get_buffer_size_out (SWVoiceOut *sw);
114 c0fe3827 bellard
void AUD_set_active_out (SWVoiceOut *sw, int on);
115 c0fe3827 bellard
int  AUD_is_active_out (SWVoiceOut *sw);
116 c0fe3827 bellard
117 c0fe3827 bellard
void     AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
118 c0fe3827 bellard
uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
119 c0fe3827 bellard
120 683efdcb balrog
void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol);
121 683efdcb balrog
void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol);
122 683efdcb balrog
123 c0fe3827 bellard
SWVoiceIn *AUD_open_in (
124 c0fe3827 bellard
    QEMUSoundCard *card,
125 1d14ffa9 bellard
    SWVoiceIn *sw,
126 1d14ffa9 bellard
    const char *name,
127 1d14ffa9 bellard
    void *callback_opaque,
128 cb4f03e8 malc
    audio_callback_fn callback_fn,
129 1ea879e5 malc
    struct audsettings *settings
130 1d14ffa9 bellard
    );
131 c0fe3827 bellard
132 c0fe3827 bellard
void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
133 c0fe3827 bellard
int  AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
134 c0fe3827 bellard
void AUD_set_active_in (SWVoiceIn *sw, int on);
135 c0fe3827 bellard
int  AUD_is_active_in (SWVoiceIn *sw);
136 c0fe3827 bellard
137 c0fe3827 bellard
void     AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
138 c0fe3827 bellard
uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
139 85571bc7 bellard
140 85571bc7 bellard
static inline void *advance (void *p, int incr)
141 85571bc7 bellard
{
142 85571bc7 bellard
    uint8_t *d = p;
143 85571bc7 bellard
    return (d + incr);
144 85571bc7 bellard
}
145 85571bc7 bellard
146 1d14ffa9 bellard
#ifdef __GNUC__
147 1d14ffa9 bellard
#define audio_MIN(a, b) ( __extension__ ({      \
148 1d14ffa9 bellard
    __typeof (a) ta = a;                        \
149 1d14ffa9 bellard
    __typeof (b) tb = b;                        \
150 1d14ffa9 bellard
    ((ta)>(tb)?(tb):(ta));                      \
151 1d14ffa9 bellard
}))
152 1d14ffa9 bellard
153 1d14ffa9 bellard
#define audio_MAX(a, b) ( __extension__ ({      \
154 1d14ffa9 bellard
    __typeof (a) ta = a;                        \
155 1d14ffa9 bellard
    __typeof (b) tb = b;                        \
156 1d14ffa9 bellard
    ((ta)<(tb)?(tb):(ta));                      \
157 1d14ffa9 bellard
}))
158 1d14ffa9 bellard
#else
159 85571bc7 bellard
#define audio_MIN(a, b) ((a)>(b)?(b):(a))
160 85571bc7 bellard
#define audio_MAX(a, b) ((a)<(b)?(b):(a))
161 1d14ffa9 bellard
#endif
162 85571bc7 bellard
163 295e390f blueswir1
int wav_start_capture (CaptureState *s, const char *path, int freq,
164 295e390f blueswir1
                       int bits, int nchannels);
165 295e390f blueswir1
166 85571bc7 bellard
#endif  /* audio.h */