Blame view
include/sound/pcm_params.h
8.18 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#ifndef __SOUND_PCM_PARAMS_H #define __SOUND_PCM_PARAMS_H /* * PCM params helpers * Copyright (c) by Abramo Bagnara <abramo@alsa-project.org> * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ |
e88e8ae63 [ALSA] Move OSS-s... |
24 25 26 27 28 29 30 31 |
int snd_pcm_hw_param_first(struct snd_pcm_substream *pcm, struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var, int *dir); int snd_pcm_hw_param_last(struct snd_pcm_substream *pcm, struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var, int *dir); int snd_pcm_hw_param_value(const struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var, int *dir); |
1da177e4c Linux-2.6.12-rc2 |
32 |
|
1da177e4c Linux-2.6.12-rc2 |
33 34 35 36 |
#define SNDRV_MASK_BITS 64 /* we use so far 64bits only */ #define SNDRV_MASK_SIZE (SNDRV_MASK_BITS / 32) #define MASK_OFS(i) ((i) >> 5) #define MASK_BIT(i) (1U << ((i) & 31)) |
9bb22e215 [ALSA] Clean up u... |
37 |
static inline unsigned int ld2(u_int32_t v) |
1da177e4c Linux-2.6.12-rc2 |
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
{ unsigned r = 0; if (v >= 0x10000) { v >>= 16; r += 16; } if (v >= 0x100) { v >>= 8; r += 8; } if (v >= 0x10) { v >>= 4; r += 4; } if (v >= 4) { v >>= 2; r += 2; } if (v >= 2) r++; return r; } |
9bb22e215 [ALSA] Clean up u... |
61 |
static inline size_t snd_mask_sizeof(void) |
1da177e4c Linux-2.6.12-rc2 |
62 |
{ |
877211f5e [ALSA] Remove xxx... |
63 |
return sizeof(struct snd_mask); |
1da177e4c Linux-2.6.12-rc2 |
64 |
} |
9bb22e215 [ALSA] Clean up u... |
65 |
static inline void snd_mask_none(struct snd_mask *mask) |
1da177e4c Linux-2.6.12-rc2 |
66 67 68 |
{ memset(mask, 0, sizeof(*mask)); } |
9bb22e215 [ALSA] Clean up u... |
69 |
static inline void snd_mask_any(struct snd_mask *mask) |
1da177e4c Linux-2.6.12-rc2 |
70 71 72 |
{ memset(mask, 0xff, SNDRV_MASK_SIZE * sizeof(u_int32_t)); } |
9bb22e215 [ALSA] Clean up u... |
73 |
static inline int snd_mask_empty(const struct snd_mask *mask) |
1da177e4c Linux-2.6.12-rc2 |
74 75 76 77 78 79 80 |
{ int i; for (i = 0; i < SNDRV_MASK_SIZE; i++) if (mask->bits[i]) return 0; return 1; } |
9bb22e215 [ALSA] Clean up u... |
81 |
static inline unsigned int snd_mask_min(const struct snd_mask *mask) |
1da177e4c Linux-2.6.12-rc2 |
82 83 |
{ int i; |
1da177e4c Linux-2.6.12-rc2 |
84 85 86 87 88 89 |
for (i = 0; i < SNDRV_MASK_SIZE; i++) { if (mask->bits[i]) return ffs(mask->bits[i]) - 1 + (i << 5); } return 0; } |
9bb22e215 [ALSA] Clean up u... |
90 |
static inline unsigned int snd_mask_max(const struct snd_mask *mask) |
1da177e4c Linux-2.6.12-rc2 |
91 92 |
{ int i; |
1da177e4c Linux-2.6.12-rc2 |
93 94 95 96 97 98 |
for (i = SNDRV_MASK_SIZE - 1; i >= 0; i--) { if (mask->bits[i]) return ld2(mask->bits[i]) + (i << 5); } return 0; } |
9bb22e215 [ALSA] Clean up u... |
99 |
static inline void snd_mask_set(struct snd_mask *mask, unsigned int val) |
1da177e4c Linux-2.6.12-rc2 |
100 |
{ |
1da177e4c Linux-2.6.12-rc2 |
101 102 |
mask->bits[MASK_OFS(val)] |= MASK_BIT(val); } |
9bb22e215 [ALSA] Clean up u... |
103 |
static inline void snd_mask_reset(struct snd_mask *mask, unsigned int val) |
1da177e4c Linux-2.6.12-rc2 |
104 |
{ |
1da177e4c Linux-2.6.12-rc2 |
105 106 |
mask->bits[MASK_OFS(val)] &= ~MASK_BIT(val); } |
9bb22e215 [ALSA] Clean up u... |
107 108 |
static inline void snd_mask_set_range(struct snd_mask *mask, unsigned int from, unsigned int to) |
1da177e4c Linux-2.6.12-rc2 |
109 110 |
{ unsigned int i; |
1da177e4c Linux-2.6.12-rc2 |
111 112 113 |
for (i = from; i <= to; i++) mask->bits[MASK_OFS(i)] |= MASK_BIT(i); } |
9bb22e215 [ALSA] Clean up u... |
114 115 |
static inline void snd_mask_reset_range(struct snd_mask *mask, unsigned int from, unsigned int to) |
1da177e4c Linux-2.6.12-rc2 |
116 117 |
{ unsigned int i; |
1da177e4c Linux-2.6.12-rc2 |
118 119 120 |
for (i = from; i <= to; i++) mask->bits[MASK_OFS(i)] &= ~MASK_BIT(i); } |
9bb22e215 [ALSA] Clean up u... |
121 |
static inline void snd_mask_leave(struct snd_mask *mask, unsigned int val) |
1da177e4c Linux-2.6.12-rc2 |
122 123 |
{ unsigned int v; |
1da177e4c Linux-2.6.12-rc2 |
124 125 126 127 |
v = mask->bits[MASK_OFS(val)] & MASK_BIT(val); snd_mask_none(mask); mask->bits[MASK_OFS(val)] = v; } |
9bb22e215 [ALSA] Clean up u... |
128 129 |
static inline void snd_mask_intersect(struct snd_mask *mask, const struct snd_mask *v) |
1da177e4c Linux-2.6.12-rc2 |
130 131 132 133 134 |
{ int i; for (i = 0; i < SNDRV_MASK_SIZE; i++) mask->bits[i] &= v->bits[i]; } |
9bb22e215 [ALSA] Clean up u... |
135 136 |
static inline int snd_mask_eq(const struct snd_mask *mask, const struct snd_mask *v) |
1da177e4c Linux-2.6.12-rc2 |
137 138 139 |
{ return ! memcmp(mask, v, SNDRV_MASK_SIZE * sizeof(u_int32_t)); } |
9bb22e215 [ALSA] Clean up u... |
140 141 |
static inline void snd_mask_copy(struct snd_mask *mask, const struct snd_mask *v) |
1da177e4c Linux-2.6.12-rc2 |
142 143 144 |
{ *mask = *v; } |
9bb22e215 [ALSA] Clean up u... |
145 |
static inline int snd_mask_test(const struct snd_mask *mask, unsigned int val) |
1da177e4c Linux-2.6.12-rc2 |
146 |
{ |
1da177e4c Linux-2.6.12-rc2 |
147 148 |
return mask->bits[MASK_OFS(val)] & MASK_BIT(val); } |
9bb22e215 [ALSA] Clean up u... |
149 |
static inline int snd_mask_single(const struct snd_mask *mask) |
1da177e4c Linux-2.6.12-rc2 |
150 151 |
{ int i, c = 0; |
1da177e4c Linux-2.6.12-rc2 |
152 153 154 155 156 157 158 159 160 161 162 |
for (i = 0; i < SNDRV_MASK_SIZE; i++) { if (! mask->bits[i]) continue; if (mask->bits[i] & (mask->bits[i] - 1)) return 0; if (c) return 0; c++; } return 1; } |
9bb22e215 [ALSA] Clean up u... |
163 164 |
static inline int snd_mask_refine(struct snd_mask *mask, const struct snd_mask *v) |
1da177e4c Linux-2.6.12-rc2 |
165 |
{ |
877211f5e [ALSA] Remove xxx... |
166 |
struct snd_mask old; |
1da177e4c Linux-2.6.12-rc2 |
167 168 169 170 171 172 |
snd_mask_copy(&old, mask); snd_mask_intersect(mask, v); if (snd_mask_empty(mask)) return -EINVAL; return !snd_mask_eq(mask, &old); } |
9bb22e215 [ALSA] Clean up u... |
173 |
static inline int snd_mask_refine_first(struct snd_mask *mask) |
1da177e4c Linux-2.6.12-rc2 |
174 |
{ |
1da177e4c Linux-2.6.12-rc2 |
175 176 177 178 179 |
if (snd_mask_single(mask)) return 0; snd_mask_leave(mask, snd_mask_min(mask)); return 1; } |
9bb22e215 [ALSA] Clean up u... |
180 |
static inline int snd_mask_refine_last(struct snd_mask *mask) |
1da177e4c Linux-2.6.12-rc2 |
181 |
{ |
1da177e4c Linux-2.6.12-rc2 |
182 183 184 185 186 |
if (snd_mask_single(mask)) return 0; snd_mask_leave(mask, snd_mask_max(mask)); return 1; } |
9bb22e215 [ALSA] Clean up u... |
187 |
static inline int snd_mask_refine_min(struct snd_mask *mask, unsigned int val) |
1da177e4c Linux-2.6.12-rc2 |
188 |
{ |
1da177e4c Linux-2.6.12-rc2 |
189 190 191 192 193 194 195 |
if (snd_mask_min(mask) >= val) return 0; snd_mask_reset_range(mask, 0, val - 1); if (snd_mask_empty(mask)) return -EINVAL; return 1; } |
9bb22e215 [ALSA] Clean up u... |
196 |
static inline int snd_mask_refine_max(struct snd_mask *mask, unsigned int val) |
1da177e4c Linux-2.6.12-rc2 |
197 |
{ |
1da177e4c Linux-2.6.12-rc2 |
198 199 200 201 202 203 204 |
if (snd_mask_max(mask) <= val) return 0; snd_mask_reset_range(mask, val + 1, SNDRV_MASK_BITS); if (snd_mask_empty(mask)) return -EINVAL; return 1; } |
9bb22e215 [ALSA] Clean up u... |
205 |
static inline int snd_mask_refine_set(struct snd_mask *mask, unsigned int val) |
1da177e4c Linux-2.6.12-rc2 |
206 207 |
{ int changed; |
1da177e4c Linux-2.6.12-rc2 |
208 209 210 211 212 213 |
changed = !snd_mask_single(mask); snd_mask_leave(mask, val); if (snd_mask_empty(mask)) return -EINVAL; return changed; } |
9bb22e215 [ALSA] Clean up u... |
214 |
static inline int snd_mask_value(const struct snd_mask *mask) |
1da177e4c Linux-2.6.12-rc2 |
215 |
{ |
1da177e4c Linux-2.6.12-rc2 |
216 217 |
return snd_mask_min(mask); } |
9bb22e215 [ALSA] Clean up u... |
218 |
static inline void snd_interval_any(struct snd_interval *i) |
1da177e4c Linux-2.6.12-rc2 |
219 220 221 222 223 224 225 226 |
{ i->min = 0; i->openmin = 0; i->max = UINT_MAX; i->openmax = 0; i->integer = 0; i->empty = 0; } |
9bb22e215 [ALSA] Clean up u... |
227 |
static inline void snd_interval_none(struct snd_interval *i) |
1da177e4c Linux-2.6.12-rc2 |
228 229 230 |
{ i->empty = 1; } |
9bb22e215 [ALSA] Clean up u... |
231 |
static inline int snd_interval_checkempty(const struct snd_interval *i) |
1da177e4c Linux-2.6.12-rc2 |
232 233 234 235 |
{ return (i->min > i->max || (i->min == i->max && (i->openmin || i->openmax))); } |
9bb22e215 [ALSA] Clean up u... |
236 |
static inline int snd_interval_empty(const struct snd_interval *i) |
1da177e4c Linux-2.6.12-rc2 |
237 238 239 |
{ return i->empty; } |
9bb22e215 [ALSA] Clean up u... |
240 |
static inline int snd_interval_single(const struct snd_interval *i) |
1da177e4c Linux-2.6.12-rc2 |
241 |
{ |
1da177e4c Linux-2.6.12-rc2 |
242 243 244 |
return (i->min == i->max || (i->min + 1 == i->max && i->openmax)); } |
9bb22e215 [ALSA] Clean up u... |
245 |
static inline int snd_interval_value(const struct snd_interval *i) |
1da177e4c Linux-2.6.12-rc2 |
246 |
{ |
1da177e4c Linux-2.6.12-rc2 |
247 248 |
return i->min; } |
9bb22e215 [ALSA] Clean up u... |
249 |
static inline int snd_interval_min(const struct snd_interval *i) |
1da177e4c Linux-2.6.12-rc2 |
250 |
{ |
1da177e4c Linux-2.6.12-rc2 |
251 252 |
return i->min; } |
9bb22e215 [ALSA] Clean up u... |
253 |
static inline int snd_interval_max(const struct snd_interval *i) |
1da177e4c Linux-2.6.12-rc2 |
254 255 |
{ unsigned int v; |
1da177e4c Linux-2.6.12-rc2 |
256 257 258 259 260 |
v = i->max; if (i->openmax) v--; return v; } |
9bb22e215 [ALSA] Clean up u... |
261 |
static inline int snd_interval_test(const struct snd_interval *i, unsigned int val) |
1da177e4c Linux-2.6.12-rc2 |
262 263 264 265 |
{ return !((i->min > val || (i->min == val && i->openmin) || i->max < val || (i->max == val && i->openmax))); } |
9bb22e215 [ALSA] Clean up u... |
266 |
static inline void snd_interval_copy(struct snd_interval *d, const struct snd_interval *s) |
1da177e4c Linux-2.6.12-rc2 |
267 268 269 |
{ *d = *s; } |
9bb22e215 [ALSA] Clean up u... |
270 |
static inline int snd_interval_setinteger(struct snd_interval *i) |
1da177e4c Linux-2.6.12-rc2 |
271 272 273 274 275 276 277 278 |
{ if (i->integer) return 0; if (i->openmin && i->openmax && i->min == i->max) return -EINVAL; i->integer = 1; return 1; } |
9bb22e215 [ALSA] Clean up u... |
279 |
static inline int snd_interval_eq(const struct snd_interval *i1, const struct snd_interval *i2) |
1da177e4c Linux-2.6.12-rc2 |
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
{ if (i1->empty) return i2->empty; if (i2->empty) return i1->empty; return i1->min == i2->min && i1->openmin == i2->openmin && i1->max == i2->max && i1->openmax == i2->openmax; } static inline unsigned int add(unsigned int a, unsigned int b) { if (a >= UINT_MAX - b) return UINT_MAX; return a + b; } static inline unsigned int sub(unsigned int a, unsigned int b) { if (a > b) return a - b; return 0; } |
b51beb756 ALSA: Make pcm.h ... |
302 303 304 305 306 307 |
#define params_access(p) ((__force snd_pcm_access_t)\ snd_mask_min(hw_param_mask_c((p), SNDRV_PCM_HW_PARAM_ACCESS))) #define params_format(p) ((__force snd_pcm_format_t)\ snd_mask_min(hw_param_mask_c((p), SNDRV_PCM_HW_PARAM_FORMAT))) #define params_subformat(p) \ snd_mask_min(hw_param_mask_c((p), SNDRV_PCM_HW_PARAM_SUBFORMAT)) |
1da177e4c Linux-2.6.12-rc2 |
308 |
|
b51beb756 ALSA: Make pcm.h ... |
309 310 311 312 313 314 315 316 317 |
static inline unsigned int params_period_bytes(const struct snd_pcm_hw_params *p) { return (params_period_size(p) * snd_pcm_format_physical_width(params_format(p)) * params_channels(p)) / 8; } #endif /* __SOUND_PCM_PARAMS_H */ |