OSDN Git Service

Changed Jaroslav Kysela's e-mail from perex@suse.cz to perex@perex.cz
[android-x86/external-alsa-lib.git] / src / pcm / pcm_local.h
1 /*
2  *  PCM Interface - local header file
3  *  Copyright (c) 2000 by Jaroslav Kysela <perex@perex.cz>
4  *                        Abramo Bagnara <abramo@alsa-project.org>
5  *
6  *
7  *   This library is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU Lesser General Public License as
9  *   published by the Free Software Foundation; either version 2.1 of
10  *   the License, or (at your option) any later version.
11  *
12  *   This program is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU Lesser General Public License for more details.
16  *
17  *   You should have received a copy of the GNU Lesser General Public
18  *   License along with this library; if not, write to the Free Software
19  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20  *
21  */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <limits.h>
26 #include <sys/uio.h>
27
28 #define _snd_mask sndrv_mask
29 #define _snd_pcm_access_mask _snd_mask
30 #define _snd_pcm_format_mask _snd_mask
31 #define _snd_pcm_subformat_mask _snd_mask
32
33 #include "local.h"
34
35 #define SND_INTERVAL_INLINE
36 #include "interval.h"
37
38 #define SND_MASK_INLINE
39 #include "mask.h"
40
41 typedef enum sndrv_pcm_hw_param snd_pcm_hw_param_t;
42 #define SND_PCM_HW_PARAM_ACCESS SNDRV_PCM_HW_PARAM_ACCESS
43 #define SND_PCM_HW_PARAM_FIRST_MASK SNDRV_PCM_HW_PARAM_FIRST_MASK
44 #define SND_PCM_HW_PARAM_FORMAT SNDRV_PCM_HW_PARAM_FORMAT
45 #define SND_PCM_HW_PARAM_SUBFORMAT SNDRV_PCM_HW_PARAM_SUBFORMAT
46 #define SND_PCM_HW_PARAM_LAST_MASK SNDRV_PCM_HW_PARAM_LAST_MASK
47 #define SND_PCM_HW_PARAM_SAMPLE_BITS SNDRV_PCM_HW_PARAM_SAMPLE_BITS
48 #define SND_PCM_HW_PARAM_FIRST_INTERVAL SNDRV_PCM_HW_PARAM_FIRST_INTERVAL
49 #define SND_PCM_HW_PARAM_FRAME_BITS SNDRV_PCM_HW_PARAM_FRAME_BITS
50 #define SND_PCM_HW_PARAM_CHANNELS SNDRV_PCM_HW_PARAM_CHANNELS
51 #define SND_PCM_HW_PARAM_RATE SNDRV_PCM_HW_PARAM_RATE
52 #define SND_PCM_HW_PARAM_PERIOD_TIME SNDRV_PCM_HW_PARAM_PERIOD_TIME
53 #define SND_PCM_HW_PARAM_PERIOD_SIZE SNDRV_PCM_HW_PARAM_PERIOD_SIZE
54 #define SND_PCM_HW_PARAM_PERIOD_BYTES SNDRV_PCM_HW_PARAM_PERIOD_BYTES
55 #define SND_PCM_HW_PARAM_PERIODS SNDRV_PCM_HW_PARAM_PERIODS
56 #define SND_PCM_HW_PARAM_BUFFER_TIME SNDRV_PCM_HW_PARAM_BUFFER_TIME
57 #define SND_PCM_HW_PARAM_BUFFER_SIZE SNDRV_PCM_HW_PARAM_BUFFER_SIZE
58 #define SND_PCM_HW_PARAM_BUFFER_BYTES SNDRV_PCM_HW_PARAM_BUFFER_BYTES
59 #define SND_PCM_HW_PARAM_TICK_TIME SNDRV_PCM_HW_PARAM_TICK_TIME
60 #define SND_PCM_HW_PARAM_LAST_INTERVAL SNDRV_PCM_HW_PARAM_LAST_INTERVAL
61 #define SND_PCM_HW_PARAM_LAST_MASK SNDRV_PCM_HW_PARAM_LAST_MASK
62 #define SND_PCM_HW_PARAM_FIRST_MASK SNDRV_PCM_HW_PARAM_FIRST_MASK
63 #define SND_PCM_HW_PARAM_LAST_INTERVAL SNDRV_PCM_HW_PARAM_LAST_INTERVAL
64 #define SND_PCM_HW_PARAM_FIRST_INTERVAL SNDRV_PCM_HW_PARAM_FIRST_INTERVAL
65
66 /** device accepts mmaped access */
67 #define SND_PCM_INFO_MMAP SNDRV_PCM_INFO_MMAP
68 /** device accepts  mmaped access with sample resolution */
69 #define SND_PCM_INFO_MMAP_VALID SNDRV_PCM_INFO_MMAP_VALID
70 /** device is doing double buffering */
71 #define SND_PCM_INFO_DOUBLE SNDRV_PCM_INFO_DOUBLE
72 /** device transfers samples in batch */
73 #define SND_PCM_INFO_BATCH SNDRV_PCM_INFO_BATCH
74 /** device accepts interleaved samples */
75 #define SND_PCM_INFO_INTERLEAVED SNDRV_PCM_INFO_INTERLEAVED
76 /** device accepts non-interleaved samples */
77 #define SND_PCM_INFO_NONINTERLEAVED SNDRV_PCM_INFO_NONINTERLEAVED
78 /** device accepts complex sample organization */
79 #define SND_PCM_INFO_COMPLEX SNDRV_PCM_INFO_COMPLEX
80 /** device is capable block transfers */
81 #define SND_PCM_INFO_BLOCK_TRANSFER SNDRV_PCM_INFO_BLOCK_TRANSFER
82 /** device can detect DAC/ADC overrange */
83 #define SND_PCM_INFO_OVERRANGE SNDRV_PCM_INFO_OVERRANGE
84 /** device supports resume */
85 #define SND_PCM_INFO_RESUME SNDRV_PCM_INFO_RESUME
86 /** device is capable to pause */
87 #define SND_PCM_INFO_PAUSE SNDRV_PCM_INFO_PAUSE
88 /** device can do only half duplex */
89 #define SND_PCM_INFO_HALF_DUPLEX SNDRV_PCM_INFO_HALF_DUPLEX
90 /** device can do only joint duplex (same parameters) */
91 #define SND_PCM_INFO_JOINT_DUPLEX SNDRV_PCM_INFO_JOINT_DUPLEX
92 /** device can do a kind of synchronized start */
93 #define SND_PCM_INFO_SYNC_START SNDRV_PCM_INFO_SYNC_START
94
95 #define SND_PCM_HW_PARAMS_NORESAMPLE SNDRV_PCM_HW_PARAMS_NORESAMPLE
96 #define SND_PCM_HW_PARAMS_EXPORT_BUFFER SNDRV_PCM_HW_PARAMS_EXPORT_BUFFER
97
98 typedef struct _snd_pcm_rbptr {
99         snd_pcm_t *master;
100         volatile snd_pcm_uframes_t *ptr;
101         int fd;
102         off_t offset;
103         int link_dst_count;
104         snd_pcm_t **link_dst;
105         void *private_data;
106         void (*changed)(snd_pcm_t *pcm, snd_pcm_t *src);
107 } snd_pcm_rbptr_t;
108
109 typedef struct _snd_pcm_channel_info {
110         unsigned int channel;
111         void *addr;                     /* base address of channel samples */
112         unsigned int first;             /* offset to first sample in bits */
113         unsigned int step;              /* samples distance in bits */
114         enum { SND_PCM_AREA_SHM, SND_PCM_AREA_MMAP, SND_PCM_AREA_LOCAL } type;
115         union {
116                 struct {
117                         struct snd_shm_area *area;
118                         int shmid;
119                 } shm;
120                 struct {
121                         int fd;
122                         off_t offset;
123                 } mmap;
124         } u;
125         char reserved[64];
126 } snd_pcm_channel_info_t;
127
128 typedef struct {
129         int (*close)(snd_pcm_t *pcm);
130         int (*nonblock)(snd_pcm_t *pcm, int nonblock);
131         int (*async)(snd_pcm_t *pcm, int sig, pid_t pid);
132         int (*info)(snd_pcm_t *pcm, snd_pcm_info_t *info);
133         int (*hw_refine)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
134         int (*hw_params)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
135         int (*hw_free)(snd_pcm_t *pcm);
136         int (*sw_params)(snd_pcm_t *pcm, snd_pcm_sw_params_t *params);
137         int (*channel_info)(snd_pcm_t *pcm, snd_pcm_channel_info_t *info);
138         void (*dump)(snd_pcm_t *pcm, snd_output_t *out);
139         int (*mmap)(snd_pcm_t *pcm);
140         int (*munmap)(snd_pcm_t *pcm);
141 } snd_pcm_ops_t;
142
143 typedef struct {
144         int (*status)(snd_pcm_t *pcm, snd_pcm_status_t *status);
145         int (*prepare)(snd_pcm_t *pcm);
146         int (*reset)(snd_pcm_t *pcm);
147         int (*start)(snd_pcm_t *pcm);
148         int (*drop)(snd_pcm_t *pcm);
149         int (*drain)(snd_pcm_t *pcm);
150         int (*pause)(snd_pcm_t *pcm, int enable);
151         snd_pcm_state_t (*state)(snd_pcm_t *pcm);
152         int (*hwsync)(snd_pcm_t *pcm);
153         int (*delay)(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp);
154         int (*resume)(snd_pcm_t *pcm);
155         int (*link)(snd_pcm_t *pcm1, snd_pcm_t *pcm2);
156         int (*link_slaves)(snd_pcm_t *pcm, snd_pcm_t *master);
157         int (*unlink)(snd_pcm_t *pcm);
158         snd_pcm_sframes_t (*rewind)(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
159         snd_pcm_sframes_t (*forward)(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
160         snd_pcm_sframes_t (*writei)(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size);
161         snd_pcm_sframes_t (*writen)(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
162         snd_pcm_sframes_t (*readi)(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size);
163         snd_pcm_sframes_t (*readn)(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
164         snd_pcm_sframes_t (*avail_update)(snd_pcm_t *pcm);
165         snd_pcm_sframes_t (*mmap_commit)(snd_pcm_t *pcm, snd_pcm_uframes_t offset, snd_pcm_uframes_t size);
166         int (*poll_descriptors_count)(snd_pcm_t *pcm);
167         int (*poll_descriptors)(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space);
168         int (*poll_revents)(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
169 } snd_pcm_fast_ops_t;
170
171 struct _snd_pcm {
172         void *dl_handle;
173         char *name;
174         snd_pcm_type_t type;
175         snd_pcm_stream_t stream;
176         int mode;
177         int poll_fd_count;
178         int poll_fd;
179         unsigned short poll_events;
180         int setup;
181         snd_pcm_access_t access;        /* access mode */
182         snd_pcm_format_t format;        /* SND_PCM_FORMAT_* */
183         snd_pcm_subformat_t subformat;  /* subformat */
184         unsigned int channels;          /* channels */
185         unsigned int rate;              /* rate in Hz */
186         snd_pcm_uframes_t period_size;
187         unsigned int period_time;       /* period duration */
188         snd_interval_t periods;
189         unsigned int tick_time;
190         snd_pcm_tstamp_t tstamp_mode;   /* timestamp mode */
191         unsigned int period_step;
192         unsigned int sleep_min;
193         snd_pcm_uframes_t avail_min;    /* min avail frames for wakeup */
194         snd_pcm_uframes_t start_threshold;      
195         snd_pcm_uframes_t stop_threshold;       
196         snd_pcm_uframes_t silence_threshold;    /* Silence filling happens when
197                                            noise is nearest than this */
198         snd_pcm_uframes_t silence_size; /* Silence filling size */
199         snd_pcm_uframes_t xfer_align;   /* xfer size need to be a multiple */
200         snd_pcm_uframes_t boundary;     /* pointers wrap point */
201         unsigned int info;              /* Info for returned setup */
202         unsigned int msbits;            /* used most significant bits */
203         unsigned int rate_num;          /* rate numerator */
204         unsigned int rate_den;          /* rate denominator */
205         unsigned int hw_flags;          /* actual hardware flags */
206         snd_pcm_uframes_t fifo_size;    /* chip FIFO size in frames */
207         snd_pcm_uframes_t buffer_size;
208         snd_interval_t buffer_time;
209         unsigned int sample_bits;
210         unsigned int frame_bits;
211         snd_pcm_rbptr_t appl;
212         snd_pcm_rbptr_t hw;
213         snd_pcm_uframes_t min_align;
214         unsigned int mmap_rw: 1;        /* use always mmapped buffer */
215         unsigned int mmap_shadow: 1;    /* don't call actual mmap,
216                                          * use the mmaped buffer of the slave
217                                          */
218         unsigned int donot_close: 1;    /* don't close this PCM */
219         snd_pcm_channel_info_t *mmap_channels;
220         snd_pcm_channel_area_t *running_areas;
221         snd_pcm_channel_area_t *stopped_areas;
222         snd_pcm_ops_t *ops;
223         snd_pcm_fast_ops_t *fast_ops;
224         snd_pcm_t *op_arg;
225         snd_pcm_t *fast_op_arg;
226         void *private_data;
227         struct list_head async_handlers;
228 };
229
230 int snd_pcm_new(snd_pcm_t **pcmp, snd_pcm_type_t type, const char *name,
231                 snd_pcm_stream_t stream, int mode);
232 int snd_pcm_free(snd_pcm_t *pcm);
233
234 void snd_pcm_areas_from_buf(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas, void *buf);
235 void snd_pcm_areas_from_bufs(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas, void **bufs);
236
237 int snd_pcm_async(snd_pcm_t *pcm, int sig, pid_t pid);
238 int snd_pcm_mmap(snd_pcm_t *pcm);
239 int snd_pcm_munmap(snd_pcm_t *pcm);
240 int snd_pcm_mmap_ready(snd_pcm_t *pcm);
241 void snd_pcm_set_hw_ptr(snd_pcm_t *pcm, volatile snd_pcm_uframes_t *hw_ptr, int fd, off_t offset);
242 void snd_pcm_set_appl_ptr(snd_pcm_t *pcm, volatile snd_pcm_uframes_t *appl_ptr, int fd, off_t offset);
243 void snd_pcm_link_hw_ptr(snd_pcm_t *pcm, snd_pcm_t *slave);
244 void snd_pcm_link_appl_ptr(snd_pcm_t *pcm, snd_pcm_t *slave);
245 void snd_pcm_unlink_hw_ptr(snd_pcm_t *pcm, snd_pcm_t *slave);
246 void snd_pcm_unlink_appl_ptr(snd_pcm_t *pcm, snd_pcm_t *slave);
247 snd_pcm_sframes_t snd_pcm_mmap_appl_ptr(snd_pcm_t *pcm, off_t offset);
248 void snd_pcm_mmap_appl_backward(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
249 void snd_pcm_mmap_appl_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
250 void snd_pcm_mmap_hw_backward(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
251 void snd_pcm_mmap_hw_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
252
253 snd_pcm_sframes_t snd_pcm_mmap_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size);
254 snd_pcm_sframes_t snd_pcm_mmap_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size);
255 snd_pcm_sframes_t snd_pcm_mmap_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
256 snd_pcm_sframes_t snd_pcm_mmap_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
257
258 typedef snd_pcm_sframes_t (*snd_pcm_xfer_areas_func_t)(snd_pcm_t *pcm, 
259                                                        const snd_pcm_channel_area_t *areas,
260                                                        snd_pcm_uframes_t offset, 
261                                                        snd_pcm_uframes_t size);
262
263 snd_pcm_sframes_t snd_pcm_read_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas,
264                                      snd_pcm_uframes_t offset, snd_pcm_uframes_t size,
265                                      snd_pcm_xfer_areas_func_t func);
266 snd_pcm_sframes_t snd_pcm_write_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas,
267                                       snd_pcm_uframes_t offset, snd_pcm_uframes_t size,
268                                       snd_pcm_xfer_areas_func_t func);
269 snd_pcm_sframes_t snd_pcm_read_mmap(snd_pcm_t *pcm, snd_pcm_uframes_t offset,
270                                     snd_pcm_uframes_t size);
271 snd_pcm_sframes_t snd_pcm_write_mmap(snd_pcm_t *pcm, snd_pcm_uframes_t offset,
272                                      snd_pcm_uframes_t size);
273 static inline int snd_pcm_channel_info(snd_pcm_t *pcm, snd_pcm_channel_info_t *info)
274 {
275         return pcm->ops->channel_info(pcm, info);
276 }
277 int snd_pcm_channel_info_shm(snd_pcm_t *pcm, snd_pcm_channel_info_t *info, int shmid);
278 int _snd_pcm_poll_descriptor(snd_pcm_t *pcm);
279 #define _snd_pcm_link_descriptor _snd_pcm_poll_descriptor /* FIXME */
280 #define _snd_pcm_async_descriptor _snd_pcm_poll_descriptor /* FIXME */
281
282 /* handle special error cases */
283 static inline int snd_pcm_check_error(snd_pcm_t *pcm, int err)
284 {
285         if (err == -EINTR) {
286                 switch (snd_pcm_state(pcm)) {
287                 case SND_PCM_STATE_XRUN:
288                         return -EPIPE;
289                 case SND_PCM_STATE_SUSPENDED:
290                         return -ESTRPIPE;
291                 case SND_PCM_STATE_DISCONNECTED:
292                         return -ENODEV;
293                 default:
294                         break;
295                 }
296         }
297         return err;
298 }
299
300 static inline snd_pcm_uframes_t snd_pcm_mmap_playback_avail(snd_pcm_t *pcm)
301 {
302         snd_pcm_sframes_t avail;
303         avail = *pcm->hw.ptr + pcm->buffer_size - *pcm->appl.ptr;
304         if (avail < 0)
305                 avail += pcm->boundary;
306         else if ((snd_pcm_uframes_t) avail >= pcm->boundary)
307                 avail -= pcm->boundary;
308         return avail;
309 }
310
311 static inline snd_pcm_uframes_t snd_pcm_mmap_capture_avail(snd_pcm_t *pcm)
312 {
313         snd_pcm_sframes_t avail;
314         avail = *pcm->hw.ptr - *pcm->appl.ptr;
315         if (avail < 0)
316                 avail += pcm->boundary;
317         return avail;
318 }
319
320 static inline snd_pcm_uframes_t snd_pcm_mmap_avail(snd_pcm_t *pcm)
321 {
322         if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
323                 return snd_pcm_mmap_playback_avail(pcm);
324         else
325                 return snd_pcm_mmap_capture_avail(pcm);
326 }
327
328 static inline snd_pcm_sframes_t snd_pcm_mmap_playback_hw_avail(snd_pcm_t *pcm)
329 {
330         return pcm->buffer_size - snd_pcm_mmap_playback_avail(pcm);
331 }
332
333 static inline snd_pcm_sframes_t snd_pcm_mmap_capture_hw_avail(snd_pcm_t *pcm)
334 {
335         return pcm->buffer_size - snd_pcm_mmap_capture_avail(pcm);
336 }
337
338 static inline snd_pcm_sframes_t snd_pcm_mmap_hw_avail(snd_pcm_t *pcm)
339 {
340         snd_pcm_sframes_t avail;
341         avail = *pcm->hw.ptr - *pcm->appl.ptr;
342         if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
343                 avail += pcm->buffer_size;
344         if (avail < 0)
345                 avail += pcm->boundary;
346         return pcm->buffer_size - avail;
347 }
348
349 static inline const snd_pcm_channel_area_t *snd_pcm_mmap_areas(snd_pcm_t *pcm)
350 {
351         if (pcm->stopped_areas &&
352             snd_pcm_state(pcm) != SND_PCM_STATE_RUNNING) 
353                 return pcm->stopped_areas;
354         return pcm->running_areas;
355 }
356
357 static inline snd_pcm_uframes_t snd_pcm_mmap_offset(snd_pcm_t *pcm)
358 {
359         assert(pcm);
360         return *pcm->appl.ptr % pcm->buffer_size;
361 }
362
363 static inline snd_pcm_uframes_t snd_pcm_mmap_hw_offset(snd_pcm_t *pcm)
364 {
365         assert(pcm);
366         return *pcm->hw.ptr % pcm->buffer_size;
367 }
368
369 static inline snd_pcm_uframes_t snd_pcm_mmap_playback_delay(snd_pcm_t *pcm)
370 {
371         return snd_pcm_mmap_playback_hw_avail(pcm);
372 }
373
374 static inline snd_pcm_uframes_t snd_pcm_mmap_capture_delay(snd_pcm_t *pcm)
375 {
376         return snd_pcm_mmap_capture_hw_avail(pcm);
377 }
378
379 static inline snd_pcm_sframes_t snd_pcm_mmap_delay(snd_pcm_t *pcm)
380 {
381         if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
382                 return snd_pcm_mmap_playback_delay(pcm);
383         else
384                 return snd_pcm_mmap_capture_delay(pcm);
385 }
386
387 static inline void *snd_pcm_channel_area_addr(const snd_pcm_channel_area_t *area, snd_pcm_uframes_t offset)
388 {
389         unsigned int bitofs = area->first + area->step * offset;
390         assert(bitofs % 8 == 0);
391         return (char *) area->addr + bitofs / 8;
392 }
393
394 static inline unsigned int snd_pcm_channel_area_step(const snd_pcm_channel_area_t *area)
395 {
396         assert(area->step % 8 == 0);
397         return area->step / 8;
398 }
399
400 static inline snd_pcm_sframes_t _snd_pcm_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size)
401 {
402         return pcm->fast_ops->writei(pcm->fast_op_arg, buffer, size);
403 }
404
405 static inline snd_pcm_sframes_t _snd_pcm_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
406 {
407         return pcm->fast_ops->writen(pcm->fast_op_arg, bufs, size);
408 }
409
410 static inline snd_pcm_sframes_t _snd_pcm_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size)
411 {
412         return pcm->fast_ops->readi(pcm->fast_op_arg, buffer, size);
413 }
414
415 static inline snd_pcm_sframes_t _snd_pcm_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
416 {
417         return pcm->fast_ops->readn(pcm->fast_op_arg, bufs, size);
418 }
419
420 static inline int muldiv(int a, int b, int c, int *r)
421 {
422         int64_t n = (int64_t)a * b;
423         int64_t v = n / c;
424         if (v > INT_MAX) {
425                 *r = 0;
426                 return INT_MAX;
427         }
428         if (v < INT_MIN) {
429                 *r = 0;
430                 return INT_MIN;
431         }
432         *r = n % c;
433         return v;
434 }
435
436 static inline int muldiv_down(int a, int b, int c)
437 {
438         int64_t v = (int64_t)a * b / c;
439         if (v > INT_MAX) {
440                 return INT_MAX;
441         }
442         if (v < INT_MIN) {
443                 return INT_MIN;
444         }
445         return v;
446 }
447
448 static inline int muldiv_near(int a, int b, int c)
449 {
450         int r;
451         int n = muldiv(a, b, c, &r);
452         if (r >= (c + 1) / 2)
453                 n++;
454         return n;
455 }
456
457 int snd_pcm_hw_refine(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
458 int _snd_pcm_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
459 int snd_pcm_hw_refine_soft(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
460 int snd_pcm_hw_refine_slave(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
461                             int (*cprepare)(snd_pcm_t *pcm,
462                                             snd_pcm_hw_params_t *params),
463                             int (*cchange)(snd_pcm_t *pcm,
464                                            snd_pcm_hw_params_t *params,
465                                            snd_pcm_hw_params_t *sparams),
466                             int (*sprepare)(snd_pcm_t *pcm,
467                                             snd_pcm_hw_params_t *params),
468                             int (*schange)(snd_pcm_t *pcm,
469                                            snd_pcm_hw_params_t *params,
470                                            snd_pcm_hw_params_t *sparams),
471                             int (*srefine)(snd_pcm_t *pcm,
472                                            snd_pcm_hw_params_t *sparams));
473 int snd_pcm_hw_params_slave(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
474                             int (*cchange)(snd_pcm_t *pcm,
475                                            snd_pcm_hw_params_t *params,
476                                            snd_pcm_hw_params_t *sparams),
477                             int (*sprepare)(snd_pcm_t *pcm,
478                                             snd_pcm_hw_params_t *params),
479                             int (*schange)(snd_pcm_t *pcm,
480                                            snd_pcm_hw_params_t *params,
481                                            snd_pcm_hw_params_t *sparams),
482                             int (*sparams)(snd_pcm_t *pcm,
483                                            snd_pcm_hw_params_t *sparams));
484
485
486 void _snd_pcm_hw_params_any(snd_pcm_hw_params_t *params);
487 void _snd_pcm_hw_param_set_empty(snd_pcm_hw_params_t *params,
488                                  snd_pcm_hw_param_t var);
489 int _snd_pcm_hw_param_set_interval(snd_pcm_hw_params_t *params,
490                                    snd_pcm_hw_param_t var,
491                                    const snd_interval_t *val);
492 int _snd_pcm_hw_param_set_mask(snd_pcm_hw_params_t *params,
493                            snd_pcm_hw_param_t var, const snd_mask_t *mask);
494 int _snd_pcm_hw_param_first(snd_pcm_hw_params_t *params,
495                             snd_pcm_hw_param_t var);
496 int _snd_pcm_hw_param_last(snd_pcm_hw_params_t *params,
497                            snd_pcm_hw_param_t var);
498 int _snd_pcm_hw_param_set(snd_pcm_hw_params_t *params,
499                           snd_pcm_hw_param_t var, unsigned int val, int dir);
500 static inline int _snd_pcm_hw_params_set_format(snd_pcm_hw_params_t *params,
501                                                 snd_pcm_format_t val)
502 {
503         return _snd_pcm_hw_param_set(params, SND_PCM_HW_PARAM_FORMAT,
504                                      (unsigned long) val, 0);
505 }
506
507 static inline int _snd_pcm_hw_params_set_subformat(snd_pcm_hw_params_t *params,
508                                      snd_pcm_subformat_t val)
509 {
510         return _snd_pcm_hw_param_set(params, SND_PCM_HW_PARAM_SUBFORMAT,
511                                      (unsigned long) val, 0);
512 }
513
514 int _snd_pcm_hw_param_set_min(snd_pcm_hw_params_t *params,
515                               snd_pcm_hw_param_t var, unsigned int val, int dir);
516 int _snd_pcm_hw_param_set_max(snd_pcm_hw_params_t *params,
517                               snd_pcm_hw_param_t var, unsigned int val, int dir);
518 int _snd_pcm_hw_param_set_minmax(snd_pcm_hw_params_t *params,
519                                  snd_pcm_hw_param_t var,
520                                  unsigned int min, int mindir,
521                                  unsigned int max, int maxdir);
522 int _snd_pcm_hw_param_refine(snd_pcm_hw_params_t *params,
523                              snd_pcm_hw_param_t var,
524                              const snd_pcm_hw_params_t *src);
525 int _snd_pcm_hw_params_refine(snd_pcm_hw_params_t *params,
526                               unsigned int vars,
527                               const snd_pcm_hw_params_t *src);
528 int snd_pcm_hw_param_refine_near(snd_pcm_t *pcm,
529                                  snd_pcm_hw_params_t *params,
530                                  snd_pcm_hw_param_t var,
531                                  const snd_pcm_hw_params_t *src);
532 int snd_pcm_hw_param_refine_multiple(snd_pcm_t *pcm,
533                                      snd_pcm_hw_params_t *params,
534                                      snd_pcm_hw_param_t var,
535                                      const snd_pcm_hw_params_t *src);
536 int snd_pcm_hw_param_empty(const snd_pcm_hw_params_t *params,
537                            snd_pcm_hw_param_t var);
538 int snd_pcm_hw_param_always_eq(const snd_pcm_hw_params_t *params,
539                                snd_pcm_hw_param_t var,
540                                const snd_pcm_hw_params_t *params1);
541 int snd_pcm_hw_param_never_eq(const snd_pcm_hw_params_t *params,
542                               snd_pcm_hw_param_t var,
543                               const snd_pcm_hw_params_t *params1);
544 const snd_mask_t *snd_pcm_hw_param_get_mask(const snd_pcm_hw_params_t *params,
545                                               snd_pcm_hw_param_t var);
546 const snd_interval_t *snd_pcm_hw_param_get_interval(const snd_pcm_hw_params_t *params,
547                                                       snd_pcm_hw_param_t var);
548
549 int snd_pcm_hw_param_any(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
550                          snd_pcm_hw_param_t var);
551 int snd_pcm_hw_param_set_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
552                                  snd_set_mode_t mode,
553                                  snd_pcm_hw_param_t var);
554 int snd_pcm_hw_param_set_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
555                                snd_pcm_hw_param_t var, unsigned int *rval, int *dir);
556 int snd_pcm_hw_param_set_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
557                               snd_pcm_hw_param_t var, unsigned int *rval, int *dir);
558 int snd_pcm_hw_param_set_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
559                               snd_pcm_hw_param_t var, unsigned int *val, int *dir);
560 int snd_pcm_hw_param_set_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
561                              snd_set_mode_t mode,
562                              snd_pcm_hw_param_t var,
563                              unsigned int *val, int *dir);
564 int snd_pcm_hw_param_set_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
565                              snd_set_mode_t mode,
566                              snd_pcm_hw_param_t var, unsigned int *val, int *dir);
567 int snd_pcm_hw_param_set_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
568                                 snd_set_mode_t mode,
569                                 snd_pcm_hw_param_t var,
570                                 unsigned int *min, int *mindir,
571                                 unsigned int *max, int *maxdir);
572 int snd_pcm_hw_param_set(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
573                          snd_set_mode_t mode,
574                          snd_pcm_hw_param_t var, unsigned int val, int dir);
575 int snd_pcm_hw_param_set_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
576                               snd_set_mode_t mode,
577                               snd_pcm_hw_param_t var, const snd_mask_t *mask);
578 int snd_pcm_hw_param_get(const snd_pcm_hw_params_t *params, snd_pcm_hw_param_t var,
579                          unsigned int *val, int *dir);
580 int snd_pcm_hw_param_get_min(const snd_pcm_hw_params_t *params,
581                              snd_pcm_hw_param_t var,
582                              unsigned int *val, int *dir);
583 int snd_pcm_hw_param_get_max(const snd_pcm_hw_params_t *params,
584                              snd_pcm_hw_param_t var,
585                              unsigned int *val, int *dir);
586
587 #ifdef INTERNAL
588 snd_pcm_sframes_t INTERNAL(snd_pcm_forward)(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
589
590 int INTERNAL(snd_pcm_hw_params_get_access)(const snd_pcm_hw_params_t *params, snd_pcm_access_t *access);
591 int snd_pcm_hw_params_test_access(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access);
592 int snd_pcm_hw_params_set_access(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access);
593 int INTERNAL(snd_pcm_hw_params_set_access_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access);
594 int INTERNAL(snd_pcm_hw_params_set_access_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access);
595 int snd_pcm_hw_params_set_access_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask);
596 int snd_pcm_hw_params_get_access_mask(snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask);
597
598 int INTERNAL(snd_pcm_hw_params_get_format)(const snd_pcm_hw_params_t *params, snd_pcm_format_t *val);
599 int snd_pcm_hw_params_test_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t val);
600 int snd_pcm_hw_params_set_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t val);
601 int INTERNAL(snd_pcm_hw_params_set_format_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format);
602 int INTERNAL(snd_pcm_hw_params_set_format_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format);
603 int snd_pcm_hw_params_set_format_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask);
604 void snd_pcm_hw_params_get_format_mask(snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask);
605
606 int INTERNAL(snd_pcm_hw_params_get_subformat)(const snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat);
607 int snd_pcm_hw_params_test_subformat(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat);
608 int snd_pcm_hw_params_set_subformat(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat);
609 int INTERNAL(snd_pcm_hw_params_set_subformat_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat);
610 int INTERNAL(snd_pcm_hw_params_set_subformat_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat);
611 int snd_pcm_hw_params_set_subformat_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask);
612 void snd_pcm_hw_params_get_subformat_mask(snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask);
613
614 int INTERNAL(snd_pcm_hw_params_get_channels)(const snd_pcm_hw_params_t *params, unsigned int *val);
615 int INTERNAL(snd_pcm_hw_params_get_channels_min)(const snd_pcm_hw_params_t *params, unsigned int *val);
616 int INTERNAL(snd_pcm_hw_params_get_channels_max)(const snd_pcm_hw_params_t *params, unsigned int *val);
617 int snd_pcm_hw_params_test_channels(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val);
618 int snd_pcm_hw_params_set_channels(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val);
619 int snd_pcm_hw_params_set_channels_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val);
620 int snd_pcm_hw_params_set_channels_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val);
621 int snd_pcm_hw_params_set_channels_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, unsigned int *max);
622 int INTERNAL(snd_pcm_hw_params_set_channels_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val);
623 int INTERNAL(snd_pcm_hw_params_set_channels_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val);
624 int INTERNAL(snd_pcm_hw_params_set_channels_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val);
625
626 int INTERNAL(snd_pcm_hw_params_get_rate)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
627 int INTERNAL(snd_pcm_hw_params_get_rate_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
628 int INTERNAL(snd_pcm_hw_params_get_rate_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
629 int snd_pcm_hw_params_test_rate(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
630 int snd_pcm_hw_params_set_rate(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
631 int snd_pcm_hw_params_set_rate_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
632 int snd_pcm_hw_params_set_rate_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
633 int snd_pcm_hw_params_set_rate_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir);
634 int INTERNAL(snd_pcm_hw_params_set_rate_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
635 int INTERNAL(snd_pcm_hw_params_set_rate_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
636 int INTERNAL(snd_pcm_hw_params_set_rate_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
637
638 int INTERNAL(snd_pcm_hw_params_get_period_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
639 int INTERNAL(snd_pcm_hw_params_get_period_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
640 int INTERNAL(snd_pcm_hw_params_get_period_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
641 int snd_pcm_hw_params_test_period_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
642 int snd_pcm_hw_params_set_period_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
643 int snd_pcm_hw_params_set_period_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
644 int snd_pcm_hw_params_set_period_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
645 int snd_pcm_hw_params_set_period_time_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir);
646 int INTERNAL(snd_pcm_hw_params_set_period_time_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
647 int INTERNAL(snd_pcm_hw_params_set_period_time_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
648 int INTERNAL(snd_pcm_hw_params_set_period_time_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
649
650 int INTERNAL(snd_pcm_hw_params_get_period_size)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir);
651 int INTERNAL(snd_pcm_hw_params_get_period_size_min)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir);
652 int INTERNAL(snd_pcm_hw_params_get_period_size_max)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir);
653 int snd_pcm_hw_params_test_period_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val, int dir);
654 int snd_pcm_hw_params_set_period_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val, int dir);
655 int snd_pcm_hw_params_set_period_size_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir);
656 int snd_pcm_hw_params_set_period_size_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir);
657 int snd_pcm_hw_params_set_period_size_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *min, int *mindir, snd_pcm_uframes_t *max, int *maxdir);
658 int INTERNAL(snd_pcm_hw_params_set_period_size_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir);
659 int INTERNAL(snd_pcm_hw_params_set_period_size_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir);
660 int INTERNAL(snd_pcm_hw_params_set_period_size_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir);
661 int snd_pcm_hw_params_set_period_size_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
662
663 int INTERNAL(snd_pcm_hw_params_get_periods)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
664 int INTERNAL(snd_pcm_hw_params_get_periods_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
665 int INTERNAL(snd_pcm_hw_params_get_periods_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
666 int snd_pcm_hw_params_test_periods(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
667 int snd_pcm_hw_params_set_periods(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
668 int snd_pcm_hw_params_set_periods_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
669 int snd_pcm_hw_params_set_periods_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
670 int snd_pcm_hw_params_set_periods_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir);
671 int INTERNAL(snd_pcm_hw_params_set_periods_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
672 int INTERNAL(snd_pcm_hw_params_set_periods_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
673 int INTERNAL(snd_pcm_hw_params_set_periods_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
674 int snd_pcm_hw_params_set_periods_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
675
676 int INTERNAL(snd_pcm_hw_params_get_buffer_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
677 int INTERNAL(snd_pcm_hw_params_get_buffer_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
678 int INTERNAL(snd_pcm_hw_params_get_buffer_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
679 int snd_pcm_hw_params_test_buffer_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
680 int snd_pcm_hw_params_set_buffer_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
681 int snd_pcm_hw_params_set_buffer_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
682 int snd_pcm_hw_params_set_buffer_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
683 int snd_pcm_hw_params_set_buffer_time_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir);
684 int INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
685 int INTERNAL(snd_pcm_hw_params_set_buffer_time_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
686 int INTERNAL(snd_pcm_hw_params_set_buffer_time_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
687
688 int INTERNAL(snd_pcm_hw_params_get_buffer_size)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
689 int INTERNAL(snd_pcm_hw_params_get_buffer_size_min)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
690 int INTERNAL(snd_pcm_hw_params_get_buffer_size_max)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
691 int snd_pcm_hw_params_test_buffer_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val);
692 int snd_pcm_hw_params_set_buffer_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val);
693 int snd_pcm_hw_params_set_buffer_size_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
694 int snd_pcm_hw_params_set_buffer_size_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
695 int snd_pcm_hw_params_set_buffer_size_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *min, snd_pcm_uframes_t *max);
696 int INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
697 int INTERNAL(snd_pcm_hw_params_set_buffer_size_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
698 int INTERNAL(snd_pcm_hw_params_set_buffer_size_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
699
700 int INTERNAL(snd_pcm_hw_params_get_tick_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
701 int INTERNAL(snd_pcm_hw_params_get_tick_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
702 int INTERNAL(snd_pcm_hw_params_get_tick_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
703 int snd_pcm_hw_params_test_tick_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
704 int snd_pcm_hw_params_set_tick_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
705 int snd_pcm_hw_params_set_tick_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
706 int snd_pcm_hw_params_set_tick_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
707 int snd_pcm_hw_params_set_tick_time_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir);
708 int INTERNAL(snd_pcm_hw_params_set_tick_time_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
709 int INTERNAL(snd_pcm_hw_params_set_tick_time_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
710 int INTERNAL(snd_pcm_hw_params_set_tick_time_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
711
712 int snd_pcm_sw_params_set_tstamp_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_t val);
713 int INTERNAL(snd_pcm_sw_params_get_tstamp_mode)(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val);
714 int snd_pcm_sw_params_set_sleep_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, unsigned int val);
715 int INTERNAL(snd_pcm_sw_params_get_sleep_min)(const snd_pcm_sw_params_t *params, unsigned int *val);
716 int snd_pcm_sw_params_set_avail_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
717 int INTERNAL(snd_pcm_sw_params_get_avail_min)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val);
718 int snd_pcm_sw_params_set_xfer_align(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
719 int INTERNAL(snd_pcm_sw_params_get_xfer_align)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val);
720 int snd_pcm_sw_params_set_start_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
721 int INTERNAL(snd_pcm_sw_params_get_start_threshold)(const snd_pcm_sw_params_t *paramsm, snd_pcm_uframes_t *val);
722 int snd_pcm_sw_params_set_stop_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
723 int INTERNAL(snd_pcm_sw_params_get_stop_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val);
724 int snd_pcm_sw_params_set_silence_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
725 int INTERNAL(snd_pcm_sw_params_get_silence_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val);
726 int snd_pcm_sw_params_set_silence_size(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
727 int INTERNAL(snd_pcm_sw_params_get_silence_size)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val);
728 #endif /* INTERNAL */
729
730 const char *snd_pcm_hw_param_name(snd_pcm_hw_param_t param);
731 void snd_pcm_hw_param_dump(const snd_pcm_hw_params_t *params,
732                            snd_pcm_hw_param_t var, snd_output_t *out);
733 #if 0
734 int snd_pcm_hw_strategy_simple_near(snd_pcm_hw_strategy_t *strategy, int order,
735                                     snd_pcm_hw_param_t var,
736                                     unsigned int best,
737                                     unsigned int mul);
738 int snd_pcm_hw_strategy_simple_choices(snd_pcm_hw_strategy_t *strategy, int order,
739                                        snd_pcm_hw_param_t var,
740                                        unsigned int count,
741                                        snd_pcm_hw_strategy_simple_choices_list_t *choices);
742 #endif
743
744 #define SCONF_MANDATORY 1
745 #define SCONF_UNCHANGED 2
746
747 int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
748                        snd_config_t **pcm_conf, unsigned int count, ...);
749
750 #define SND_PCM_APPEND  (1<<8)
751
752 int snd_pcm_open_slave(snd_pcm_t **pcmp, snd_config_t *root,
753                        snd_config_t *conf, snd_pcm_stream_t stream,
754                        int mode, snd_config_t *parent_conf);
755 int snd_pcm_conf_generic_id(const char *id);
756
757 int snd_pcm_hw_open_fd(snd_pcm_t **pcmp, const char *name, int fd, int mmap_emulation, int sync_ptr_ioctl);
758
759 int snd_pcm_wait_nocheck(snd_pcm_t *pcm, int timeout);
760
761 const snd_config_t *snd_pcm_rate_get_default_converter(snd_config_t *root);
762
763 #define SND_PCM_HW_PARBIT_ACCESS        (1U << SND_PCM_HW_PARAM_ACCESS)
764 #define SND_PCM_HW_PARBIT_FORMAT        (1U << SND_PCM_HW_PARAM_FORMAT)
765 #define SND_PCM_HW_PARBIT_SUBFORMAT     (1U << SND_PCM_HW_PARAM_SUBFORMAT)
766 #define SND_PCM_HW_PARBIT_CHANNELS      (1U << SND_PCM_HW_PARAM_CHANNELS)
767 #define SND_PCM_HW_PARBIT_RATE          (1U << SND_PCM_HW_PARAM_RATE)
768 #define SND_PCM_HW_PARBIT_PERIOD_TIME   (1U << SND_PCM_HW_PARAM_PERIOD_TIME)
769 #define SND_PCM_HW_PARBIT_PERIOD_SIZE   (1U << SND_PCM_HW_PARAM_PERIOD_SIZE)
770 #define SND_PCM_HW_PARBIT_PERIODS       (1U << SND_PCM_HW_PARAM_PERIODS)
771 #define SND_PCM_HW_PARBIT_BUFFER_TIME   (1U << SND_PCM_HW_PARAM_BUFFER_TIME)
772 #define SND_PCM_HW_PARBIT_BUFFER_SIZE   (1U << SND_PCM_HW_PARAM_BUFFER_SIZE)
773 #define SND_PCM_HW_PARBIT_SAMPLE_BITS   (1U << SND_PCM_HW_PARAM_SAMPLE_BITS)
774 #define SND_PCM_HW_PARBIT_FRAME_BITS    (1U << SND_PCM_HW_PARAM_FRAME_BITS)
775 #define SND_PCM_HW_PARBIT_PERIOD_BYTES  (1U << SND_PCM_HW_PARAM_PERIOD_BYTES)
776 #define SND_PCM_HW_PARBIT_BUFFER_BYTES  (1U << SND_PCM_HW_PARAM_BUFFER_BYTES)
777 #define SND_PCM_HW_PARBIT_TICK_TIME     (1U << SND_PCM_HW_PARAM_TICK_TIME)
778
779
780 #define SND_PCM_ACCBIT_MMAP { ((1U << SND_PCM_ACCESS_MMAP_INTERLEAVED) | \
781                              (1U << SND_PCM_ACCESS_MMAP_NONINTERLEAVED) | \
782                              (1U << SND_PCM_ACCESS_MMAP_COMPLEX)) }
783 #define SND_PCM_ACCBIT_MMAPI { (1U << SND_PCM_ACCESS_MMAP_INTERLEAVED) }
784 #define SND_PCM_ACCBIT_MMAPN { (1U << SND_PCM_ACCESS_MMAP_NONINTERLEAVED) }
785 #define SND_PCM_ACCBIT_MMAPC { (1U << SND_PCM_ACCESS_MMAP_COMPLEX) }
786
787 #define SND_PCM_ACCBIT_SHM { ((1U << SND_PCM_ACCESS_MMAP_INTERLEAVED) | \
788                             (1U << SND_PCM_ACCESS_RW_INTERLEAVED) | \
789                             (1U << SND_PCM_ACCESS_MMAP_NONINTERLEAVED) | \
790                             (1U << SND_PCM_ACCESS_RW_NONINTERLEAVED)) }
791 #define SND_PCM_ACCBIT_SHMI { ((1U << SND_PCM_ACCESS_MMAP_INTERLEAVED) | \
792                              (1U << SND_PCM_ACCESS_RW_INTERLEAVED)) }
793 #define SND_PCM_ACCBIT_SHMN { ((1U << SND_PCM_ACCESS_MMAP_NONINTERLEAVED) | \
794                              (1U << SND_PCM_ACCESS_RW_NONINTERLEAVED)) }
795
796 #define SND_PCM_FMTBIT_LINEAR \
797         { ((1U << SND_PCM_FORMAT_S8) | \
798          (1U << SND_PCM_FORMAT_U8) | \
799          (1U << SND_PCM_FORMAT_S16_LE) | \
800          (1U << SND_PCM_FORMAT_S16_BE) | \
801          (1U << SND_PCM_FORMAT_U16_LE) | \
802          (1U << SND_PCM_FORMAT_U16_BE) | \
803          (1U << SND_PCM_FORMAT_S24_LE) | \
804          (1U << SND_PCM_FORMAT_S24_BE) | \
805          (1U << SND_PCM_FORMAT_U24_LE) | \
806          (1U << SND_PCM_FORMAT_U24_BE) | \
807          (1U << SND_PCM_FORMAT_S32_LE) | \
808          (1U << SND_PCM_FORMAT_S32_BE) | \
809          (1U << SND_PCM_FORMAT_U32_LE) | \
810          (1U << SND_PCM_FORMAT_U32_BE)), \
811         ((1U << (SND_PCM_FORMAT_S24_3LE - 32)) | \
812          (1U << (SND_PCM_FORMAT_U24_3LE - 32)) | \
813          (1U << (SND_PCM_FORMAT_S24_3BE - 32)) | \
814          (1U << (SND_PCM_FORMAT_U24_3BE - 32)) | \
815          (1U << (SND_PCM_FORMAT_S20_3LE - 32)) | \
816          (1U << (SND_PCM_FORMAT_U20_3LE - 32)) | \
817          (1U << (SND_PCM_FORMAT_S20_3BE - 32)) | \
818          (1U << (SND_PCM_FORMAT_U20_3BE - 32)) | \
819          (1U << (SND_PCM_FORMAT_S18_3LE - 32)) | \
820          (1U << (SND_PCM_FORMAT_U18_3LE - 32)) | \
821          (1U << (SND_PCM_FORMAT_S18_3BE - 32)) | \
822          (1U << (SND_PCM_FORMAT_U18_3BE - 32))) }
823         
824
825 #define SND_PCM_FMTBIT_FLOAT \
826         { ((1U << SND_PCM_FORMAT_FLOAT_LE) | \
827          (1U << SND_PCM_FORMAT_FLOAT_BE) | \
828          (1U << SND_PCM_FORMAT_FLOAT64_LE) | \
829          (1U << SND_PCM_FORMAT_FLOAT64_BE)) }
830
831
832 typedef union snd_tmp_float {
833         float f;
834         int32_t i;
835 } snd_tmp_float_t;
836
837 typedef union snd_tmp_double {
838         double d;
839         int64_t l;
840 } snd_tmp_double_t;