Statistics
| Branch: | Revision:

root / audio / audio.h @ 85571bc7

History | View | Annotate | Download (5 kB)

1
/*
2
 * QEMU Audio subsystem header
3
 * 
4
 * Copyright (c) 2003-2004 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
#ifndef QEMU_AUDIO_H
25
#define QEMU_AUDIO_H
26

    
27
#include "mixeng.h"
28

    
29
#define dolog(...) fprintf (stderr, AUDIO_CAP ": " __VA_ARGS__)
30
#ifdef DEBUG
31
#define ldebug(...) dolog (__VA_ARGS__)
32
#else
33
#define ldebug(...)
34
#endif
35

    
36
typedef enum {
37
  AUD_FMT_U8,
38
  AUD_FMT_S8,
39
  AUD_FMT_U16,
40
  AUD_FMT_S16
41
} audfmt_e;
42

    
43
typedef struct HWVoice HWVoice;
44
struct audio_output_driver;
45

    
46
typedef struct AudioState {
47
    int fixed_format;
48
    int fixed_freq;
49
    int fixed_channels;
50
    int fixed_fmt;
51
    int nb_hw_voices;
52
    int voice_size;
53
    int64_t ticks_threshold;
54
    int freq_threshold;
55
    void *opaque;
56
    struct audio_output_driver *drv;
57
} AudioState;
58

    
59
extern AudioState audio_state;
60

    
61
typedef struct SWVoice {
62
    int freq;
63
    audfmt_e fmt;
64
    int nchannels;
65

    
66
    int shift;
67
    int align;
68

    
69
    t_sample *conv;
70

    
71
    int left;
72
    int pos;
73
    int bytes_per_second;
74
    int64_t ratio;
75
    st_sample_t *buf;
76
    void *rate;
77

    
78
    int wpos;
79
    int live;
80
    int active;
81
    int64_t old_ticks;
82
    HWVoice *hw;
83
    char *name;
84
} SWVoice;
85

    
86
#define VOICE_ENABLE 1
87
#define VOICE_DISABLE 2
88

    
89
struct pcm_ops {
90
    int  (*init)  (HWVoice *hw, int freq, int nchannels, audfmt_e fmt);
91
    void (*fini)  (HWVoice *hw);
92
    void (*run)   (HWVoice *hw);
93
    int  (*write) (SWVoice *sw, void *buf, int size);
94
    int  (*ctl)   (HWVoice *hw, int cmd, ...);
95
};
96

    
97
struct audio_output_driver {
98
    const char *name;
99
    void *(*init) (void);
100
    void (*fini) (void *);
101
    struct pcm_ops *pcm_ops;
102
    int can_be_default;
103
    int max_voices;
104
    int voice_size;
105
};
106

    
107
struct HWVoice {
108
    int active;
109
    int enabled;
110
    int pending_disable;
111
    int valid;
112
    int freq;
113

    
114
    f_sample *clip;
115
    audfmt_e fmt;
116
    int nchannels;
117

    
118
    int align;
119
    int shift;
120

    
121
    int rpos;
122
    int bufsize;
123

    
124
    int bytes_per_second;
125
    st_sample_t *mix_buf;
126

    
127
    int samples;
128
    int64_t old_ticks;
129
    int nb_voices;
130
    struct SWVoice **pvoice;
131
    struct pcm_ops *pcm_ops;
132
};
133

    
134
void      audio_log (const char *fmt, ...);
135
void      pcm_sw_free_resources (SWVoice *sw);
136
int       pcm_sw_alloc_resources (SWVoice *sw);
137
void      pcm_sw_fini (SWVoice *sw);
138
int       pcm_sw_init (SWVoice *sw, HWVoice *hw, int freq,
139
                       int nchannels, audfmt_e fmt);
140

    
141
void      pcm_hw_clear (HWVoice *hw, void *buf, int len);
142
HWVoice * pcm_hw_find_any (HWVoice *hw);
143
HWVoice * pcm_hw_find_any_active (HWVoice *hw);
144
HWVoice * pcm_hw_find_any_passive (HWVoice *hw);
145
HWVoice * pcm_hw_find_specific (HWVoice *hw, int freq,
146
                                int nchannels, audfmt_e fmt);
147
HWVoice * pcm_hw_add (int freq, int nchannels, audfmt_e fmt);
148
int       pcm_hw_add_sw (HWVoice *hw, SWVoice *sw);
149
int       pcm_hw_del_sw (HWVoice *hw, SWVoice *sw);
150
SWVoice * pcm_create_voice_pair (int freq, int nchannels, audfmt_e fmt);
151

    
152
void      pcm_hw_free_resources (HWVoice *hw);
153
int       pcm_hw_alloc_resources (HWVoice *hw);
154
void      pcm_hw_fini (HWVoice *hw);
155
void      pcm_hw_gc (HWVoice *hw);
156
int       pcm_hw_get_live (HWVoice *hw);
157
int       pcm_hw_get_live2 (HWVoice *hw, int *nb_active);
158
void      pcm_hw_dec_live (HWVoice *hw, int decr);
159
int       pcm_hw_write (SWVoice *sw, void *buf, int len);
160

    
161
int         audio_get_conf_int (const char *key, int defval);
162
const char *audio_get_conf_str (const char *key, const char *defval);
163

    
164
/* Public API */
165
SWVoice * AUD_open (SWVoice *sw, const char *name, int freq,
166
                    int nchannels, audfmt_e fmt);
167
int    AUD_write (SWVoice *sw, void *pcm_buf, int size);
168
void   AUD_adjust (SWVoice *sw, int leftover);
169
void   AUD_reset (SWVoice *sw);
170
int    AUD_get_free (SWVoice *sw);
171
int    AUD_get_buffer_size (SWVoice *sw);
172
void   AUD_run (void);
173
void   AUD_enable (SWVoice *sw, int on);
174
int    AUD_calc_elapsed (SWVoice *sw);
175

    
176
static inline void *advance (void *p, int incr)
177
{
178
    uint8_t *d = p;
179
    return (d + incr);
180
}
181

    
182
uint32_t popcount (uint32_t u);
183
inline uint32_t lsbindex (uint32_t u);
184

    
185
#define audio_MIN(a, b) ((a)>(b)?(b):(a))
186
#define audio_MAX(a, b) ((a)<(b)?(b):(a))
187

    
188
#endif  /* audio.h */