aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core/pcm_misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/core/pcm_misc.c')
-rw-r--r--sound/core/pcm_misc.c65
1 files changed, 23 insertions, 42 deletions
diff --git a/sound/core/pcm_misc.c b/sound/core/pcm_misc.c
index 0019c59a77..dd9aa51d8c 100644
--- a/sound/core/pcm_misc.c
+++ b/sound/core/pcm_misc.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * PCM Interface - misc routines 2 * PCM Interface - misc routines
3 * Copyright (c) 1998 by Jaroslav Kysela <perex@suse.cz> 3 * Copyright (c) 1998 by Jaroslav Kysela <perex@perex.cz>
4 * 4 *
5 * 5 *
6 * This library is free software; you can redistribute it and/or modify 6 * This library is free software; you can redistribute it and/or modify
@@ -422,38 +422,6 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
422 422
423EXPORT_SYMBOL(snd_pcm_format_set_silence); 423EXPORT_SYMBOL(snd_pcm_format_set_silence);
424 424
425/* [width][unsigned][bigendian] */
426static int linear_formats[4][2][2] = {
427 {{ SNDRV_PCM_FORMAT_S8, SNDRV_PCM_FORMAT_S8},
428 { SNDRV_PCM_FORMAT_U8, SNDRV_PCM_FORMAT_U8}},
429 {{SNDRV_PCM_FORMAT_S16_LE, SNDRV_PCM_FORMAT_S16_BE},
430 {SNDRV_PCM_FORMAT_U16_LE, SNDRV_PCM_FORMAT_U16_BE}},
431 {{SNDRV_PCM_FORMAT_S24_LE, SNDRV_PCM_FORMAT_S24_BE},
432 {SNDRV_PCM_FORMAT_U24_LE, SNDRV_PCM_FORMAT_U24_BE}},
433 {{SNDRV_PCM_FORMAT_S32_LE, SNDRV_PCM_FORMAT_S32_BE},
434 {SNDRV_PCM_FORMAT_U32_LE, SNDRV_PCM_FORMAT_U32_BE}}
435};
436
437/**
438 * snd_pcm_build_linear_format - return the suitable linear format for the given condition
439 * @width: the bit-width
440 * @unsignd: 1 if unsigned, 0 if signed.
441 * @big_endian: 1 if big-endian, 0 if little-endian
442 *
443 * Returns the suitable linear format for the given condition.
444 */
445snd_pcm_format_t snd_pcm_build_linear_format(int width, int unsignd, int big_endian)
446{
447 if (width & 7)
448 return SND_PCM_FORMAT_UNKNOWN;
449 width = (width / 8) - 1;
450 if (width < 0 || width >= 4)
451 return SND_PCM_FORMAT_UNKNOWN;
452 return linear_formats[width][!!unsignd][!!big_endian];
453}
454
455EXPORT_SYMBOL(snd_pcm_build_linear_format);
456
457/** 425/**
458 * snd_pcm_limit_hw_rates - determine rate_min/rate_max fields 426 * snd_pcm_limit_hw_rates - determine rate_min/rate_max fields
459 * @runtime: the runtime instance 427 * @runtime: the runtime instance
@@ -465,21 +433,16 @@ EXPORT_SYMBOL(snd_pcm_build_linear_format);
465 */ 433 */
466int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime) 434int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime)
467{ 435{
468 static unsigned rates[] = {
469 /* ATTENTION: these values depend on the definition in pcm.h! */
470 5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000,
471 64000, 88200, 96000, 176400, 192000
472 };
473 int i; 436 int i;
474 for (i = 0; i < (int)ARRAY_SIZE(rates); i++) { 437 for (i = 0; i < (int)snd_pcm_known_rates.count; i++) {
475 if (runtime->hw.rates & (1 << i)) { 438 if (runtime->hw.rates & (1 << i)) {
476 runtime->hw.rate_min = rates[i]; 439 runtime->hw.rate_min = snd_pcm_known_rates.list[i];
477 break; 440 break;
478 } 441 }
479 } 442 }
480 for (i = (int)ARRAY_SIZE(rates) - 1; i >= 0; i--) { 443 for (i = (int)snd_pcm_known_rates.count - 1; i >= 0; i--) {
481 if (runtime->hw.rates & (1 << i)) { 444 if (runtime->hw.rates & (1 << i)) {
482 runtime->hw.rate_max = rates[i]; 445 runtime->hw.rate_max = snd_pcm_known_rates.list[i];
483 break; 446 break;
484 } 447 }
485 } 448 }
@@ -487,3 +450,21 @@ int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime)
487} 450}
488 451
489EXPORT_SYMBOL(snd_pcm_limit_hw_rates); 452EXPORT_SYMBOL(snd_pcm_limit_hw_rates);
453
454/**
455 * snd_pcm_rate_to_rate_bit - converts sample rate to SNDRV_PCM_RATE_xxx bit
456 * @rate: the sample rate to convert
457 *
458 * Returns the SNDRV_PCM_RATE_xxx flag that corresponds to the given rate, or
459 * SNDRV_PCM_RATE_KNOT for an unknown rate.
460 */
461unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate)
462{
463 unsigned int i;
464
465 for (i = 0; i < snd_pcm_known_rates.count; i++)
466 if (snd_pcm_known_rates.list[i] == rate)
467 return 1u << i;
468 return SNDRV_PCM_RATE_KNOT;
469}
470EXPORT_SYMBOL(snd_pcm_rate_to_rate_bit);