"SfR Fresh" - the SfR Freeware/Shareware Archive 
Member "usr/lib/oss/include/internals/audio_core.h" of archive oss-linux-v4.0-1016-i386.tar.gz:
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1 #ifndef AUDIO_CORE_H
2 #define AUDIO_CORE_H
3 /*
4 * Purpose: Internal definitions for the OS audio core
5 *
6 * IMPORTANT NOTICE!
7 *
8 * This file contains internal structures used by Open Sound Systems.
9 * They will change without any notice between OSS versions. Care must be taken
10 * to make sure any software using this header gets properly re-compiled before
11 * use.
12 *
13 * 4Front Technologies (or anybody else) takes no responsibility of damages
14 * caused by use of this file.
15 */
16
17 #define COPYING26 Copyright (C) Hannu Savolainen and Dev Mazumdar 1996-2006. All rights reserved.
18
19 /*
20 * Max number of audio channels currently supported by the sample format converter.
21 */
22 #define OSS_MAX_CONVERT_CHANNELS 8
23
24 #define TMP_CONVERT_MAX 1024
25 #define TMP_CONVERT_BUF_SIZE (8*TMP_CONVERT_MAX+512)
26
27 /*
28 * open_flags (for opening audio devices)
29 */
30 #define OF_MMAP 0x00000001 /* Opening application is known to use mmap() */
31 #define OF_BLOCK 0x00000002 /* Disable O_NONBLOCK */
32 #define OF_NOCONV 0x00000010 /* Disable all fmt/src conversions */
33 #define OF_DEVAUDIO 0x00000020 /* Solaris /dev/audio emulator */
34 #define OF_SMALLFRAGS 0x00000040 /* Use smaller fragments than requested */
35 #define OF_SMALLBUF 0x00000080 /* Allocate small (4k) buffer this time */
36 #define OF_MEDIUMBUF 0x00000100 /* Allocate moderate (16k) buffer */
37
38 #define CONVERTABLE_FORMATS \
39 (AFMT_U8|AFMT_S8|AFMT_MU_LAW|AFMT_S16_LE|AFMT_S16_BE|\
40 AFMT_S24_LE|AFMT_S24_BE|AFMT_S32_LE|AFMT_S32_BE|AFMT_S24_PACKED)
41
42 #ifndef _KERNEL
43 typedef struct _audiodrv_t audiodrv_t;
44 #endif
45
46 typedef struct
47 {
48 char *name;
49 int fmt;
50 unsigned char neutral_byte;
51 char bits;
52 char is_linear;
53 char endianess;
54 #define ENDIAN_NONE 0
55 #define ENDIAN_LITTLE 1
56 #define ENDIAN_BIG 2
57 #ifdef OSS_BIG_ENDIAN
58 # define ENDIAN_NATIVE ENDIAN_BIG
59 #else
60 # define ENDIAN_NATIVE ENDIAN_LITTLE
61 #endif
62
63 char is_signed;
64 char alignment;
65 #define ALIGN_MSB 0
66 #define ALIGN_LSB 1
67 int no_convert;
68 }
69 audio_format_info_t, *audio_format_info_p;
70
71 typedef struct
72 {
73 int fmt, rate, channels;
74 int convert;
75 }
76 sample_parms;
77
78 typedef struct _adev_t adev_t, *adev_p;
79 typedef struct _dmap_t *dmap_p;
80 typedef int (*cnv_func_t) (adev_p adev, dmap_p dmap, void **srcp, int *srcl,
81 void **tgtp, sample_parms * source,
82 sample_parms * target);
83
84 struct _dmap_t
85 {
86 /*
87 * Static fields (not to be cleared during open)
88 */
89 #ifdef _KERNEL
90 oss_mutex_t mutex;
91 #endif
92 oss_device_t *osdev;
93 oss_device_t *master_osdev; /* The osdev pointer of the master (for virtual drivers) */
94 adev_t *adev;
95 unsigned char *dmabuf;
96 oss_native_word dmabuf_phys;
97 int buffsize;
98 int buffer_protected; /* Buffer is shared - don't modify/clear */
99 unsigned char *tmpbuf1, *tmpbuf2;
100 void *driver_use_ptr;
101 long driver_use_value;
102 /* Interrupt callback stuff */
103 void (*audio_callback) (int dev, int parm);
104 int callback_parm;
105
106 #ifdef OS_DMA_PARMS
107 OS_DMA_PARMS
108 #endif
109 /*
110 * Dynamic fields (will be zeroed during open)
111 * Don't add anything before flags.
112 */
113 void *srcstate[OSS_MAX_CONVERT_CHANNELS];
114 oss_native_word flags;
115 #define DMAP_NOTIMEOUT 0x00000001
116 #define DMAP_POST 0x00000002
117 #define DMAP_PREPARED 0x00000004
118 #define DMAP_FRAGFIXED 0x00000008 /* Fragment size fixed */
119 #define DMAP_STARTED 0x00000010
120 #define DMAP_COOKED 0x00000020
121 #define DMAP_SMALLBUF 0x00000040 /* Allocate small buffers */
122 #define DMAP_MEDIUMBUF 0x00000040 /* Allocate 16k buffers */
123 int dma_mode; /* PCM_ENABLE_INPUT, PCM_ENABLE_OUTPUT or 0 */
124
125 /*
126 * Queue parameters.
127 */
128 int nfrags;
129 int fragment_size;
130 int bytes_in_use;
131 int data_rate; /* Bytes/second */
132 int frame_size; /* Device frame size */
133 int user_frame_size; /* Application frame size */
134 int fragsize_rq;
135 int low_water, low_water_rq;
136 volatile oss_uint64_t byte_counter;
137 volatile oss_uint64_t user_counter;
138 int interrupt_count;
139 int fragment_counter;
140 int expand_factor;
141
142 int mapping_flags;
143 #define DMA_MAP_MAPPED 0x00000001
144 char neutral_byte;
145
146 int error;
147 int play_underruns, rec_overruns;
148 int underrun_flag;
149 int num_errors;
150 #define MAX_AUDIO_ERRORS 5
151 int errors[MAX_AUDIO_ERRORS];
152 int error_parms[MAX_AUDIO_ERRORS];
153
154 unsigned char *leftover_buf;
155 int leftover_bytes;
156 int tmpbuf_len, tmpbuf_ptr;
157 cnv_func_t convert_func;
158 unsigned int convert_mode;
159 struct audio_buffer *(*user_import) (adev_t * adev,
160 dmap_t * dmap,
161 sample_parms * parms,
162 unsigned char *cbuf, int len);
163 int (*user_export) (adev_t * adev,
164 dmap_t * dmap, sample_parms * parms,
165 struct audio_buffer * buf, unsigned char *cbuf,
166 int maxbytes);
167 struct audio_buffer *(*device_read) (adev_t * adev,
168 dmap_t * dmap,
169 sample_parms * parms,
170 unsigned char *cbuf, int len);
171 int (*device_write) (adev_t * adev,
172 dmap_t * dmap,
173 void *frombuf, void *tobuf,
174 int maxspace, int *fromlen, int *tolen);
175 };
176 extern int dmap_get_qlen (dmap_t * dmap);
177 extern int dmap_get_qhead (dmap_t * dmap);
178 extern int dmap_get_qtail (dmap_t * dmap);
179
180 struct _adev_t
181 {
182 char name[64];
183 char handle[32];
184 int engine_num; /* Audio engine number */
185 int audio_devfile; /* Audio device file number */
186 int enabled;
187 int unloaded;
188 struct _adev_t *next_in, *next_out; /* Links to the next "shadow" devices */
189 int flags;
190 int open_flags;
191 int src_quality;
192 int caps;
193 int magic; /* Secret low level driver ID */
194 int latency; /* In usecs, -1=unknown */
195
196
197 /*
198 * Sampling parameters
199 */
200
201 sample_parms user_parms, hw_parms;
202 int iformat_mask, oformat_mask; /* Bitmasks for supported audio formats */
203 int min_rate, max_rate; /* Sampling rate limits */
204 int min_channels, max_channels;
205 char *inch_names, *outch_names;
206 int xformat_mask; /* Format mask for current open mode */
207 int binding;
208 void *devc; /* Driver specific info */
209 audiodrv_t *d;
210 void *portc, *portc_play, *portc_record; /* Driver specific info */
211 dmap_t *dmap_in, *dmap_out;
212 int mixer_dev;
213 int open_mode;
214 int go;
215 int enable_bits;
216 int parent_dev; /* 0 -> no parent, 1 to n -> parent=parent_dev+1 */
217 int max_block; /* Maximum fragment size to be accepted */
218 int min_block; /* Minimum fragment size */
219 int min_fragments; /* Minimum number of fragments */
220 int max_fragments; /* Maximum number of fragments */
221 int max_intrate; /* Another form of min_block */
222 int dmabuf_alloc_flags;
223 oss_uint64_t dmabuf_maxaddr;
224 int fixed_rate;
225 int vmix_flags; /* special flags sent to virtual mixer */
226 #define VMIX_MULTIFRAG 0x00000001 /* More than 2 fragments required (causes longer latencies) */
227 #define VMIX_DISABLED 0x00000002 /* Not compatible with vmix */
228 #define VMIX_NOINPUT 0x00000004 /* Disable input capability */
229 #define VMIX_NOMAINVOL 0x00000008 /* No main volume sliders/meters please */
230 #define VMIX_SKIP 0x00000010 /* Do not install vmix devices by default */
231 #define VMIX_SMART_ATTACH 0x00000020 /* Do not atach vmix before the input master device is available */
232 pid_t pid;
233 char cmd[16];
234 oss_device_t *osdev;
235 oss_device_t *master_osdev; /* The osdev pointer of the master (for virtual drivers) */
236 int setfragment_warned;
237 int getispace_error_count;
238 int redirect_in, redirect_out;
239 int dmask; /* Open dmaps */
240 #define DMASK_OUT 0x01
241 #define DMASK_IN 0x02
242 int nonblock;
243 int forced_nonblock;
244 int ossd_registered;
245 int sync_flags;
246 #define SYNC_MASTER 0x01
247 #define SYNC_SLAVE 0x02
248 int sync_group;
249 int sync_mode;
250 adev_t *sync_next; /* Next device in sync group */
251
252 int rate_source;
253 unsigned int nrates, rates[OSS_MAX_SAMPLE_RATES + 1];
254
255 #ifdef _KERNEL
256 oss_mutex_t mutex;
257 oss_wait_queue_t *out_wq, *in_wq;
258 #endif
259
260 int card_number;
261 int port_number;
262 int real_dev;
263
264 /*
265 * By default OSS will let applications to use sampling rates and formats
266 * that are not supported by the hardware. Instead OSS performs the necessary
267 * format conversions in software. Applications that don't tolerate this kind
268 * of conversions usually disable them by using features of the OSS API
269 * (SNDCTL_DSP_COOKEDMODE). If this option is set to 0 then the format
270 * conversions will be disabled for all applications and devices unless the
271 * application explicitly enables them.
272 *
273 * cooked_enable is a global variable (int) defined in options.c. The current
274 * value of this global variable will be copied to adev->cooked_enable when
275 * an audio engine is opened.
276 */
277 int cooked_enable;
278 int timeout_count;
279
280 void (*outputintr) (int dev, int intr_flags);
281 void (*inputintr) (int dev, int intr_flags);
282
283 int policy;
284 void *os_id; /* The device ID (dip) given by the system. */
285 oss_longname_t song_name;
286 oss_label_t label;
287 oss_devnode_t devnode;
288 void *vmix_mixer;
289 };
290
291 #define UNIT_EXPAND 1024
292
293 /*
294 * The audio_devfiles and audio_engines tables contain pointers to
295 * the (same) adev_t structures. The difference is that
296 * audio_engines contains an entry for all audio devices/engines in the system
297 * (including hidden and shadow devices). The 'dev' parameter of most audio
298 * core routines and audio driver methods are indexes to this array.
299 *
300 * The audio_devfiles array is a "parallel" structure that contains only
301 * the audio engines that have a device file in /dev/oss (and usually also
302 * an legacy /dev/dsp# device file). This audio_devfiles array doesn't contain
303 * "hidden" audio engines.
304 *
305 * Each audio operations structure in audio_devfiles will also be in
306 * audio_engines but the indexes are different. Both arrays contain pointer to
307 * the same structure in memory (not a copy).
308 *
309 * For example the 6th audio device file (usually but not always /dev/dsp5) is
310 * audio_devfiles[5]. However it may be (say) audio_engines[11] if there are
311 * hidden devices created before it.
312 *
313 * /dev/dsp5 -> audio_devfile[5] == audio_engines[11]
314 *
315 * The next field of the adev_t structure contains a pointer
316 * to the next "identical" device. Most OSS implementations will
317 * try to open one of the subsequent devices in the next chain if
318 * the original device was busy. "Identical" means that the device suports
319 * multiple identical (hw mixing) engines or the vmix driver is used to
320 * add software mixing capability to the device.
321 */
322
323 extern adev_t **audio_engines;
324 extern int num_audio_engines;
325 extern adev_t **audio_devfiles;
326 extern int num_audio_devfiles;
327
328 typedef struct
329 {
330 int ndevs;
331 unsigned char devices[MAX_PCM_DEV];
332 }
333 oss_devlist_t;
334
335 extern oss_devlist_t dspoutlist, dspoutlist2, dspinlist, dspinoutlist;
336 int oss_install_audiodev_with_devname (int vers,
337 oss_device_t * osdev,
338 oss_device_t * master_osdev,
339 char *name,
340 const audiodrv_t * driver,
341 int driver_size,
342 int flags,
343 unsigned int format_mask, void *devc, int parent,
344 char *dev_name);
345
346 int oss_install_audiodev (int vers,
347 oss_device_t * osdev,
348 oss_device_t * master_osdev,
349 char *name,
350 const audiodrv_t * driver,
351 int driver_size,
352 int flags,
353 unsigned int format_mask, void *devc, int parent);
354 extern void install_vdsp (oss_device_t * osdev);
355 extern int *load_mixer_volumes (char *name, int *levels, int present);
356
357 #ifdef _KERNEL
358 int oss_audio_read (int dev, struct fileinfo *file, uio_t * buf, int count);
359 int oss_audio_write (int dev, struct fileinfo *file, uio_t * buf, int count);
360 int oss_audio_open_engine (int dev, int dev_class, struct fileinfo *file,
361 int recursive, int open_flags, int *newdev);
362 int oss_audio_open_devfile (int dev, int dev_class, struct fileinfo *file,
363 int recursive, int open_flags, int *newdev);
364 int oss_open_vdsp (int dev, int dev_type, struct fileinfo *file,
365 int recursive, int open_flags, int *newdev);
366 void oss_audio_release (int dev, struct fileinfo *file);
367 int oss_audio_ioctl (int dev, struct fileinfo *file,
368 unsigned int cmd, ioctl_arg arg);
369 int oss_audio_set_format (int dev, int fmt, int format_mask);
370 int oss_audio_set_channels (int dev, int ch);
371 int oss_audio_set_rate (int dev, int val);
372 void audio_uninit_device (int dev);
373 int oss_audio_mmap (int dev, int direction);
374 #endif
375
376 /* From audiofmt.c */
377 int setup_format_conversions (adev_p adev, dmap_p dmap, sample_parms * source,
378 sample_parms * target,
379 sample_parms * user,
380 sample_parms * device, int format_mask);
381 audio_format_info_p oss_find_format (unsigned int fmt);
382
383
384 #define oss_audio_outputintr(dev, flags) audio_engines[dev]->outputintr(dev, flags)
385 #define oss_audio_inputintr(dev, flags) audio_engines[dev]->inputintr(dev, flags)
386 void oss_audio_reset (int dev);
387 void oss_audio_start_syncgroup (unsigned int syncgroup);
388 typedef int (*oss_audio_startup_func) (void *devc);
389 extern void oss_audio_register_client (oss_audio_startup_func func,
390 void *devc, oss_device_t * osdev);
391
392 extern int oss_encode_enum (oss_mixer_enuminfo * ei, const char *s,
393 int version);
394 extern char *audio_show_latency (int dev);
395 extern void oss_audio_inc_byte_counter (dmap_t * dmap, int increment);
396 extern void oss_add_audio_devlist (int list, int devfile);
397
398 #ifndef SMALL_DMABUF_SIZE
399 #define SMALL_DMABUF_SIZE (4*1024)
400 #endif
401
402 #define MEDIUM_DMABUF_SIZE (16*1024)
403 #endif