From 3696e16613698e1bf7a1365a297d98cb34f4a0e3 Mon Sep 17 00:00:00 2001 From: Abramo Bagnara Date: Sat, 25 Dec 1999 15:22:21 +0000 Subject: [PATCH] Added snd_pcm_build_linear_format --- include/pcm.h | 1 + src/pcm/pcm_misc.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/include/pcm.h b/include/pcm.h index be487eb6..32566e0b 100644 --- a/include/pcm.h +++ b/include/pcm.h @@ -56,6 +56,7 @@ int snd_pcm_format_linear(int format); int snd_pcm_format_little_endian(int format); int snd_pcm_format_big_endian(int format); int snd_pcm_format_width(int format); /* in bits */ +int snd_pcm_build_linear_format(int width, int unsignd, int big_endian); ssize_t snd_pcm_format_size(int format, size_t samples); const char *snd_pcm_get_format_name(int format); diff --git a/src/pcm/pcm_misc.c b/src/pcm/pcm_misc.c index 30a903d3..f4cf49ad 100644 --- a/src/pcm/pcm_misc.c +++ b/src/pcm/pcm_misc.c @@ -104,9 +104,9 @@ int snd_pcm_format_big_endian(int format) int val; val = snd_pcm_format_little_endian(format); - if (val >= 0) - val ^= 1; - return val; + if (val < 0) + return val; + return !val; } int snd_pcm_format_width(int format) @@ -227,3 +227,43 @@ const char *snd_pcm_get_format_name(int format) return "Unknown"; return formats[format]; } + +static int linear_formats[4][2][2] = { + SND_PCM_SFMT_S8, + SND_PCM_SFMT_U8, + SND_PCM_SFMT_S8, + SND_PCM_SFMT_U8, + SND_PCM_SFMT_S16_LE, + SND_PCM_SFMT_S16_BE, + SND_PCM_SFMT_U16_LE, + SND_PCM_SFMT_U16_BE, + SND_PCM_SFMT_S24_LE, + SND_PCM_SFMT_S24_BE, + SND_PCM_SFMT_U24_LE, + SND_PCM_SFMT_U24_BE, + SND_PCM_SFMT_S32_LE, + SND_PCM_SFMT_S32_BE, + SND_PCM_SFMT_U32_LE, + SND_PCM_SFMT_U32_BE +}; + +int snd_pcm_build_linear_format(int width, int unsignd, int big_endian) +{ + switch (width) { + case 8: + width = 0; + break; + case 16: + width = 1; + break; + case 24: + width = 2; + break; + case 32: + width = 3; + break; + default: + return -1; + } + return linear_formats[width][!!unsignd][!!big_endian]; +} -- 2.11.0