1 #ifndef __SOUND_PCM_PARAMS_H
2 #define __SOUND_PCM_PARAMS_H
6 * Copyright (c) by Abramo Bagnara <abramo@alsa-project.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 extern int snd_pcm_hw_param_mask(struct snd_pcm_substream *pcm, struct snd_pcm_hw_params *params,
26 snd_pcm_hw_param_t var, const struct snd_mask *val);
27 extern unsigned int snd_pcm_hw_param_value_min(const struct snd_pcm_hw_params *params,
28 snd_pcm_hw_param_t var, int *dir);
29 extern unsigned int snd_pcm_hw_param_value_max(const struct snd_pcm_hw_params *params,
30 snd_pcm_hw_param_t var, int *dir);
31 extern int _snd_pcm_hw_param_min(struct snd_pcm_hw_params *params,
32 snd_pcm_hw_param_t var, unsigned int val, int dir);
33 extern int _snd_pcm_hw_param_setinteger(struct snd_pcm_hw_params *params,
34 snd_pcm_hw_param_t var);
35 extern int _snd_pcm_hw_param_set(struct snd_pcm_hw_params *params,
36 snd_pcm_hw_param_t var, unsigned int val, int dir);
38 #define SNDRV_MASK_BITS 64 /* we use so far 64bits only */
39 #define SNDRV_MASK_SIZE (SNDRV_MASK_BITS / 32)
40 #define MASK_OFS(i) ((i) >> 5)
41 #define MASK_BIT(i) (1U << ((i) & 31))
43 static inline unsigned int ld2(u_int32_t v)
68 static inline size_t snd_mask_sizeof(void)
70 return sizeof(struct snd_mask);
73 static inline void snd_mask_none(struct snd_mask *mask)
75 memset(mask, 0, sizeof(*mask));
78 static inline void snd_mask_any(struct snd_mask *mask)
80 memset(mask, 0xff, SNDRV_MASK_SIZE * sizeof(u_int32_t));
83 static inline int snd_mask_empty(const struct snd_mask *mask)
86 for (i = 0; i < SNDRV_MASK_SIZE; i++)
92 static inline unsigned int snd_mask_min(const struct snd_mask *mask)
95 for (i = 0; i < SNDRV_MASK_SIZE; i++) {
97 return ffs(mask->bits[i]) - 1 + (i << 5);
102 static inline unsigned int snd_mask_max(const struct snd_mask *mask)
105 for (i = SNDRV_MASK_SIZE - 1; i >= 0; i--) {
107 return ld2(mask->bits[i]) + (i << 5);
112 static inline void snd_mask_set(struct snd_mask *mask, unsigned int val)
114 mask->bits[MASK_OFS(val)] |= MASK_BIT(val);
117 static inline void snd_mask_reset(struct snd_mask *mask, unsigned int val)
119 mask->bits[MASK_OFS(val)] &= ~MASK_BIT(val);
122 static inline void snd_mask_set_range(struct snd_mask *mask,
123 unsigned int from, unsigned int to)
126 for (i = from; i <= to; i++)
127 mask->bits[MASK_OFS(i)] |= MASK_BIT(i);
130 static inline void snd_mask_reset_range(struct snd_mask *mask,
131 unsigned int from, unsigned int to)
134 for (i = from; i <= to; i++)
135 mask->bits[MASK_OFS(i)] &= ~MASK_BIT(i);
138 static inline void snd_mask_leave(struct snd_mask *mask, unsigned int val)
141 v = mask->bits[MASK_OFS(val)] & MASK_BIT(val);
143 mask->bits[MASK_OFS(val)] = v;
146 static inline void snd_mask_intersect(struct snd_mask *mask,
147 const struct snd_mask *v)
150 for (i = 0; i < SNDRV_MASK_SIZE; i++)
151 mask->bits[i] &= v->bits[i];
154 static inline int snd_mask_eq(const struct snd_mask *mask,
155 const struct snd_mask *v)
157 return ! memcmp(mask, v, SNDRV_MASK_SIZE * sizeof(u_int32_t));
160 static inline void snd_mask_copy(struct snd_mask *mask,
161 const struct snd_mask *v)
166 static inline int snd_mask_test(const struct snd_mask *mask, unsigned int val)
168 return mask->bits[MASK_OFS(val)] & MASK_BIT(val);
171 static inline int snd_mask_single(const struct snd_mask *mask)
174 for (i = 0; i < SNDRV_MASK_SIZE; i++) {
177 if (mask->bits[i] & (mask->bits[i] - 1))
186 static inline int snd_mask_refine(struct snd_mask *mask,
187 const struct snd_mask *v)
190 snd_mask_copy(&old, mask);
191 snd_mask_intersect(mask, v);
192 if (snd_mask_empty(mask))
194 return !snd_mask_eq(mask, &old);
197 static inline int snd_mask_refine_first(struct snd_mask *mask)
199 if (snd_mask_single(mask))
201 snd_mask_leave(mask, snd_mask_min(mask));
205 static inline int snd_mask_refine_last(struct snd_mask *mask)
207 if (snd_mask_single(mask))
209 snd_mask_leave(mask, snd_mask_max(mask));
213 static inline int snd_mask_refine_min(struct snd_mask *mask, unsigned int val)
215 if (snd_mask_min(mask) >= val)
217 snd_mask_reset_range(mask, 0, val - 1);
218 if (snd_mask_empty(mask))
223 static inline int snd_mask_refine_max(struct snd_mask *mask, unsigned int val)
225 if (snd_mask_max(mask) <= val)
227 snd_mask_reset_range(mask, val + 1, SNDRV_MASK_BITS);
228 if (snd_mask_empty(mask))
233 static inline int snd_mask_refine_set(struct snd_mask *mask, unsigned int val)
236 changed = !snd_mask_single(mask);
237 snd_mask_leave(mask, val);
238 if (snd_mask_empty(mask))
243 static inline int snd_mask_value(const struct snd_mask *mask)
245 return snd_mask_min(mask);
248 static inline void snd_interval_any(struct snd_interval *i)
258 static inline void snd_interval_none(struct snd_interval *i)
263 static inline int snd_interval_checkempty(const struct snd_interval *i)
265 return (i->min > i->max ||
266 (i->min == i->max && (i->openmin || i->openmax)));
269 static inline int snd_interval_empty(const struct snd_interval *i)
274 static inline int snd_interval_single(const struct snd_interval *i)
276 return (i->min == i->max ||
277 (i->min + 1 == i->max && i->openmax));
280 static inline int snd_interval_value(const struct snd_interval *i)
285 static inline int snd_interval_min(const struct snd_interval *i)
290 static inline int snd_interval_max(const struct snd_interval *i)
299 static inline int snd_interval_test(const struct snd_interval *i, unsigned int val)
301 return !((i->min > val || (i->min == val && i->openmin) ||
302 i->max < val || (i->max == val && i->openmax)));
305 static inline void snd_interval_copy(struct snd_interval *d, const struct snd_interval *s)
310 static inline int snd_interval_setinteger(struct snd_interval *i)
314 if (i->openmin && i->openmax && i->min == i->max)
320 static inline int snd_interval_eq(const struct snd_interval *i1, const struct snd_interval *i2)
326 return i1->min == i2->min && i1->openmin == i2->openmin &&
327 i1->max == i2->max && i1->openmax == i2->openmax;
330 static inline unsigned int add(unsigned int a, unsigned int b)
332 if (a >= UINT_MAX - b)
337 static inline unsigned int sub(unsigned int a, unsigned int b)
344 #endif /* __SOUND_PCM_PARAMS_H */