aboutsummaryrefslogtreecommitdiffstats
path: root/include/sound
diff options
context:
space:
mode:
Diffstat (limited to 'include/sound')
-rw-r--r--include/sound/pcm_params.h105
1 files changed, 42 insertions, 63 deletions
diff --git a/include/sound/pcm_params.h b/include/sound/pcm_params.h
index fb18aef77341..e3bebd98e1ce 100644
--- a/include/sound/pcm_params.h
+++ b/include/sound/pcm_params.h
@@ -35,16 +35,12 @@ extern int _snd_pcm_hw_param_setinteger(struct snd_pcm_hw_params *params,
35extern int _snd_pcm_hw_param_set(struct snd_pcm_hw_params *params, 35extern int _snd_pcm_hw_param_set(struct snd_pcm_hw_params *params,
36 snd_pcm_hw_param_t var, unsigned int val, int dir); 36 snd_pcm_hw_param_t var, unsigned int val, int dir);
37 37
38/* To share the same code we have alsa-lib */
39#define INLINE static inline
40#define assert(a) (void)(a)
41
42#define SNDRV_MASK_BITS 64 /* we use so far 64bits only */ 38#define SNDRV_MASK_BITS 64 /* we use so far 64bits only */
43#define SNDRV_MASK_SIZE (SNDRV_MASK_BITS / 32) 39#define SNDRV_MASK_SIZE (SNDRV_MASK_BITS / 32)
44#define MASK_OFS(i) ((i) >> 5) 40#define MASK_OFS(i) ((i) >> 5)
45#define MASK_BIT(i) (1U << ((i) & 31)) 41#define MASK_BIT(i) (1U << ((i) & 31))
46 42
47INLINE unsigned int ld2(u_int32_t v) 43static inline unsigned int ld2(u_int32_t v)
48{ 44{
49 unsigned r = 0; 45 unsigned r = 0;
50 46
@@ -69,22 +65,22 @@ INLINE unsigned int ld2(u_int32_t v)
69 return r; 65 return r;
70} 66}
71 67
72INLINE size_t snd_mask_sizeof(void) 68static inline size_t snd_mask_sizeof(void)
73{ 69{
74 return sizeof(struct snd_mask); 70 return sizeof(struct snd_mask);
75} 71}
76 72
77INLINE void snd_mask_none(struct snd_mask *mask) 73static inline void snd_mask_none(struct snd_mask *mask)
78{ 74{
79 memset(mask, 0, sizeof(*mask)); 75 memset(mask, 0, sizeof(*mask));
80} 76}
81 77
82INLINE void snd_mask_any(struct snd_mask *mask) 78static inline void snd_mask_any(struct snd_mask *mask)
83{ 79{
84 memset(mask, 0xff, SNDRV_MASK_SIZE * sizeof(u_int32_t)); 80 memset(mask, 0xff, SNDRV_MASK_SIZE * sizeof(u_int32_t));
85} 81}
86 82
87INLINE int snd_mask_empty(const struct snd_mask *mask) 83static inline int snd_mask_empty(const struct snd_mask *mask)
88{ 84{
89 int i; 85 int i;
90 for (i = 0; i < SNDRV_MASK_SIZE; i++) 86 for (i = 0; i < SNDRV_MASK_SIZE; i++)
@@ -93,10 +89,9 @@ INLINE int snd_mask_empty(const struct snd_mask *mask)
93 return 1; 89 return 1;
94} 90}
95 91
96INLINE unsigned int snd_mask_min(const struct snd_mask *mask) 92static inline unsigned int snd_mask_min(const struct snd_mask *mask)
97{ 93{
98 int i; 94 int i;
99 assert(!snd_mask_empty(mask));
100 for (i = 0; i < SNDRV_MASK_SIZE; i++) { 95 for (i = 0; i < SNDRV_MASK_SIZE; i++) {
101 if (mask->bits[i]) 96 if (mask->bits[i])
102 return ffs(mask->bits[i]) - 1 + (i << 5); 97 return ffs(mask->bits[i]) - 1 + (i << 5);
@@ -104,10 +99,9 @@ INLINE unsigned int snd_mask_min(const struct snd_mask *mask)
104 return 0; 99 return 0;
105} 100}
106 101
107INLINE unsigned int snd_mask_max(const struct snd_mask *mask) 102static inline unsigned int snd_mask_max(const struct snd_mask *mask)
108{ 103{
109 int i; 104 int i;
110 assert(!snd_mask_empty(mask));
111 for (i = SNDRV_MASK_SIZE - 1; i >= 0; i--) { 105 for (i = SNDRV_MASK_SIZE - 1; i >= 0; i--) {
112 if (mask->bits[i]) 106 if (mask->bits[i])
113 return ld2(mask->bits[i]) + (i << 5); 107 return ld2(mask->bits[i]) + (i << 5);
@@ -115,70 +109,68 @@ INLINE unsigned int snd_mask_max(const struct snd_mask *mask)
115 return 0; 109 return 0;
116} 110}
117 111
118INLINE void snd_mask_set(struct snd_mask *mask, unsigned int val) 112static inline void snd_mask_set(struct snd_mask *mask, unsigned int val)
119{ 113{
120 assert(val <= SNDRV_MASK_BITS);
121 mask->bits[MASK_OFS(val)] |= MASK_BIT(val); 114 mask->bits[MASK_OFS(val)] |= MASK_BIT(val);
122} 115}
123 116
124INLINE void snd_mask_reset(struct snd_mask *mask, unsigned int val) 117static inline void snd_mask_reset(struct snd_mask *mask, unsigned int val)
125{ 118{
126 assert(val <= SNDRV_MASK_BITS);
127 mask->bits[MASK_OFS(val)] &= ~MASK_BIT(val); 119 mask->bits[MASK_OFS(val)] &= ~MASK_BIT(val);
128} 120}
129 121
130INLINE void snd_mask_set_range(struct snd_mask *mask, unsigned int from, unsigned int to) 122static inline void snd_mask_set_range(struct snd_mask *mask,
123 unsigned int from, unsigned int to)
131{ 124{
132 unsigned int i; 125 unsigned int i;
133 assert(to <= SNDRV_MASK_BITS && from <= to);
134 for (i = from; i <= to; i++) 126 for (i = from; i <= to; i++)
135 mask->bits[MASK_OFS(i)] |= MASK_BIT(i); 127 mask->bits[MASK_OFS(i)] |= MASK_BIT(i);
136} 128}
137 129
138INLINE void snd_mask_reset_range(struct snd_mask *mask, unsigned int from, unsigned int to) 130static inline void snd_mask_reset_range(struct snd_mask *mask,
131 unsigned int from, unsigned int to)
139{ 132{
140 unsigned int i; 133 unsigned int i;
141 assert(to <= SNDRV_MASK_BITS && from <= to);
142 for (i = from; i <= to; i++) 134 for (i = from; i <= to; i++)
143 mask->bits[MASK_OFS(i)] &= ~MASK_BIT(i); 135 mask->bits[MASK_OFS(i)] &= ~MASK_BIT(i);
144} 136}
145 137
146INLINE void snd_mask_leave(struct snd_mask *mask, unsigned int val) 138static inline void snd_mask_leave(struct snd_mask *mask, unsigned int val)
147{ 139{
148 unsigned int v; 140 unsigned int v;
149 assert(val <= SNDRV_MASK_BITS);
150 v = mask->bits[MASK_OFS(val)] & MASK_BIT(val); 141 v = mask->bits[MASK_OFS(val)] & MASK_BIT(val);
151 snd_mask_none(mask); 142 snd_mask_none(mask);
152 mask->bits[MASK_OFS(val)] = v; 143 mask->bits[MASK_OFS(val)] = v;
153} 144}
154 145
155INLINE void snd_mask_intersect(struct snd_mask *mask, const struct snd_mask *v) 146static inline void snd_mask_intersect(struct snd_mask *mask,
147 const struct snd_mask *v)
156{ 148{
157 int i; 149 int i;
158 for (i = 0; i < SNDRV_MASK_SIZE; i++) 150 for (i = 0; i < SNDRV_MASK_SIZE; i++)
159 mask->bits[i] &= v->bits[i]; 151 mask->bits[i] &= v->bits[i];
160} 152}
161 153
162INLINE int snd_mask_eq(const struct snd_mask *mask, const struct snd_mask *v) 154static inline int snd_mask_eq(const struct snd_mask *mask,
155 const struct snd_mask *v)
163{ 156{
164 return ! memcmp(mask, v, SNDRV_MASK_SIZE * sizeof(u_int32_t)); 157 return ! memcmp(mask, v, SNDRV_MASK_SIZE * sizeof(u_int32_t));
165} 158}
166 159
167INLINE void snd_mask_copy(struct snd_mask *mask, const struct snd_mask *v) 160static inline void snd_mask_copy(struct snd_mask *mask,
161 const struct snd_mask *v)
168{ 162{
169 *mask = *v; 163 *mask = *v;
170} 164}
171 165
172INLINE int snd_mask_test(const struct snd_mask *mask, unsigned int val) 166static inline int snd_mask_test(const struct snd_mask *mask, unsigned int val)
173{ 167{
174 assert(val <= SNDRV_MASK_BITS);
175 return mask->bits[MASK_OFS(val)] & MASK_BIT(val); 168 return mask->bits[MASK_OFS(val)] & MASK_BIT(val);
176} 169}
177 170
178INLINE int snd_mask_single(const struct snd_mask *mask) 171static inline int snd_mask_single(const struct snd_mask *mask)
179{ 172{
180 int i, c = 0; 173 int i, c = 0;
181 assert(!snd_mask_empty(mask));
182 for (i = 0; i < SNDRV_MASK_SIZE; i++) { 174 for (i = 0; i < SNDRV_MASK_SIZE; i++) {
183 if (! mask->bits[i]) 175 if (! mask->bits[i])
184 continue; 176 continue;
@@ -191,10 +183,10 @@ INLINE int snd_mask_single(const struct snd_mask *mask)
191 return 1; 183 return 1;
192} 184}
193 185
194INLINE int snd_mask_refine(struct snd_mask *mask, const struct snd_mask *v) 186static inline int snd_mask_refine(struct snd_mask *mask,
187 const struct snd_mask *v)
195{ 188{
196 struct snd_mask old; 189 struct snd_mask old;
197 assert(!snd_mask_empty(mask));
198 snd_mask_copy(&old, mask); 190 snd_mask_copy(&old, mask);
199 snd_mask_intersect(mask, v); 191 snd_mask_intersect(mask, v);
200 if (snd_mask_empty(mask)) 192 if (snd_mask_empty(mask))
@@ -202,27 +194,24 @@ INLINE int snd_mask_refine(struct snd_mask *mask, const struct snd_mask *v)
202 return !snd_mask_eq(mask, &old); 194 return !snd_mask_eq(mask, &old);
203} 195}
204 196
205INLINE int snd_mask_refine_first(struct snd_mask *mask) 197static inline int snd_mask_refine_first(struct snd_mask *mask)
206{ 198{
207 assert(!snd_mask_empty(mask));
208 if (snd_mask_single(mask)) 199 if (snd_mask_single(mask))
209 return 0; 200 return 0;
210 snd_mask_leave(mask, snd_mask_min(mask)); 201 snd_mask_leave(mask, snd_mask_min(mask));
211 return 1; 202 return 1;
212} 203}
213 204
214INLINE int snd_mask_refine_last(struct snd_mask *mask) 205static inline int snd_mask_refine_last(struct snd_mask *mask)
215{ 206{
216 assert(!snd_mask_empty(mask));
217 if (snd_mask_single(mask)) 207 if (snd_mask_single(mask))
218 return 0; 208 return 0;
219 snd_mask_leave(mask, snd_mask_max(mask)); 209 snd_mask_leave(mask, snd_mask_max(mask));
220 return 1; 210 return 1;
221} 211}
222 212
223INLINE int snd_mask_refine_min(struct snd_mask *mask, unsigned int val) 213static inline int snd_mask_refine_min(struct snd_mask *mask, unsigned int val)
224{ 214{
225 assert(!snd_mask_empty(mask));
226 if (snd_mask_min(mask) >= val) 215 if (snd_mask_min(mask) >= val)
227 return 0; 216 return 0;
228 snd_mask_reset_range(mask, 0, val - 1); 217 snd_mask_reset_range(mask, 0, val - 1);
@@ -231,9 +220,8 @@ INLINE int snd_mask_refine_min(struct snd_mask *mask, unsigned int val)
231 return 1; 220 return 1;
232} 221}
233 222
234INLINE int snd_mask_refine_max(struct snd_mask *mask, unsigned int val) 223static inline int snd_mask_refine_max(struct snd_mask *mask, unsigned int val)
235{ 224{
236 assert(!snd_mask_empty(mask));
237 if (snd_mask_max(mask) <= val) 225 if (snd_mask_max(mask) <= val)
238 return 0; 226 return 0;
239 snd_mask_reset_range(mask, val + 1, SNDRV_MASK_BITS); 227 snd_mask_reset_range(mask, val + 1, SNDRV_MASK_BITS);
@@ -242,10 +230,9 @@ INLINE int snd_mask_refine_max(struct snd_mask *mask, unsigned int val)
242 return 1; 230 return 1;
243} 231}
244 232
245INLINE int snd_mask_refine_set(struct snd_mask *mask, unsigned int val) 233static inline int snd_mask_refine_set(struct snd_mask *mask, unsigned int val)
246{ 234{
247 int changed; 235 int changed;
248 assert(!snd_mask_empty(mask));
249 changed = !snd_mask_single(mask); 236 changed = !snd_mask_single(mask);
250 snd_mask_leave(mask, val); 237 snd_mask_leave(mask, val);
251 if (snd_mask_empty(mask)) 238 if (snd_mask_empty(mask))
@@ -253,13 +240,12 @@ INLINE int snd_mask_refine_set(struct snd_mask *mask, unsigned int val)
253 return changed; 240 return changed;
254} 241}
255 242
256INLINE int snd_mask_value(const struct snd_mask *mask) 243static inline int snd_mask_value(const struct snd_mask *mask)
257{ 244{
258 assert(!snd_mask_empty(mask));
259 return snd_mask_min(mask); 245 return snd_mask_min(mask);
260} 246}
261 247
262INLINE void snd_interval_any(struct snd_interval *i) 248static inline void snd_interval_any(struct snd_interval *i)
263{ 249{
264 i->min = 0; 250 i->min = 0;
265 i->openmin = 0; 251 i->openmin = 0;
@@ -269,63 +255,59 @@ INLINE void snd_interval_any(struct snd_interval *i)
269 i->empty = 0; 255 i->empty = 0;
270} 256}
271 257
272INLINE void snd_interval_none(struct snd_interval *i) 258static inline void snd_interval_none(struct snd_interval *i)
273{ 259{
274 i->empty = 1; 260 i->empty = 1;
275} 261}
276 262
277INLINE int snd_interval_checkempty(const struct snd_interval *i) 263static inline int snd_interval_checkempty(const struct snd_interval *i)
278{ 264{
279 return (i->min > i->max || 265 return (i->min > i->max ||
280 (i->min == i->max && (i->openmin || i->openmax))); 266 (i->min == i->max && (i->openmin || i->openmax)));
281} 267}
282 268
283INLINE int snd_interval_empty(const struct snd_interval *i) 269static inline int snd_interval_empty(const struct snd_interval *i)
284{ 270{
285 return i->empty; 271 return i->empty;
286} 272}
287 273
288INLINE int snd_interval_single(const struct snd_interval *i) 274static inline int snd_interval_single(const struct snd_interval *i)
289{ 275{
290 assert(!snd_interval_empty(i));
291 return (i->min == i->max || 276 return (i->min == i->max ||
292 (i->min + 1 == i->max && i->openmax)); 277 (i->min + 1 == i->max && i->openmax));
293} 278}
294 279
295INLINE int snd_interval_value(const struct snd_interval *i) 280static inline int snd_interval_value(const struct snd_interval *i)
296{ 281{
297 assert(snd_interval_single(i));
298 return i->min; 282 return i->min;
299} 283}
300 284
301INLINE int snd_interval_min(const struct snd_interval *i) 285static inline int snd_interval_min(const struct snd_interval *i)
302{ 286{
303 assert(!snd_interval_empty(i));
304 return i->min; 287 return i->min;
305} 288}
306 289
307INLINE int snd_interval_max(const struct snd_interval *i) 290static inline int snd_interval_max(const struct snd_interval *i)
308{ 291{
309 unsigned int v; 292 unsigned int v;
310 assert(!snd_interval_empty(i));
311 v = i->max; 293 v = i->max;
312 if (i->openmax) 294 if (i->openmax)
313 v--; 295 v--;
314 return v; 296 return v;
315} 297}
316 298
317INLINE int snd_interval_test(const struct snd_interval *i, unsigned int val) 299static inline int snd_interval_test(const struct snd_interval *i, unsigned int val)
318{ 300{
319 return !((i->min > val || (i->min == val && i->openmin) || 301 return !((i->min > val || (i->min == val && i->openmin) ||
320 i->max < val || (i->max == val && i->openmax))); 302 i->max < val || (i->max == val && i->openmax)));
321} 303}
322 304
323INLINE void snd_interval_copy(struct snd_interval *d, const struct snd_interval *s) 305static inline void snd_interval_copy(struct snd_interval *d, const struct snd_interval *s)
324{ 306{
325 *d = *s; 307 *d = *s;
326} 308}
327 309
328INLINE int snd_interval_setinteger(struct snd_interval *i) 310static inline int snd_interval_setinteger(struct snd_interval *i)
329{ 311{
330 if (i->integer) 312 if (i->integer)
331 return 0; 313 return 0;
@@ -335,7 +317,7 @@ INLINE int snd_interval_setinteger(struct snd_interval *i)
335 return 1; 317 return 1;
336} 318}
337 319
338INLINE int snd_interval_eq(const struct snd_interval *i1, const struct snd_interval *i2) 320static inline int snd_interval_eq(const struct snd_interval *i1, const struct snd_interval *i2)
339{ 321{
340 if (i1->empty) 322 if (i1->empty)
341 return i2->empty; 323 return i2->empty;
@@ -359,8 +341,5 @@ static inline unsigned int sub(unsigned int a, unsigned int b)
359 return 0; 341 return 0;
360} 342}
361 343
362#undef INLINE
363#undef assert
364
365#endif /* __SOUND_PCM_PARAMS_H */ 344#endif /* __SOUND_PCM_PARAMS_H */
366 345