Blame view

sound/core/pcm_misc.c 12.5 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
  /*
   *  PCM Interface - misc routines
c1017a4cd   Jaroslav Kysela   [ALSA] Changed Ja...
3
   *  Copyright (c) 1998 by Jaroslav Kysela <perex@perex.cz>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
   *
   *
   *   This library is free software; you can redistribute it and/or modify
   *   it under the terms of the GNU Library 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 Library General Public License for more details.
   *
   *   You should have received a copy of the GNU Library General Public
   *   License along with this library; if not, write to the Free Software
   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   *
   */
    
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  #include <linux/time.h>
  #include <sound/core.h>
  #include <sound/pcm.h>
  #define SND_PCM_FORMAT_UNKNOWN (-1)
  
  /* NOTE: "signed" prefix must be given below since the default char is
   *       unsigned on some architectures!
   */
  struct pcm_format_data {
  	unsigned char width;	/* bit width */
  	unsigned char phys;	/* physical bit width */
  	signed char le;	/* 0 = big-endian, 1 = little-endian, -1 = others */
  	signed char signd;	/* 0 = unsigned, 1 = signed, -1 = others */
  	unsigned char silence[8];	/* silence data to fill */
  };
fea952e5c   Clemens Ladisch   ALSA: core: spars...
37
38
39
40
  /* we do lots of calculations on snd_pcm_format_t; shut up sparse */
  #define INT	__force int
  
  static struct pcm_format_data pcm_formats[(INT)SNDRV_PCM_FORMAT_LAST+1] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  	[SNDRV_PCM_FORMAT_S8] = {
  		.width = 8, .phys = 8, .le = -1, .signd = 1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_U8] = {
  		.width = 8, .phys = 8, .le = -1, .signd = 0,
  		.silence = { 0x80 },
  	},
  	[SNDRV_PCM_FORMAT_S16_LE] = {
  		.width = 16, .phys = 16, .le = 1, .signd = 1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_S16_BE] = {
  		.width = 16, .phys = 16, .le = 0, .signd = 1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_U16_LE] = {
  		.width = 16, .phys = 16, .le = 1, .signd = 0,
  		.silence = { 0x00, 0x80 },
  	},
  	[SNDRV_PCM_FORMAT_U16_BE] = {
  		.width = 16, .phys = 16, .le = 0, .signd = 0,
  		.silence = { 0x80, 0x00 },
  	},
  	[SNDRV_PCM_FORMAT_S24_LE] = {
  		.width = 24, .phys = 32, .le = 1, .signd = 1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_S24_BE] = {
  		.width = 24, .phys = 32, .le = 0, .signd = 1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_U24_LE] = {
  		.width = 24, .phys = 32, .le = 1, .signd = 0,
  		.silence = { 0x00, 0x00, 0x80 },
  	},
  	[SNDRV_PCM_FORMAT_U24_BE] = {
  		.width = 24, .phys = 32, .le = 0, .signd = 0,
67a7be7e9   Jaroslav Kysela   [ALSA] PCM - fixe...
79
  		.silence = { 0x00, 0x80, 0x00, 0x00 },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  	},
  	[SNDRV_PCM_FORMAT_S32_LE] = {
  		.width = 32, .phys = 32, .le = 1, .signd = 1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_S32_BE] = {
  		.width = 32, .phys = 32, .le = 0, .signd = 1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_U32_LE] = {
  		.width = 32, .phys = 32, .le = 1, .signd = 0,
  		.silence = { 0x00, 0x00, 0x00, 0x80 },
  	},
  	[SNDRV_PCM_FORMAT_U32_BE] = {
  		.width = 32, .phys = 32, .le = 0, .signd = 0,
  		.silence = { 0x80, 0x00, 0x00, 0x00 },
  	},
  	[SNDRV_PCM_FORMAT_FLOAT_LE] = {
  		.width = 32, .phys = 32, .le = 1, .signd = -1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_FLOAT_BE] = {
  		.width = 32, .phys = 32, .le = 0, .signd = -1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_FLOAT64_LE] = {
  		.width = 64, .phys = 64, .le = 1, .signd = -1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_FLOAT64_BE] = {
  		.width = 64, .phys = 64, .le = 0, .signd = -1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE] = {
  		.width = 32, .phys = 32, .le = 1, .signd = -1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE] = {
  		.width = 32, .phys = 32, .le = 0, .signd = -1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_MU_LAW] = {
  		.width = 8, .phys = 8, .le = -1, .signd = -1,
  		.silence = { 0x7f },
  	},
  	[SNDRV_PCM_FORMAT_A_LAW] = {
  		.width = 8, .phys = 8, .le = -1, .signd = -1,
  		.silence = { 0x55 },
  	},
  	[SNDRV_PCM_FORMAT_IMA_ADPCM] = {
  		.width = 4, .phys = 4, .le = -1, .signd = -1,
  		.silence = {},
  	},
15c0cee6c   Ben Collins   ALSA: pcm: Define...
133
134
135
136
137
138
139
140
  	[SNDRV_PCM_FORMAT_G723_24] = {
  		.width = 3, .phys = 3, .le = -1, .signd = -1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_G723_40] = {
  		.width = 5, .phys = 5, .le = -1, .signd = -1,
  		.silence = {},
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
  	/* FIXME: the following three formats are not defined properly yet */
  	[SNDRV_PCM_FORMAT_MPEG] = {
  		.le = -1, .signd = -1,
  	},
  	[SNDRV_PCM_FORMAT_GSM] = {
  		.le = -1, .signd = -1,
  	},
  	[SNDRV_PCM_FORMAT_SPECIAL] = {
  		.le = -1, .signd = -1,
  	},
  	[SNDRV_PCM_FORMAT_S24_3LE] = {
  		.width = 24, .phys = 24, .le = 1, .signd = 1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_S24_3BE] = {
  		.width = 24, .phys = 24, .le = 0, .signd = 1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_U24_3LE] = {
  		.width = 24, .phys = 24, .le = 1, .signd = 0,
  		.silence = { 0x00, 0x00, 0x80 },
  	},
  	[SNDRV_PCM_FORMAT_U24_3BE] = {
  		.width = 24, .phys = 24, .le = 0, .signd = 0,
  		.silence = { 0x80, 0x00, 0x00 },
  	},
  	[SNDRV_PCM_FORMAT_S20_3LE] = {
  		.width = 20, .phys = 24, .le = 1, .signd = 1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_S20_3BE] = {
  		.width = 20, .phys = 24, .le = 0, .signd = 1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_U20_3LE] = {
  		.width = 20, .phys = 24, .le = 1, .signd = 0,
  		.silence = { 0x00, 0x00, 0x08 },
  	},
  	[SNDRV_PCM_FORMAT_U20_3BE] = {
  		.width = 20, .phys = 24, .le = 0, .signd = 0,
  		.silence = { 0x08, 0x00, 0x00 },
  	},
  	[SNDRV_PCM_FORMAT_S18_3LE] = {
  		.width = 18, .phys = 24, .le = 1, .signd = 1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_S18_3BE] = {
  		.width = 18, .phys = 24, .le = 0, .signd = 1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_U18_3LE] = {
  		.width = 18, .phys = 24, .le = 1, .signd = 0,
  		.silence = { 0x00, 0x00, 0x02 },
  	},
  	[SNDRV_PCM_FORMAT_U18_3BE] = {
  		.width = 18, .phys = 24, .le = 0, .signd = 0,
  		.silence = { 0x02, 0x00, 0x00 },
  	},
15c0cee6c   Ben Collins   ALSA: pcm: Define...
199
200
201
202
203
204
205
206
  	[SNDRV_PCM_FORMAT_G723_24_1B] = {
  		.width = 3, .phys = 8, .le = -1, .signd = -1,
  		.silence = {},
  	},
  	[SNDRV_PCM_FORMAT_G723_40_1B] = {
  		.width = 5, .phys = 8, .le = -1, .signd = -1,
  		.silence = {},
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
207
208
209
210
211
212
213
214
215
216
217
218
219
  };
  
  
  /**
   * snd_pcm_format_signed - Check the PCM format is signed linear
   * @format: the format to check
   *
   * Returns 1 if the given PCM format is signed linear, 0 if unsigned
   * linear, and a negative error code for non-linear formats.
   */
  int snd_pcm_format_signed(snd_pcm_format_t format)
  {
  	int val;
fea952e5c   Clemens Ladisch   ALSA: core: spars...
220
  	if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
221
  		return -EINVAL;
fea952e5c   Clemens Ladisch   ALSA: core: spars...
222
  	if ((val = pcm_formats[(INT)format].signd) < 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
223
224
225
  		return -EINVAL;
  	return val;
  }
e88e8ae63   Takashi Iwai   [ALSA] Move OSS-s...
226
  EXPORT_SYMBOL(snd_pcm_format_signed);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
  /**
   * snd_pcm_format_unsigned - Check the PCM format is unsigned linear
   * @format: the format to check
   *
   * Returns 1 if the given PCM format is unsigned linear, 0 if signed
   * linear, and a negative error code for non-linear formats.
   */
  int snd_pcm_format_unsigned(snd_pcm_format_t format)
  {
  	int val;
  
  	val = snd_pcm_format_signed(format);
  	if (val < 0)
  		return val;
  	return !val;
  }
e88e8ae63   Takashi Iwai   [ALSA] Move OSS-s...
243
  EXPORT_SYMBOL(snd_pcm_format_unsigned);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
244
245
246
247
248
249
250
251
252
253
  /**
   * snd_pcm_format_linear - Check the PCM format is linear
   * @format: the format to check
   *
   * Returns 1 if the given PCM format is linear, 0 if not.
   */
  int snd_pcm_format_linear(snd_pcm_format_t format)
  {
  	return snd_pcm_format_signed(format) >= 0;
  }
e88e8ae63   Takashi Iwai   [ALSA] Move OSS-s...
254
  EXPORT_SYMBOL(snd_pcm_format_linear);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
255
256
257
258
259
260
261
262
263
264
  /**
   * snd_pcm_format_little_endian - Check the PCM format is little-endian
   * @format: the format to check
   *
   * Returns 1 if the given PCM format is little-endian, 0 if
   * big-endian, or a negative error code if endian not specified.
   */
  int snd_pcm_format_little_endian(snd_pcm_format_t format)
  {
  	int val;
fea952e5c   Clemens Ladisch   ALSA: core: spars...
265
  	if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
266
  		return -EINVAL;
fea952e5c   Clemens Ladisch   ALSA: core: spars...
267
  	if ((val = pcm_formats[(INT)format].le) < 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
268
269
270
  		return -EINVAL;
  	return val;
  }
e88e8ae63   Takashi Iwai   [ALSA] Move OSS-s...
271
  EXPORT_SYMBOL(snd_pcm_format_little_endian);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
  /**
   * snd_pcm_format_big_endian - Check the PCM format is big-endian
   * @format: the format to check
   *
   * Returns 1 if the given PCM format is big-endian, 0 if
   * little-endian, or a negative error code if endian not specified.
   */
  int snd_pcm_format_big_endian(snd_pcm_format_t format)
  {
  	int val;
  
  	val = snd_pcm_format_little_endian(format);
  	if (val < 0)
  		return val;
  	return !val;
  }
e88e8ae63   Takashi Iwai   [ALSA] Move OSS-s...
288
  EXPORT_SYMBOL(snd_pcm_format_big_endian);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
289
  /**
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
290
291
292
293
294
295
296
297
298
   * snd_pcm_format_width - return the bit-width of the format
   * @format: the format to check
   *
   * Returns the bit-width of the format, or a negative error code
   * if unknown format.
   */
  int snd_pcm_format_width(snd_pcm_format_t format)
  {
  	int val;
fea952e5c   Clemens Ladisch   ALSA: core: spars...
299
  	if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
300
  		return -EINVAL;
fea952e5c   Clemens Ladisch   ALSA: core: spars...
301
  	if ((val = pcm_formats[(INT)format].width) == 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
302
303
304
  		return -EINVAL;
  	return val;
  }
e88e8ae63   Takashi Iwai   [ALSA] Move OSS-s...
305
  EXPORT_SYMBOL(snd_pcm_format_width);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
306
307
308
309
310
311
312
313
314
315
  /**
   * snd_pcm_format_physical_width - return the physical bit-width of the format
   * @format: the format to check
   *
   * Returns the physical bit-width of the format, or a negative error code
   * if unknown format.
   */
  int snd_pcm_format_physical_width(snd_pcm_format_t format)
  {
  	int val;
fea952e5c   Clemens Ladisch   ALSA: core: spars...
316
  	if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
317
  		return -EINVAL;
fea952e5c   Clemens Ladisch   ALSA: core: spars...
318
  	if ((val = pcm_formats[(INT)format].phys) == 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
319
320
321
  		return -EINVAL;
  	return val;
  }
e88e8ae63   Takashi Iwai   [ALSA] Move OSS-s...
322
  EXPORT_SYMBOL(snd_pcm_format_physical_width);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
323
324
325
  /**
   * snd_pcm_format_size - return the byte size of samples on the given format
   * @format: the format to check
a66547f3a   Randy Dunlap   sound: add missin...
326
   * @samples: sampling rate
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
327
328
329
330
331
332
333
334
335
336
337
   *
   * Returns the byte size of the given samples for the format, or a
   * negative error code if unknown format.
   */
  ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples)
  {
  	int phys_width = snd_pcm_format_physical_width(format);
  	if (phys_width < 0)
  		return -EINVAL;
  	return samples * phys_width / 8;
  }
e88e8ae63   Takashi Iwai   [ALSA] Move OSS-s...
338
  EXPORT_SYMBOL(snd_pcm_format_size);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
339
340
341
342
343
344
345
346
  /**
   * snd_pcm_format_silence_64 - return the silent data in 8 bytes array
   * @format: the format to check
   *
   * Returns the format pattern to fill or NULL if error.
   */
  const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format)
  {
fea952e5c   Clemens Ladisch   ALSA: core: spars...
347
  	if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
348
  		return NULL;
fea952e5c   Clemens Ladisch   ALSA: core: spars...
349
  	if (! pcm_formats[(INT)format].phys)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
350
  		return NULL;
fea952e5c   Clemens Ladisch   ALSA: core: spars...
351
  	return pcm_formats[(INT)format].silence;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
352
  }
e88e8ae63   Takashi Iwai   [ALSA] Move OSS-s...
353
  EXPORT_SYMBOL(snd_pcm_format_silence_64);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
354
355
356
357
358
359
360
361
362
363
364
365
366
367
  /**
   * snd_pcm_format_set_silence - set the silence data on the buffer
   * @format: the PCM format
   * @data: the buffer pointer
   * @samples: the number of samples to set silence
   *
   * Sets the silence data on the buffer for the given samples.
   *
   * Returns zero if successful, or a negative error code on failure.
   */
  int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int samples)
  {
  	int width;
  	unsigned char *dst, *pat;
fea952e5c   Clemens Ladisch   ALSA: core: spars...
368
  	if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
369
370
371
  		return -EINVAL;
  	if (samples == 0)
  		return 0;
fea952e5c   Clemens Ladisch   ALSA: core: spars...
372
373
  	width = pcm_formats[(INT)format].phys; /* physical width */
  	pat = pcm_formats[(INT)format].silence;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
374
375
376
  	if (! width)
  		return -EINVAL;
  	/* signed or 1 byte data */
fea952e5c   Clemens Ladisch   ALSA: core: spars...
377
  	if (pcm_formats[(INT)format].signd == 1 || width <= 8) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
  		unsigned int bytes = samples * width / 8;
  		memset(data, *pat, bytes);
  		return 0;
  	}
  	/* non-zero samples, fill using a loop */
  	width /= 8;
  	dst = data;
  #if 0
  	while (samples--) {
  		memcpy(dst, pat, width);
  		dst += width;
  	}
  #else
  	/* a bit optimization for constant width */
  	switch (width) {
  	case 2:
  		while (samples--) {
  			memcpy(dst, pat, 2);
  			dst += 2;
  		}
  		break;
  	case 3:
  		while (samples--) {
  			memcpy(dst, pat, 3);
  			dst += 3;
  		}
  		break;
  	case 4:
  		while (samples--) {
  			memcpy(dst, pat, 4);
  			dst += 4;
  		}
  		break;
  	case 8:
  		while (samples--) {
  			memcpy(dst, pat, 8);
  			dst += 8;
  		}
  		break;
  	}
  #endif
  	return 0;
  }
e88e8ae63   Takashi Iwai   [ALSA] Move OSS-s...
421
  EXPORT_SYMBOL(snd_pcm_format_set_silence);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
422
423
424
425
426
427
428
429
430
  /**
   * snd_pcm_limit_hw_rates - determine rate_min/rate_max fields
   * @runtime: the runtime instance
   *
   * Determines the rate_min and rate_max fields from the rates bits of
   * the given runtime->hw.
   *
   * Returns zero if successful.
   */
877211f5e   Takashi Iwai   [ALSA] Remove xxx...
431
  int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
432
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
433
  	int i;
7653d5576   Clemens Ladisch   [ALSA] pcm: merge...
434
  	for (i = 0; i < (int)snd_pcm_known_rates.count; i++) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
435
  		if (runtime->hw.rates & (1 << i)) {
7653d5576   Clemens Ladisch   [ALSA] pcm: merge...
436
  			runtime->hw.rate_min = snd_pcm_known_rates.list[i];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
437
438
439
  			break;
  		}
  	}
7653d5576   Clemens Ladisch   [ALSA] pcm: merge...
440
  	for (i = (int)snd_pcm_known_rates.count - 1; i >= 0; i--) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
441
  		if (runtime->hw.rates & (1 << i)) {
7653d5576   Clemens Ladisch   [ALSA] pcm: merge...
442
  			runtime->hw.rate_max = snd_pcm_known_rates.list[i];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
443
444
445
446
447
  			break;
  		}
  	}
  	return 0;
  }
e88e8ae63   Takashi Iwai   [ALSA] Move OSS-s...
448
449
  
  EXPORT_SYMBOL(snd_pcm_limit_hw_rates);
918f3a0e8   Clemens Ladisch   [ALSA] pcm: add s...
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
  
  /**
   * snd_pcm_rate_to_rate_bit - converts sample rate to SNDRV_PCM_RATE_xxx bit
   * @rate: the sample rate to convert
   *
   * Returns the SNDRV_PCM_RATE_xxx flag that corresponds to the given rate, or
   * SNDRV_PCM_RATE_KNOT for an unknown rate.
   */
  unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate)
  {
  	unsigned int i;
  
  	for (i = 0; i < snd_pcm_known_rates.count; i++)
  		if (snd_pcm_known_rates.list[i] == rate)
  			return 1u << i;
  	return SNDRV_PCM_RATE_KNOT;
  }
  EXPORT_SYMBOL(snd_pcm_rate_to_rate_bit);