pcm_misc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /*
  2. * PCM Interface - misc routines
  3. * Copyright (c) 1998 by Jaroslav Kysela <perex@perex.cz>
  4. *
  5. *
  6. * This library is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Library General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <linux/time.h>
  22. #include <linux/export.h>
  23. #include <sound/core.h>
  24. #include <sound/pcm.h>
  25. #include "pcm_local.h"
  26. #define SND_PCM_FORMAT_UNKNOWN (-1)
  27. /* NOTE: "signed" prefix must be given below since the default char is
  28. * unsigned on some architectures!
  29. */
  30. struct pcm_format_data {
  31. unsigned char width; /* bit width */
  32. unsigned char phys; /* physical bit width */
  33. signed char le; /* 0 = big-endian, 1 = little-endian, -1 = others */
  34. signed char signd; /* 0 = unsigned, 1 = signed, -1 = others */
  35. unsigned char silence[8]; /* silence data to fill */
  36. };
  37. /* we do lots of calculations on snd_pcm_format_t; shut up sparse */
  38. #define INT __force int
  39. static struct pcm_format_data pcm_formats[(INT)SNDRV_PCM_FORMAT_LAST+1] = {
  40. [SNDRV_PCM_FORMAT_S8] = {
  41. .width = 8, .phys = 8, .le = -1, .signd = 1,
  42. .silence = {},
  43. },
  44. [SNDRV_PCM_FORMAT_U8] = {
  45. .width = 8, .phys = 8, .le = -1, .signd = 0,
  46. .silence = { 0x80 },
  47. },
  48. [SNDRV_PCM_FORMAT_S16_LE] = {
  49. .width = 16, .phys = 16, .le = 1, .signd = 1,
  50. .silence = {},
  51. },
  52. [SNDRV_PCM_FORMAT_S16_BE] = {
  53. .width = 16, .phys = 16, .le = 0, .signd = 1,
  54. .silence = {},
  55. },
  56. [SNDRV_PCM_FORMAT_U16_LE] = {
  57. .width = 16, .phys = 16, .le = 1, .signd = 0,
  58. .silence = { 0x00, 0x80 },
  59. },
  60. [SNDRV_PCM_FORMAT_U16_BE] = {
  61. .width = 16, .phys = 16, .le = 0, .signd = 0,
  62. .silence = { 0x80, 0x00 },
  63. },
  64. [SNDRV_PCM_FORMAT_S24_LE] = {
  65. .width = 24, .phys = 32, .le = 1, .signd = 1,
  66. .silence = {},
  67. },
  68. [SNDRV_PCM_FORMAT_S24_BE] = {
  69. .width = 24, .phys = 32, .le = 0, .signd = 1,
  70. .silence = {},
  71. },
  72. [SNDRV_PCM_FORMAT_U24_LE] = {
  73. .width = 24, .phys = 32, .le = 1, .signd = 0,
  74. .silence = { 0x00, 0x00, 0x80 },
  75. },
  76. [SNDRV_PCM_FORMAT_U24_BE] = {
  77. .width = 24, .phys = 32, .le = 0, .signd = 0,
  78. .silence = { 0x00, 0x80, 0x00, 0x00 },
  79. },
  80. [SNDRV_PCM_FORMAT_S32_LE] = {
  81. .width = 32, .phys = 32, .le = 1, .signd = 1,
  82. .silence = {},
  83. },
  84. [SNDRV_PCM_FORMAT_S32_BE] = {
  85. .width = 32, .phys = 32, .le = 0, .signd = 1,
  86. .silence = {},
  87. },
  88. [SNDRV_PCM_FORMAT_U32_LE] = {
  89. .width = 32, .phys = 32, .le = 1, .signd = 0,
  90. .silence = { 0x00, 0x00, 0x00, 0x80 },
  91. },
  92. [SNDRV_PCM_FORMAT_U32_BE] = {
  93. .width = 32, .phys = 32, .le = 0, .signd = 0,
  94. .silence = { 0x80, 0x00, 0x00, 0x00 },
  95. },
  96. [SNDRV_PCM_FORMAT_FLOAT_LE] = {
  97. .width = 32, .phys = 32, .le = 1, .signd = -1,
  98. .silence = {},
  99. },
  100. [SNDRV_PCM_FORMAT_FLOAT_BE] = {
  101. .width = 32, .phys = 32, .le = 0, .signd = -1,
  102. .silence = {},
  103. },
  104. [SNDRV_PCM_FORMAT_FLOAT64_LE] = {
  105. .width = 64, .phys = 64, .le = 1, .signd = -1,
  106. .silence = {},
  107. },
  108. [SNDRV_PCM_FORMAT_FLOAT64_BE] = {
  109. .width = 64, .phys = 64, .le = 0, .signd = -1,
  110. .silence = {},
  111. },
  112. [SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE] = {
  113. .width = 32, .phys = 32, .le = 1, .signd = -1,
  114. .silence = {},
  115. },
  116. [SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE] = {
  117. .width = 32, .phys = 32, .le = 0, .signd = -1,
  118. .silence = {},
  119. },
  120. [SNDRV_PCM_FORMAT_MU_LAW] = {
  121. .width = 8, .phys = 8, .le = -1, .signd = -1,
  122. .silence = { 0x7f },
  123. },
  124. [SNDRV_PCM_FORMAT_A_LAW] = {
  125. .width = 8, .phys = 8, .le = -1, .signd = -1,
  126. .silence = { 0x55 },
  127. },
  128. [SNDRV_PCM_FORMAT_IMA_ADPCM] = {
  129. .width = 4, .phys = 4, .le = -1, .signd = -1,
  130. .silence = {},
  131. },
  132. [SNDRV_PCM_FORMAT_G723_24] = {
  133. .width = 3, .phys = 3, .le = -1, .signd = -1,
  134. .silence = {},
  135. },
  136. [SNDRV_PCM_FORMAT_G723_40] = {
  137. .width = 5, .phys = 5, .le = -1, .signd = -1,
  138. .silence = {},
  139. },
  140. [SNDRV_PCM_FORMAT_DSD_U8] = {
  141. .width = 8, .phys = 8, .le = 1, .signd = 0,
  142. .silence = { 0x69 },
  143. },
  144. [SNDRV_PCM_FORMAT_DSD_U16_LE] = {
  145. .width = 16, .phys = 16, .le = 1, .signd = 0,
  146. .silence = { 0x69, 0x69 },
  147. },
  148. [SNDRV_PCM_FORMAT_DSD_U32_LE] = {
  149. .width = 32, .phys = 32, .le = 1, .signd = 0,
  150. .silence = { 0x69, 0x69, 0x69, 0x69 },
  151. },
  152. [SNDRV_PCM_FORMAT_DSD_U16_BE] = {
  153. .width = 16, .phys = 16, .le = 0, .signd = 0,
  154. .silence = { 0x69, 0x69 },
  155. },
  156. [SNDRV_PCM_FORMAT_DSD_U32_BE] = {
  157. .width = 32, .phys = 32, .le = 0, .signd = 0,
  158. .silence = { 0x69, 0x69, 0x69, 0x69 },
  159. },
  160. /* FIXME: the following three formats are not defined properly yet */
  161. [SNDRV_PCM_FORMAT_MPEG] = {
  162. .le = -1, .signd = -1,
  163. },
  164. [SNDRV_PCM_FORMAT_GSM] = {
  165. .le = -1, .signd = -1,
  166. },
  167. [SNDRV_PCM_FORMAT_SPECIAL] = {
  168. .le = -1, .signd = -1,
  169. },
  170. [SNDRV_PCM_FORMAT_S24_3LE] = {
  171. .width = 24, .phys = 24, .le = 1, .signd = 1,
  172. .silence = {},
  173. },
  174. [SNDRV_PCM_FORMAT_S24_3BE] = {
  175. .width = 24, .phys = 24, .le = 0, .signd = 1,
  176. .silence = {},
  177. },
  178. [SNDRV_PCM_FORMAT_U24_3LE] = {
  179. .width = 24, .phys = 24, .le = 1, .signd = 0,
  180. .silence = { 0x00, 0x00, 0x80 },
  181. },
  182. [SNDRV_PCM_FORMAT_U24_3BE] = {
  183. .width = 24, .phys = 24, .le = 0, .signd = 0,
  184. .silence = { 0x80, 0x00, 0x00 },
  185. },
  186. [SNDRV_PCM_FORMAT_S20_3LE] = {
  187. .width = 20, .phys = 24, .le = 1, .signd = 1,
  188. .silence = {},
  189. },
  190. [SNDRV_PCM_FORMAT_S20_3BE] = {
  191. .width = 20, .phys = 24, .le = 0, .signd = 1,
  192. .silence = {},
  193. },
  194. [SNDRV_PCM_FORMAT_U20_3LE] = {
  195. .width = 20, .phys = 24, .le = 1, .signd = 0,
  196. .silence = { 0x00, 0x00, 0x08 },
  197. },
  198. [SNDRV_PCM_FORMAT_U20_3BE] = {
  199. .width = 20, .phys = 24, .le = 0, .signd = 0,
  200. .silence = { 0x08, 0x00, 0x00 },
  201. },
  202. [SNDRV_PCM_FORMAT_S18_3LE] = {
  203. .width = 18, .phys = 24, .le = 1, .signd = 1,
  204. .silence = {},
  205. },
  206. [SNDRV_PCM_FORMAT_S18_3BE] = {
  207. .width = 18, .phys = 24, .le = 0, .signd = 1,
  208. .silence = {},
  209. },
  210. [SNDRV_PCM_FORMAT_U18_3LE] = {
  211. .width = 18, .phys = 24, .le = 1, .signd = 0,
  212. .silence = { 0x00, 0x00, 0x02 },
  213. },
  214. [SNDRV_PCM_FORMAT_U18_3BE] = {
  215. .width = 18, .phys = 24, .le = 0, .signd = 0,
  216. .silence = { 0x02, 0x00, 0x00 },
  217. },
  218. [SNDRV_PCM_FORMAT_G723_24_1B] = {
  219. .width = 3, .phys = 8, .le = -1, .signd = -1,
  220. .silence = {},
  221. },
  222. [SNDRV_PCM_FORMAT_G723_40_1B] = {
  223. .width = 5, .phys = 8, .le = -1, .signd = -1,
  224. .silence = {},
  225. },
  226. };
  227. /**
  228. * snd_pcm_format_signed - Check the PCM format is signed linear
  229. * @format: the format to check
  230. *
  231. * Return: 1 if the given PCM format is signed linear, 0 if unsigned
  232. * linear, and a negative error code for non-linear formats.
  233. */
  234. int snd_pcm_format_signed(snd_pcm_format_t format)
  235. {
  236. int val;
  237. if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
  238. return -EINVAL;
  239. if ((val = pcm_formats[(INT)format].signd) < 0)
  240. return -EINVAL;
  241. return val;
  242. }
  243. EXPORT_SYMBOL(snd_pcm_format_signed);
  244. /**
  245. * snd_pcm_format_unsigned - Check the PCM format is unsigned linear
  246. * @format: the format to check
  247. *
  248. * Return: 1 if the given PCM format is unsigned linear, 0 if signed
  249. * linear, and a negative error code for non-linear formats.
  250. */
  251. int snd_pcm_format_unsigned(snd_pcm_format_t format)
  252. {
  253. int val;
  254. val = snd_pcm_format_signed(format);
  255. if (val < 0)
  256. return val;
  257. return !val;
  258. }
  259. EXPORT_SYMBOL(snd_pcm_format_unsigned);
  260. /**
  261. * snd_pcm_format_linear - Check the PCM format is linear
  262. * @format: the format to check
  263. *
  264. * Return: 1 if the given PCM format is linear, 0 if not.
  265. */
  266. int snd_pcm_format_linear(snd_pcm_format_t format)
  267. {
  268. return snd_pcm_format_signed(format) >= 0;
  269. }
  270. EXPORT_SYMBOL(snd_pcm_format_linear);
  271. /**
  272. * snd_pcm_format_little_endian - Check the PCM format is little-endian
  273. * @format: the format to check
  274. *
  275. * Return: 1 if the given PCM format is little-endian, 0 if
  276. * big-endian, or a negative error code if endian not specified.
  277. */
  278. int snd_pcm_format_little_endian(snd_pcm_format_t format)
  279. {
  280. int val;
  281. if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
  282. return -EINVAL;
  283. if ((val = pcm_formats[(INT)format].le) < 0)
  284. return -EINVAL;
  285. return val;
  286. }
  287. EXPORT_SYMBOL(snd_pcm_format_little_endian);
  288. /**
  289. * snd_pcm_format_big_endian - Check the PCM format is big-endian
  290. * @format: the format to check
  291. *
  292. * Return: 1 if the given PCM format is big-endian, 0 if
  293. * little-endian, or a negative error code if endian not specified.
  294. */
  295. int snd_pcm_format_big_endian(snd_pcm_format_t format)
  296. {
  297. int val;
  298. val = snd_pcm_format_little_endian(format);
  299. if (val < 0)
  300. return val;
  301. return !val;
  302. }
  303. EXPORT_SYMBOL(snd_pcm_format_big_endian);
  304. /**
  305. * snd_pcm_format_width - return the bit-width of the format
  306. * @format: the format to check
  307. *
  308. * Return: The bit-width of the format, or a negative error code
  309. * if unknown format.
  310. */
  311. int snd_pcm_format_width(snd_pcm_format_t format)
  312. {
  313. int val;
  314. if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
  315. return -EINVAL;
  316. if ((val = pcm_formats[(INT)format].width) == 0)
  317. return -EINVAL;
  318. return val;
  319. }
  320. EXPORT_SYMBOL(snd_pcm_format_width);
  321. /**
  322. * snd_pcm_format_physical_width - return the physical bit-width of the format
  323. * @format: the format to check
  324. *
  325. * Return: The physical bit-width of the format, or a negative error code
  326. * if unknown format.
  327. */
  328. int snd_pcm_format_physical_width(snd_pcm_format_t format)
  329. {
  330. int val;
  331. if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
  332. return -EINVAL;
  333. if ((val = pcm_formats[(INT)format].phys) == 0)
  334. return -EINVAL;
  335. return val;
  336. }
  337. EXPORT_SYMBOL(snd_pcm_format_physical_width);
  338. /**
  339. * snd_pcm_format_size - return the byte size of samples on the given format
  340. * @format: the format to check
  341. * @samples: sampling rate
  342. *
  343. * Return: The byte size of the given samples for the format, or a
  344. * negative error code if unknown format.
  345. */
  346. ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples)
  347. {
  348. int phys_width = snd_pcm_format_physical_width(format);
  349. if (phys_width < 0)
  350. return -EINVAL;
  351. return samples * phys_width / 8;
  352. }
  353. EXPORT_SYMBOL(snd_pcm_format_size);
  354. /**
  355. * snd_pcm_format_silence_64 - return the silent data in 8 bytes array
  356. * @format: the format to check
  357. *
  358. * Return: The format pattern to fill or %NULL if error.
  359. */
  360. const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format)
  361. {
  362. if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
  363. return NULL;
  364. if (! pcm_formats[(INT)format].phys)
  365. return NULL;
  366. return pcm_formats[(INT)format].silence;
  367. }
  368. EXPORT_SYMBOL(snd_pcm_format_silence_64);
  369. /**
  370. * snd_pcm_format_set_silence - set the silence data on the buffer
  371. * @format: the PCM format
  372. * @data: the buffer pointer
  373. * @samples: the number of samples to set silence
  374. *
  375. * Sets the silence data on the buffer for the given samples.
  376. *
  377. * Return: Zero if successful, or a negative error code on failure.
  378. */
  379. int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int samples)
  380. {
  381. int width;
  382. unsigned char *dst, *pat;
  383. if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
  384. return -EINVAL;
  385. if (samples == 0)
  386. return 0;
  387. width = pcm_formats[(INT)format].phys; /* physical width */
  388. pat = pcm_formats[(INT)format].silence;
  389. if (! width)
  390. return -EINVAL;
  391. /* signed or 1 byte data */
  392. if (pcm_formats[(INT)format].signd == 1 || width <= 8) {
  393. unsigned int bytes = samples * width / 8;
  394. memset(data, *pat, bytes);
  395. return 0;
  396. }
  397. /* non-zero samples, fill using a loop */
  398. width /= 8;
  399. dst = data;
  400. #if 0
  401. while (samples--) {
  402. memcpy(dst, pat, width);
  403. dst += width;
  404. }
  405. #else
  406. /* a bit optimization for constant width */
  407. switch (width) {
  408. case 2:
  409. while (samples--) {
  410. memcpy(dst, pat, 2);
  411. dst += 2;
  412. }
  413. break;
  414. case 3:
  415. while (samples--) {
  416. memcpy(dst, pat, 3);
  417. dst += 3;
  418. }
  419. break;
  420. case 4:
  421. while (samples--) {
  422. memcpy(dst, pat, 4);
  423. dst += 4;
  424. }
  425. break;
  426. case 8:
  427. while (samples--) {
  428. memcpy(dst, pat, 8);
  429. dst += 8;
  430. }
  431. break;
  432. }
  433. #endif
  434. return 0;
  435. }
  436. EXPORT_SYMBOL(snd_pcm_format_set_silence);
  437. /**
  438. * snd_pcm_limit_hw_rates - determine rate_min/rate_max fields
  439. * @runtime: the runtime instance
  440. *
  441. * Determines the rate_min and rate_max fields from the rates bits of
  442. * the given runtime->hw.
  443. *
  444. * Return: Zero if successful.
  445. */
  446. int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime)
  447. {
  448. int i;
  449. for (i = 0; i < (int)snd_pcm_known_rates.count; i++) {
  450. if (runtime->hw.rates & (1 << i)) {
  451. runtime->hw.rate_min = snd_pcm_known_rates.list[i];
  452. break;
  453. }
  454. }
  455. for (i = (int)snd_pcm_known_rates.count - 1; i >= 0; i--) {
  456. if (runtime->hw.rates & (1 << i)) {
  457. runtime->hw.rate_max = snd_pcm_known_rates.list[i];
  458. break;
  459. }
  460. }
  461. return 0;
  462. }
  463. EXPORT_SYMBOL(snd_pcm_limit_hw_rates);
  464. /**
  465. * snd_pcm_rate_to_rate_bit - converts sample rate to SNDRV_PCM_RATE_xxx bit
  466. * @rate: the sample rate to convert
  467. *
  468. * Return: The SNDRV_PCM_RATE_xxx flag that corresponds to the given rate, or
  469. * SNDRV_PCM_RATE_KNOT for an unknown rate.
  470. */
  471. unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate)
  472. {
  473. unsigned int i;
  474. for (i = 0; i < snd_pcm_known_rates.count; i++)
  475. if (snd_pcm_known_rates.list[i] == rate)
  476. return 1u << i;
  477. return SNDRV_PCM_RATE_KNOT;
  478. }
  479. EXPORT_SYMBOL(snd_pcm_rate_to_rate_bit);
  480. /**
  481. * snd_pcm_rate_bit_to_rate - converts SNDRV_PCM_RATE_xxx bit to sample rate
  482. * @rate_bit: the rate bit to convert
  483. *
  484. * Return: The sample rate that corresponds to the given SNDRV_PCM_RATE_xxx flag
  485. * or 0 for an unknown rate bit.
  486. */
  487. unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit)
  488. {
  489. unsigned int i;
  490. for (i = 0; i < snd_pcm_known_rates.count; i++)
  491. if ((1u << i) == rate_bit)
  492. return snd_pcm_known_rates.list[i];
  493. return 0;
  494. }
  495. EXPORT_SYMBOL(snd_pcm_rate_bit_to_rate);
  496. static unsigned int snd_pcm_rate_mask_sanitize(unsigned int rates)
  497. {
  498. if (rates & SNDRV_PCM_RATE_CONTINUOUS)
  499. return SNDRV_PCM_RATE_CONTINUOUS;
  500. else if (rates & SNDRV_PCM_RATE_KNOT)
  501. return SNDRV_PCM_RATE_KNOT;
  502. return rates;
  503. }
  504. /**
  505. * snd_pcm_rate_mask_intersect - computes the intersection between two rate masks
  506. * @rates_a: The first rate mask
  507. * @rates_b: The second rate mask
  508. *
  509. * This function computes the rates that are supported by both rate masks passed
  510. * to the function. It will take care of the special handling of
  511. * SNDRV_PCM_RATE_CONTINUOUS and SNDRV_PCM_RATE_KNOT.
  512. *
  513. * Return: A rate mask containing the rates that are supported by both rates_a
  514. * and rates_b.
  515. */
  516. unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a,
  517. unsigned int rates_b)
  518. {
  519. rates_a = snd_pcm_rate_mask_sanitize(rates_a);
  520. rates_b = snd_pcm_rate_mask_sanitize(rates_b);
  521. if (rates_a & SNDRV_PCM_RATE_CONTINUOUS)
  522. return rates_b;
  523. else if (rates_b & SNDRV_PCM_RATE_CONTINUOUS)
  524. return rates_a;
  525. else if (rates_a & SNDRV_PCM_RATE_KNOT)
  526. return rates_b;
  527. else if (rates_b & SNDRV_PCM_RATE_KNOT)
  528. return rates_a;
  529. return rates_a & rates_b;
  530. }
  531. EXPORT_SYMBOL_GPL(snd_pcm_rate_mask_intersect);
  532. /**
  533. * snd_pcm_rate_range_to_bits - converts rate range to SNDRV_PCM_RATE_xxx bit
  534. * @rate_min: the minimum sample rate
  535. * @rate_max: the maximum sample rate
  536. *
  537. * This function has an implicit assumption: the rates in the given range have
  538. * only the pre-defined rates like 44100 or 16000.
  539. *
  540. * Return: The SNDRV_PCM_RATE_xxx flag that corresponds to the given rate range,
  541. * or SNDRV_PCM_RATE_KNOT for an unknown range.
  542. */
  543. unsigned int snd_pcm_rate_range_to_bits(unsigned int rate_min,
  544. unsigned int rate_max)
  545. {
  546. unsigned int rates = 0;
  547. int i;
  548. for (i = 0; i < snd_pcm_known_rates.count; i++) {
  549. if (snd_pcm_known_rates.list[i] >= rate_min
  550. && snd_pcm_known_rates.list[i] <= rate_max)
  551. rates |= 1 << i;
  552. }
  553. if (!rates)
  554. rates = SNDRV_PCM_RATE_KNOT;
  555. return rates;
  556. }
  557. EXPORT_SYMBOL_GPL(snd_pcm_rate_range_to_bits);