Statistics
| Branch: | Revision:

root / audio / audio.h @ ecd78a0a

History | View | Annotate | Download (4 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 c0fe3827 bellard
#include "sys-queue.h"
28 c0fe3827 bellard
29 1d14ffa9 bellard
typedef void (*audio_callback_fn_t) (void *opaque, int avail);
30 85571bc7 bellard
31 85571bc7 bellard
typedef enum {
32 c0fe3827 bellard
    AUD_FMT_U8,
33 c0fe3827 bellard
    AUD_FMT_S8,
34 c0fe3827 bellard
    AUD_FMT_U16,
35 c0fe3827 bellard
    AUD_FMT_S16
36 85571bc7 bellard
} audfmt_e;
37 85571bc7 bellard
38 c0fe3827 bellard
typedef struct {
39 c0fe3827 bellard
    int freq;
40 c0fe3827 bellard
    int nchannels;
41 c0fe3827 bellard
    audfmt_e fmt;
42 c0fe3827 bellard
} audsettings_t;
43 c0fe3827 bellard
44 c0fe3827 bellard
typedef struct AudioState AudioState;
45 1d14ffa9 bellard
typedef struct SWVoiceOut SWVoiceOut;
46 1d14ffa9 bellard
typedef struct SWVoiceIn SWVoiceIn;
47 1d14ffa9 bellard
48 c0fe3827 bellard
typedef struct QEMUSoundCard {
49 c0fe3827 bellard
    AudioState *audio;
50 c0fe3827 bellard
    char *name;
51 c0fe3827 bellard
    LIST_ENTRY (QEMUSoundCard) entries;
52 c0fe3827 bellard
} QEMUSoundCard;
53 c0fe3827 bellard
54 1d14ffa9 bellard
typedef struct QEMUAudioTimeStamp {
55 1d14ffa9 bellard
    uint64_t old_ts;
56 1d14ffa9 bellard
} QEMUAudioTimeStamp;
57 1d14ffa9 bellard
58 1d14ffa9 bellard
void AUD_vlog (const char *cap, const char *fmt, va_list ap);
59 1d14ffa9 bellard
void AUD_log (const char *cap, const char *fmt, ...)
60 1d14ffa9 bellard
#ifdef __GNUC__
61 1d14ffa9 bellard
    __attribute__ ((__format__ (__printf__, 2, 3)))
62 1d14ffa9 bellard
#endif
63 1d14ffa9 bellard
    ;
64 85571bc7 bellard
65 c0fe3827 bellard
AudioState *AUD_init (void);
66 1d14ffa9 bellard
void AUD_help (void);
67 c0fe3827 bellard
void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card);
68 c0fe3827 bellard
void AUD_remove_card (QEMUSoundCard *card);
69 1d14ffa9 bellard
70 c0fe3827 bellard
SWVoiceOut *AUD_open_out (
71 c0fe3827 bellard
    QEMUSoundCard *card,
72 1d14ffa9 bellard
    SWVoiceOut *sw,
73 1d14ffa9 bellard
    const char *name,
74 1d14ffa9 bellard
    void *callback_opaque,
75 1d14ffa9 bellard
    audio_callback_fn_t callback_fn,
76 571ec3d6 bellard
    audsettings_t *settings,
77 571ec3d6 bellard
    int sw_endian
78 1d14ffa9 bellard
    );
79 c0fe3827 bellard
80 c0fe3827 bellard
void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
81 c0fe3827 bellard
int  AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
82 c0fe3827 bellard
int  AUD_get_buffer_size_out (SWVoiceOut *sw);
83 c0fe3827 bellard
void AUD_set_active_out (SWVoiceOut *sw, int on);
84 c0fe3827 bellard
int  AUD_is_active_out (SWVoiceOut *sw);
85 c0fe3827 bellard
86 c0fe3827 bellard
void     AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
87 c0fe3827 bellard
uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
88 c0fe3827 bellard
89 c0fe3827 bellard
SWVoiceIn *AUD_open_in (
90 c0fe3827 bellard
    QEMUSoundCard *card,
91 1d14ffa9 bellard
    SWVoiceIn *sw,
92 1d14ffa9 bellard
    const char *name,
93 1d14ffa9 bellard
    void *callback_opaque,
94 1d14ffa9 bellard
    audio_callback_fn_t callback_fn,
95 571ec3d6 bellard
    audsettings_t *settings,
96 571ec3d6 bellard
    int sw_endian
97 1d14ffa9 bellard
    );
98 c0fe3827 bellard
99 c0fe3827 bellard
void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
100 c0fe3827 bellard
int  AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
101 c0fe3827 bellard
void AUD_set_active_in (SWVoiceIn *sw, int on);
102 c0fe3827 bellard
int  AUD_is_active_in (SWVoiceIn *sw);
103 c0fe3827 bellard
104 c0fe3827 bellard
void     AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
105 c0fe3827 bellard
uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
106 85571bc7 bellard
107 85571bc7 bellard
static inline void *advance (void *p, int incr)
108 85571bc7 bellard
{
109 85571bc7 bellard
    uint8_t *d = p;
110 85571bc7 bellard
    return (d + incr);
111 85571bc7 bellard
}
112 85571bc7 bellard
113 85571bc7 bellard
uint32_t popcount (uint32_t u);
114 85571bc7 bellard
inline uint32_t lsbindex (uint32_t u);
115 85571bc7 bellard
116 1d14ffa9 bellard
#ifdef __GNUC__
117 1d14ffa9 bellard
#define audio_MIN(a, b) ( __extension__ ({      \
118 1d14ffa9 bellard
    __typeof (a) ta = a;                        \
119 1d14ffa9 bellard
    __typeof (b) tb = b;                        \
120 1d14ffa9 bellard
    ((ta)>(tb)?(tb):(ta));                      \
121 1d14ffa9 bellard
}))
122 1d14ffa9 bellard
123 1d14ffa9 bellard
#define audio_MAX(a, b) ( __extension__ ({      \
124 1d14ffa9 bellard
    __typeof (a) ta = a;                        \
125 1d14ffa9 bellard
    __typeof (b) tb = b;                        \
126 1d14ffa9 bellard
    ((ta)<(tb)?(tb):(ta));                      \
127 1d14ffa9 bellard
}))
128 1d14ffa9 bellard
#else
129 85571bc7 bellard
#define audio_MIN(a, b) ((a)>(b)?(b):(a))
130 85571bc7 bellard
#define audio_MAX(a, b) ((a)<(b)?(b):(a))
131 1d14ffa9 bellard
#endif
132 85571bc7 bellard
133 85571bc7 bellard
#endif  /* audio.h */