Revision fb065187 audio/audio.h
b/audio/audio.h | ||
---|---|---|
26 | 26 |
|
27 | 27 |
#include "mixeng.h" |
28 | 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 | 29 |
typedef enum { |
37 | 30 |
AUD_FMT_U8, |
38 | 31 |
AUD_FMT_S8, |
... | ... | |
40 | 33 |
AUD_FMT_S16 |
41 | 34 |
} audfmt_e; |
42 | 35 |
|
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); |
|
36 |
typedef struct SWVoice SWVoice; |
|
163 | 37 |
|
164 |
/* Public API */ |
|
165 | 38 |
SWVoice * AUD_open (SWVoice *sw, const char *name, int freq, |
166 | 39 |
int nchannels, audfmt_e fmt); |
40 |
void AUD_init (void); |
|
41 |
void AUD_log (const char *cap, const char *fmt, ...) |
|
42 |
__attribute__ ((__format__ (__printf__, 2, 3)));; |
|
43 |
void AUD_close (SWVoice *sw); |
|
167 | 44 |
int AUD_write (SWVoice *sw, void *pcm_buf, int size); |
168 | 45 |
void AUD_adjust (SWVoice *sw, int leftover); |
169 | 46 |
void AUD_reset (SWVoice *sw); |
Also available in: Unified diff