/*
* PCM Interface - misc routines
* Copyright (c) 1998 by Jaroslav Kysela <[email protected]>
*
*
* 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
*
*/
#include <linux/time.h>
#include <linux/export.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 */
};
/* 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] = {
[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,
.silence = { 0x00, 0x80, 0x00, 0x00 },
},
[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 = {},
},
[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 = {},
},
[SNDRV_PCM_FORMAT_DSD_U8] = {
.width = 8, .phys = 8, .le = 1, .signd = 0,
.silence = {},
},
[SNDRV_PCM_FORMAT_DSD_U16_LE] = {
.width = 16, .phys = 16, .le = 1, .signd = 0,
.silence = {},
},
/* 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 },
},
[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 = {},
},
};
/**
* snd_pcm_format_signed - Check the PCM format is signed linear
* @format: the format to check
*
* Return: 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;
if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
return -EINVAL;
if ((val = pcm_formats[(INT)format].signd) < 0)
return -EINVAL;
return val;
}
EXPORT_SYMBOL(snd_pcm_format_signed);
/**
* snd_pcm_format_unsigned - Check the PCM format is unsigned linear
* @format: the format to check
*
* Return: 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;
}
EXPORT_SYMBOL(snd_pcm_format_unsigned);
/**
* snd_pcm_format_linear - Check the PCM format is linear
* @format: the format to check
*
* Return: 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;
}
EXPORT_SYMBOL(snd_pcm_format_linear);
/**
* snd_pcm_format_little_endian - Check the PCM format is little-endian
* @format: the format to check
*
* Return: 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;
if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
return -EINVAL;
if ((val = pcm_formats[(INT)format].le) < 0)
return -EINVAL;
return val;
}
EXPORT_SYMBOL(snd_pcm_format_little_endian);
/**
pcm_misc.rar_interface
版权申诉
101 浏览量
2022-09-24
20:12:28
上传
评论
收藏 3KB RAR 举报
weixin_42653672
- 粉丝: 93
- 资源: 1万+
最新资源
- flowable-designer-5.22.0.zip
- threadmanager.cpp
- 腾讯云小程序 - 一站式开发与部署平台
- 基于JSP+Java+Servlet采用MVC模式开发的购物网站+源码(毕业设计&课程设计&项目开发)
- fastgestures安装包,模拟mac的触控板收拾,两指代表右击, 三指拖拽
- 基于组态王的升降式横移立体车库控制系统+源码(毕业设计&课程设计&项目开发)
- 基于python+Django和协同过滤算法的电影推荐系统+源码(毕业设计&课程设计&项目开发)
- 环境配置 vscode+jupyter
- 项目全部代码,还包含使用到的图片
- 项目全部代码,还包含使用到的图片
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈