|
Packit Service |
db8eaa |
/**
|
|
Packit Service |
db8eaa |
* \file pcm/pcm_linear.c
|
|
Packit Service |
db8eaa |
* \ingroup PCM_Plugins
|
|
Packit Service |
db8eaa |
* \brief PCM Linear Conversion Plugin Interface
|
|
Packit Service |
db8eaa |
* \author Abramo Bagnara <abramo@alsa-project.org>
|
|
Packit Service |
db8eaa |
* \date 2000-2001
|
|
Packit Service |
db8eaa |
*/
|
|
Packit Service |
db8eaa |
/*
|
|
Packit Service |
db8eaa |
* PCM - Linear conversion
|
|
Packit Service |
db8eaa |
* Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
|
|
Packit Service |
db8eaa |
*
|
|
Packit Service |
db8eaa |
*
|
|
Packit Service |
db8eaa |
* This library is free software; you can redistribute it and/or modify
|
|
Packit Service |
db8eaa |
* it under the terms of the GNU Lesser General Public License as
|
|
Packit Service |
db8eaa |
* published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
db8eaa |
* the License, or (at your option) any later version.
|
|
Packit Service |
db8eaa |
*
|
|
Packit Service |
db8eaa |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
db8eaa |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
db8eaa |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
db8eaa |
* GNU Lesser General Public License for more details.
|
|
Packit Service |
db8eaa |
*
|
|
Packit Service |
db8eaa |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
db8eaa |
* License along with this library; if not, write to the Free Software
|
|
Packit Service |
db8eaa |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit Service |
db8eaa |
*
|
|
Packit Service |
db8eaa |
*/
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#include "bswap.h"
|
|
Packit Service |
db8eaa |
#include "pcm_local.h"
|
|
Packit Service |
db8eaa |
#include "pcm_plugin.h"
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#include "plugin_ops.h"
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#ifndef PIC
|
|
Packit Service |
db8eaa |
/* entry for static linking */
|
|
Packit Service |
db8eaa |
const char *_snd_module_pcm_linear = "";
|
|
Packit Service |
db8eaa |
#endif
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#ifndef DOC_HIDDEN
|
|
Packit Service |
db8eaa |
typedef struct {
|
|
Packit Service |
db8eaa |
/* This field need to be the first */
|
|
Packit Service |
db8eaa |
snd_pcm_plugin_t plug;
|
|
Packit Service |
db8eaa |
unsigned int use_getput;
|
|
Packit Service |
db8eaa |
unsigned int conv_idx;
|
|
Packit Service |
db8eaa |
unsigned int get_idx, put_idx;
|
|
Packit Service |
db8eaa |
snd_pcm_format_t sformat;
|
|
Packit Service |
db8eaa |
} snd_pcm_linear_t;
|
|
Packit Service |
db8eaa |
#endif
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#ifndef DOC_HIDDEN
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
int snd_pcm_linear_convert_index(snd_pcm_format_t src_format,
|
|
Packit Service |
db8eaa |
snd_pcm_format_t dst_format)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
int src_endian, dst_endian, sign, src_width, dst_width;
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
sign = (snd_pcm_format_signed(src_format) !=
|
|
Packit Service |
db8eaa |
snd_pcm_format_signed(dst_format));
|
|
Packit Service |
db8eaa |
#ifdef SND_LITTLE_ENDIAN
|
|
Packit Service |
db8eaa |
src_endian = snd_pcm_format_big_endian(src_format);
|
|
Packit Service |
db8eaa |
dst_endian = snd_pcm_format_big_endian(dst_format);
|
|
Packit Service |
db8eaa |
#else
|
|
Packit Service |
db8eaa |
src_endian = snd_pcm_format_little_endian(src_format);
|
|
Packit Service |
db8eaa |
dst_endian = snd_pcm_format_little_endian(dst_format);
|
|
Packit Service |
db8eaa |
#endif
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
if (src_endian < 0)
|
|
Packit Service |
db8eaa |
src_endian = 0;
|
|
Packit Service |
db8eaa |
if (dst_endian < 0)
|
|
Packit Service |
db8eaa |
dst_endian = 0;
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
src_width = snd_pcm_format_width(src_format) / 8 - 1;
|
|
Packit Service |
db8eaa |
dst_width = snd_pcm_format_width(dst_format) / 8 - 1;
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
return src_width * 32 + src_endian * 16 + sign * 8 + dst_width * 2 + dst_endian;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
int snd_pcm_linear_get_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
int sign, width, pwidth, endian;
|
|
Packit Service |
db8eaa |
sign = (snd_pcm_format_signed(src_format) !=
|
|
Packit Service |
db8eaa |
snd_pcm_format_signed(dst_format));
|
|
Packit Service |
db8eaa |
#ifdef SND_LITTLE_ENDIAN
|
|
Packit Service |
db8eaa |
endian = snd_pcm_format_big_endian(src_format);
|
|
Packit Service |
db8eaa |
#else
|
|
Packit Service |
db8eaa |
endian = snd_pcm_format_little_endian(src_format);
|
|
Packit Service |
db8eaa |
#endif
|
|
Packit Service |
db8eaa |
if (endian < 0)
|
|
Packit Service |
db8eaa |
endian = 0;
|
|
Packit Service |
db8eaa |
pwidth = snd_pcm_format_physical_width(src_format);
|
|
Packit Service |
db8eaa |
width = snd_pcm_format_width(src_format);
|
|
Packit Service |
db8eaa |
if (pwidth == 24) {
|
|
Packit Service |
db8eaa |
switch (width) {
|
|
Packit Service |
db8eaa |
case 24:
|
|
Packit Service |
db8eaa |
width = 0; break;
|
|
Packit Service |
db8eaa |
case 20:
|
|
Packit Service |
db8eaa |
width = 1; break;
|
|
Packit Service |
db8eaa |
case 18:
|
|
Packit Service |
db8eaa |
default:
|
|
Packit Service |
db8eaa |
width = 2; break;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
return width * 4 + endian * 2 + sign + 20;
|
|
Packit Service |
db8eaa |
} else {
|
|
Packit Service |
db8eaa |
if (width == 20)
|
|
Packit Service |
db8eaa |
width = 40;
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
width = width / 8 - 1;
|
|
Packit Service |
db8eaa |
return width * 4 + endian * 2 + sign;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
int snd_pcm_linear_put_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
int sign, width, pwidth, endian;
|
|
Packit Service |
db8eaa |
sign = (snd_pcm_format_signed(src_format) !=
|
|
Packit Service |
db8eaa |
snd_pcm_format_signed(dst_format));
|
|
Packit Service |
db8eaa |
#ifdef SND_LITTLE_ENDIAN
|
|
Packit Service |
db8eaa |
endian = snd_pcm_format_big_endian(dst_format);
|
|
Packit Service |
db8eaa |
#else
|
|
Packit Service |
db8eaa |
endian = snd_pcm_format_little_endian(dst_format);
|
|
Packit Service |
db8eaa |
#endif
|
|
Packit Service |
db8eaa |
if (endian < 0)
|
|
Packit Service |
db8eaa |
endian = 0;
|
|
Packit Service |
db8eaa |
pwidth = snd_pcm_format_physical_width(dst_format);
|
|
Packit Service |
db8eaa |
width = snd_pcm_format_width(dst_format);
|
|
Packit Service |
db8eaa |
if (pwidth == 24) {
|
|
Packit Service |
db8eaa |
switch (width) {
|
|
Packit Service |
db8eaa |
case 24:
|
|
Packit Service |
db8eaa |
width = 0; break;
|
|
Packit Service |
db8eaa |
case 20:
|
|
Packit Service |
db8eaa |
width = 1; break;
|
|
Packit Service |
db8eaa |
case 18:
|
|
Packit Service |
db8eaa |
default:
|
|
Packit Service |
db8eaa |
width = 2; break;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
return width * 4 + endian * 2 + sign + 20;
|
|
Packit Service |
db8eaa |
} else {
|
|
Packit Service |
db8eaa |
if (width == 20)
|
|
Packit Service |
db8eaa |
width = 40;
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
width = width / 8 - 1;
|
|
Packit Service |
db8eaa |
return width * 4 + endian * 2 + sign;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
void snd_pcm_linear_convert(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
|
|
Packit Service |
db8eaa |
const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset,
|
|
Packit Service |
db8eaa |
unsigned int channels, snd_pcm_uframes_t frames,
|
|
Packit Service |
db8eaa |
unsigned int convidx)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
#define CONV_LABELS
|
|
Packit Service |
db8eaa |
#include "plugin_ops.h"
|
|
Packit Service |
db8eaa |
#undef CONV_LABELS
|
|
Packit Service |
db8eaa |
void *conv = conv_labels[convidx];
|
|
Packit Service |
db8eaa |
unsigned int channel;
|
|
Packit Service |
db8eaa |
for (channel = 0; channel < channels; ++channel) {
|
|
Packit Service |
db8eaa |
const char *src;
|
|
Packit Service |
db8eaa |
char *dst;
|
|
Packit Service |
db8eaa |
int src_step, dst_step;
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t frames1;
|
|
Packit Service |
db8eaa |
const snd_pcm_channel_area_t *src_area = &src_areas[channel];
|
|
Packit Service |
db8eaa |
const snd_pcm_channel_area_t *dst_area = &dst_areas[channel];
|
|
Packit Service |
db8eaa |
src = snd_pcm_channel_area_addr(src_area, src_offset);
|
|
Packit Service |
db8eaa |
dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
|
|
Packit Service |
db8eaa |
src_step = snd_pcm_channel_area_step(src_area);
|
|
Packit Service |
db8eaa |
dst_step = snd_pcm_channel_area_step(dst_area);
|
|
Packit Service |
db8eaa |
frames1 = frames;
|
|
Packit Service |
db8eaa |
while (frames1-- > 0) {
|
|
Packit Service |
db8eaa |
goto *conv;
|
|
Packit Service |
db8eaa |
#define CONV_END after
|
|
Packit Service |
db8eaa |
#include "plugin_ops.h"
|
|
Packit Service |
db8eaa |
#undef CONV_END
|
|
Packit Service |
db8eaa |
after:
|
|
Packit Service |
db8eaa |
src += src_step;
|
|
Packit Service |
db8eaa |
dst += dst_step;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
void snd_pcm_linear_getput(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
|
|
Packit Service |
db8eaa |
const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset,
|
|
Packit Service |
db8eaa |
unsigned int channels, snd_pcm_uframes_t frames,
|
|
Packit Service |
db8eaa |
unsigned int get_idx, unsigned int put_idx)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
#define CONV24_LABELS
|
|
Packit Service |
db8eaa |
#include "plugin_ops.h"
|
|
Packit Service |
db8eaa |
#undef CONV24_LABELS
|
|
Packit Service |
db8eaa |
void *get = get32_labels[get_idx];
|
|
Packit Service |
db8eaa |
void *put = put32_labels[put_idx];
|
|
Packit Service |
db8eaa |
unsigned int channel;
|
|
Packit Service |
db8eaa |
uint32_t sample = 0;
|
|
Packit Service |
db8eaa |
for (channel = 0; channel < channels; ++channel) {
|
|
Packit Service |
db8eaa |
const char *src;
|
|
Packit Service |
db8eaa |
char *dst;
|
|
Packit Service |
db8eaa |
int src_step, dst_step;
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t frames1;
|
|
Packit Service |
db8eaa |
const snd_pcm_channel_area_t *src_area = &src_areas[channel];
|
|
Packit Service |
db8eaa |
const snd_pcm_channel_area_t *dst_area = &dst_areas[channel];
|
|
Packit Service |
db8eaa |
src = snd_pcm_channel_area_addr(src_area, src_offset);
|
|
Packit Service |
db8eaa |
dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
|
|
Packit Service |
db8eaa |
src_step = snd_pcm_channel_area_step(src_area);
|
|
Packit Service |
db8eaa |
dst_step = snd_pcm_channel_area_step(dst_area);
|
|
Packit Service |
db8eaa |
frames1 = frames;
|
|
Packit Service |
db8eaa |
while (frames1-- > 0) {
|
|
Packit Service |
db8eaa |
goto *get;
|
|
Packit Service |
db8eaa |
#define CONV24_END after
|
|
Packit Service |
db8eaa |
#include "plugin_ops.h"
|
|
Packit Service |
db8eaa |
#undef CONV24_END
|
|
Packit Service |
db8eaa |
after:
|
|
Packit Service |
db8eaa |
src += src_step;
|
|
Packit Service |
db8eaa |
dst += dst_step;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#endif /* DOC_HIDDEN */
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static int snd_pcm_linear_hw_refine_cprepare(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
int err;
|
|
Packit Service |
db8eaa |
snd_pcm_access_mask_t access_mask = { SND_PCM_ACCBIT_SHM };
|
|
Packit Service |
db8eaa |
snd_pcm_format_mask_t format_mask = { SND_PCM_FMTBIT_LINEAR };
|
|
Packit Service |
db8eaa |
err = _snd_pcm_hw_param_set_mask(params, SND_PCM_HW_PARAM_ACCESS,
|
|
Packit Service |
db8eaa |
&access_mask);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
err = _snd_pcm_hw_param_set_mask(params, SND_PCM_HW_PARAM_FORMAT,
|
|
Packit Service |
db8eaa |
&format_mask);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
err = _snd_pcm_hw_params_set_subformat(params, SND_PCM_SUBFORMAT_STD);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
params->info &= ~(SND_PCM_INFO_MMAP | SND_PCM_INFO_MMAP_VALID);
|
|
Packit Service |
db8eaa |
return 0;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static int snd_pcm_linear_hw_refine_sprepare(snd_pcm_t *pcm, snd_pcm_hw_params_t *sparams)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
snd_pcm_linear_t *linear = pcm->private_data;
|
|
Packit Service |
db8eaa |
snd_pcm_access_mask_t saccess_mask = { SND_PCM_ACCBIT_MMAP };
|
|
Packit Service |
db8eaa |
_snd_pcm_hw_params_any(sparams);
|
|
Packit Service |
db8eaa |
_snd_pcm_hw_param_set_mask(sparams, SND_PCM_HW_PARAM_ACCESS,
|
|
Packit Service |
db8eaa |
&saccess_mask);
|
|
Packit Service |
db8eaa |
_snd_pcm_hw_params_set_format(sparams, linear->sformat);
|
|
Packit Service |
db8eaa |
_snd_pcm_hw_params_set_subformat(sparams, SND_PCM_SUBFORMAT_STD);
|
|
Packit Service |
db8eaa |
return 0;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static int snd_pcm_linear_hw_refine_schange(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params,
|
|
Packit Service |
db8eaa |
snd_pcm_hw_params_t *sparams)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
int err;
|
|
Packit Service |
db8eaa |
unsigned int links = (SND_PCM_HW_PARBIT_CHANNELS |
|
|
Packit Service |
db8eaa |
SND_PCM_HW_PARBIT_RATE |
|
|
Packit Service |
db8eaa |
SND_PCM_HW_PARBIT_PERIOD_SIZE |
|
|
Packit Service |
db8eaa |
SND_PCM_HW_PARBIT_BUFFER_SIZE |
|
|
Packit Service |
db8eaa |
SND_PCM_HW_PARBIT_PERIODS |
|
|
Packit Service |
db8eaa |
SND_PCM_HW_PARBIT_PERIOD_TIME |
|
|
Packit Service |
db8eaa |
SND_PCM_HW_PARBIT_BUFFER_TIME |
|
|
Packit Service |
db8eaa |
SND_PCM_HW_PARBIT_TICK_TIME);
|
|
Packit Service |
db8eaa |
err = _snd_pcm_hw_params_refine(sparams, links, params);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
return 0;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static int snd_pcm_linear_hw_refine_cchange(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params,
|
|
Packit Service |
db8eaa |
snd_pcm_hw_params_t *sparams)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
int err;
|
|
Packit Service |
db8eaa |
unsigned int links = (SND_PCM_HW_PARBIT_CHANNELS |
|
|
Packit Service |
db8eaa |
SND_PCM_HW_PARBIT_RATE |
|
|
Packit Service |
db8eaa |
SND_PCM_HW_PARBIT_PERIOD_SIZE |
|
|
Packit Service |
db8eaa |
SND_PCM_HW_PARBIT_BUFFER_SIZE |
|
|
Packit Service |
db8eaa |
SND_PCM_HW_PARBIT_PERIODS |
|
|
Packit Service |
db8eaa |
SND_PCM_HW_PARBIT_PERIOD_TIME |
|
|
Packit Service |
db8eaa |
SND_PCM_HW_PARBIT_BUFFER_TIME |
|
|
Packit Service |
db8eaa |
SND_PCM_HW_PARBIT_TICK_TIME);
|
|
Packit Service |
db8eaa |
err = _snd_pcm_hw_params_refine(params, links, sparams);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
return 0;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static int snd_pcm_linear_hw_refine(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
return snd_pcm_hw_refine_slave(pcm, params,
|
|
Packit Service |
db8eaa |
snd_pcm_linear_hw_refine_cprepare,
|
|
Packit Service |
db8eaa |
snd_pcm_linear_hw_refine_cchange,
|
|
Packit Service |
db8eaa |
snd_pcm_linear_hw_refine_sprepare,
|
|
Packit Service |
db8eaa |
snd_pcm_linear_hw_refine_schange,
|
|
Packit Service |
db8eaa |
snd_pcm_generic_hw_refine);
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static int snd_pcm_linear_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
snd_pcm_linear_t *linear = pcm->private_data;
|
|
Packit Service |
db8eaa |
snd_pcm_format_t format;
|
|
Packit Service |
db8eaa |
int err = snd_pcm_hw_params_slave(pcm, params,
|
|
Packit Service |
db8eaa |
snd_pcm_linear_hw_refine_cchange,
|
|
Packit Service |
db8eaa |
snd_pcm_linear_hw_refine_sprepare,
|
|
Packit Service |
db8eaa |
snd_pcm_linear_hw_refine_schange,
|
|
Packit Service |
db8eaa |
snd_pcm_generic_hw_params);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
err = INTERNAL(snd_pcm_hw_params_get_format)(params, &format);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
linear->use_getput = (snd_pcm_format_physical_width(format) == 24 ||
|
|
Packit Service |
db8eaa |
snd_pcm_format_physical_width(linear->sformat) == 24 ||
|
|
Packit Service |
db8eaa |
snd_pcm_format_width(format) == 20 ||
|
|
Packit Service |
db8eaa |
snd_pcm_format_width(linear->sformat) == 20);
|
|
Packit Service |
db8eaa |
if (linear->use_getput) {
|
|
Packit Service |
db8eaa |
if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
|
|
Packit Service |
db8eaa |
linear->get_idx = snd_pcm_linear_get_index(format, SND_PCM_FORMAT_S32);
|
|
Packit Service |
db8eaa |
linear->put_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_S32, linear->sformat);
|
|
Packit Service |
db8eaa |
} else {
|
|
Packit Service |
db8eaa |
linear->get_idx = snd_pcm_linear_get_index(linear->sformat, SND_PCM_FORMAT_S32);
|
|
Packit Service |
db8eaa |
linear->put_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_S32, format);
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
} else {
|
|
Packit Service |
db8eaa |
if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
|
|
Packit Service |
db8eaa |
linear->conv_idx = snd_pcm_linear_convert_index(format,
|
|
Packit Service |
db8eaa |
linear->sformat);
|
|
Packit Service |
db8eaa |
else
|
|
Packit Service |
db8eaa |
linear->conv_idx = snd_pcm_linear_convert_index(linear->sformat,
|
|
Packit Service |
db8eaa |
format);
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
return 0;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static snd_pcm_uframes_t
|
|
Packit Service |
db8eaa |
snd_pcm_linear_write_areas(snd_pcm_t *pcm,
|
|
Packit Service |
db8eaa |
const snd_pcm_channel_area_t *areas,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t offset,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t size,
|
|
Packit Service |
db8eaa |
const snd_pcm_channel_area_t *slave_areas,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t slave_offset,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t *slave_sizep)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
snd_pcm_linear_t *linear = pcm->private_data;
|
|
Packit Service |
db8eaa |
if (size > *slave_sizep)
|
|
Packit Service |
db8eaa |
size = *slave_sizep;
|
|
Packit Service |
db8eaa |
if (linear->use_getput)
|
|
Packit Service |
db8eaa |
snd_pcm_linear_getput(slave_areas, slave_offset,
|
|
Packit Service |
db8eaa |
areas, offset,
|
|
Packit Service |
db8eaa |
pcm->channels, size,
|
|
Packit Service |
db8eaa |
linear->get_idx, linear->put_idx);
|
|
Packit Service |
db8eaa |
else
|
|
Packit Service |
db8eaa |
snd_pcm_linear_convert(slave_areas, slave_offset,
|
|
Packit Service |
db8eaa |
areas, offset,
|
|
Packit Service |
db8eaa |
pcm->channels, size, linear->conv_idx);
|
|
Packit Service |
db8eaa |
*slave_sizep = size;
|
|
Packit Service |
db8eaa |
return size;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static snd_pcm_uframes_t
|
|
Packit Service |
db8eaa |
snd_pcm_linear_read_areas(snd_pcm_t *pcm,
|
|
Packit Service |
db8eaa |
const snd_pcm_channel_area_t *areas,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t offset,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t size,
|
|
Packit Service |
db8eaa |
const snd_pcm_channel_area_t *slave_areas,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t slave_offset,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t *slave_sizep)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
snd_pcm_linear_t *linear = pcm->private_data;
|
|
Packit Service |
db8eaa |
if (size > *slave_sizep)
|
|
Packit Service |
db8eaa |
size = *slave_sizep;
|
|
Packit Service |
db8eaa |
if (linear->use_getput)
|
|
Packit Service |
db8eaa |
snd_pcm_linear_getput(areas, offset,
|
|
Packit Service |
db8eaa |
slave_areas, slave_offset,
|
|
Packit Service |
db8eaa |
pcm->channels, size,
|
|
Packit Service |
db8eaa |
linear->get_idx, linear->put_idx);
|
|
Packit Service |
db8eaa |
else
|
|
Packit Service |
db8eaa |
snd_pcm_linear_convert(areas, offset,
|
|
Packit Service |
db8eaa |
slave_areas, slave_offset,
|
|
Packit Service |
db8eaa |
pcm->channels, size, linear->conv_idx);
|
|
Packit Service |
db8eaa |
*slave_sizep = size;
|
|
Packit Service |
db8eaa |
return size;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static void snd_pcm_linear_dump(snd_pcm_t *pcm, snd_output_t *out)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
snd_pcm_linear_t *linear = pcm->private_data;
|
|
Packit Service |
db8eaa |
snd_output_printf(out, "Linear conversion PCM (%s)\n",
|
|
Packit Service |
db8eaa |
snd_pcm_format_name(linear->sformat));
|
|
Packit Service |
db8eaa |
if (pcm->setup) {
|
|
Packit Service |
db8eaa |
snd_output_printf(out, "Its setup is:\n");
|
|
Packit Service |
db8eaa |
snd_pcm_dump_setup(pcm, out);
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
snd_output_printf(out, "Slave: ");
|
|
Packit Service |
db8eaa |
snd_pcm_dump(linear->plug.gen.slave, out);
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static const snd_pcm_ops_t snd_pcm_linear_ops = {
|
|
Packit Service |
db8eaa |
.close = snd_pcm_generic_close,
|
|
Packit Service |
db8eaa |
.info = snd_pcm_generic_info,
|
|
Packit Service |
db8eaa |
.hw_refine = snd_pcm_linear_hw_refine,
|
|
Packit Service |
db8eaa |
.hw_params = snd_pcm_linear_hw_params,
|
|
Packit Service |
db8eaa |
.hw_free = snd_pcm_generic_hw_free,
|
|
Packit Service |
db8eaa |
.sw_params = snd_pcm_generic_sw_params,
|
|
Packit Service |
db8eaa |
.channel_info = snd_pcm_generic_channel_info,
|
|
Packit Service |
db8eaa |
.dump = snd_pcm_linear_dump,
|
|
Packit Service |
db8eaa |
.nonblock = snd_pcm_generic_nonblock,
|
|
Packit Service |
db8eaa |
.async = snd_pcm_generic_async,
|
|
Packit Service |
db8eaa |
.mmap = snd_pcm_generic_mmap,
|
|
Packit Service |
db8eaa |
.munmap = snd_pcm_generic_munmap,
|
|
Packit Service |
db8eaa |
.query_chmaps = snd_pcm_generic_query_chmaps,
|
|
Packit Service |
db8eaa |
.get_chmap = snd_pcm_generic_get_chmap,
|
|
Packit Service |
db8eaa |
.set_chmap = snd_pcm_generic_set_chmap,
|
|
Packit Service |
db8eaa |
};
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/**
|
|
Packit Service |
db8eaa |
* \brief Creates a new linear conversion PCM
|
|
Packit Service |
db8eaa |
* \param pcmp Returns created PCM handle
|
|
Packit Service |
db8eaa |
* \param name Name of PCM
|
|
Packit Service |
db8eaa |
* \param sformat Slave (destination) format
|
|
Packit Service |
db8eaa |
* \param slave Slave PCM handle
|
|
Packit Service |
db8eaa |
* \param close_slave When set, the slave PCM handle is closed with copy PCM
|
|
Packit Service |
db8eaa |
* \retval zero on success otherwise a negative error code
|
|
Packit Service |
db8eaa |
* \warning Using of this function might be dangerous in the sense
|
|
Packit Service |
db8eaa |
* of compatibility reasons. The prototype might be freely
|
|
Packit Service |
db8eaa |
* changed in future.
|
|
Packit Service |
db8eaa |
*/
|
|
Packit Service |
db8eaa |
int snd_pcm_linear_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sformat, snd_pcm_t *slave, int close_slave)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
snd_pcm_t *pcm;
|
|
Packit Service |
db8eaa |
snd_pcm_linear_t *linear;
|
|
Packit Service |
db8eaa |
int err;
|
|
Packit Service |
db8eaa |
assert(pcmp && slave);
|
|
Packit Service |
db8eaa |
if (snd_pcm_format_linear(sformat) != 1)
|
|
Packit Service |
db8eaa |
return -EINVAL;
|
|
Packit Service |
db8eaa |
linear = calloc(1, sizeof(snd_pcm_linear_t));
|
|
Packit Service |
db8eaa |
if (!linear) {
|
|
Packit Service |
db8eaa |
return -ENOMEM;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
snd_pcm_plugin_init(&linear->plug);
|
|
Packit Service |
db8eaa |
linear->sformat = sformat;
|
|
Packit Service |
db8eaa |
linear->plug.read = snd_pcm_linear_read_areas;
|
|
Packit Service |
db8eaa |
linear->plug.write = snd_pcm_linear_write_areas;
|
|
Packit Service |
db8eaa |
linear->plug.undo_read = snd_pcm_plugin_undo_read_generic;
|
|
Packit Service |
db8eaa |
linear->plug.undo_write = snd_pcm_plugin_undo_write_generic;
|
|
Packit Service |
db8eaa |
linear->plug.gen.slave = slave;
|
|
Packit Service |
db8eaa |
linear->plug.gen.close_slave = close_slave;
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
err = snd_pcm_new(&pcm, SND_PCM_TYPE_LINEAR, name, slave->stream, slave->mode);
|
|
Packit Service |
db8eaa |
if (err < 0) {
|
|
Packit Service |
db8eaa |
free(linear);
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
pcm->ops = &snd_pcm_linear_ops;
|
|
Packit Service |
db8eaa |
pcm->fast_ops = &snd_pcm_plugin_fast_ops;
|
|
Packit Service |
db8eaa |
pcm->private_data = linear;
|
|
Packit Service |
db8eaa |
pcm->poll_fd = slave->poll_fd;
|
|
Packit Service |
db8eaa |
pcm->poll_events = slave->poll_events;
|
|
Packit Service |
db8eaa |
pcm->tstamp_type = slave->tstamp_type;
|
|
Packit Service |
db8eaa |
snd_pcm_set_hw_ptr(pcm, &linear->plug.hw_ptr, -1, 0);
|
|
Packit Service |
db8eaa |
snd_pcm_set_appl_ptr(pcm, &linear->plug.appl_ptr, -1, 0);
|
|
Packit Service |
db8eaa |
*pcmp = pcm;
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
return 0;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/*! \page pcm_plugins
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
\section pcm_plugins_linear Plugin: linear
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
This plugin converts linear samples from master linear conversion PCM to given
|
|
Packit Service |
db8eaa |
slave PCM. The channel count, format and rate must match for both of them.
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
\code
|
|
Packit Service |
db8eaa |
pcm.name {
|
|
Packit Service |
db8eaa |
type linear # Linear conversion PCM
|
|
Packit Service |
db8eaa |
slave STR # Slave name
|
|
Packit Service |
db8eaa |
# or
|
|
Packit Service |
db8eaa |
slave { # Slave definition
|
|
Packit Service |
db8eaa |
pcm STR # Slave PCM name
|
|
Packit Service |
db8eaa |
# or
|
|
Packit Service |
db8eaa |
pcm { } # Slave PCM definition
|
|
Packit Service |
db8eaa |
format STR # Slave format
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
\endcode
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
\subsection pcm_plugins_linear_funcref Function reference
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
snd_pcm_linear_open()
|
|
Packit Service |
db8eaa |
_snd_pcm_linear_open()
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
*/
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/**
|
|
Packit Service |
db8eaa |
* \brief Creates a new linear conversion PCM
|
|
Packit Service |
db8eaa |
* \param pcmp Returns created PCM handle
|
|
Packit Service |
db8eaa |
* \param name Name of PCM
|
|
Packit Service |
db8eaa |
* \param root Root configuration node
|
|
Packit Service |
db8eaa |
* \param conf Configuration node with copy PCM description
|
|
Packit Service |
db8eaa |
* \param stream Stream type
|
|
Packit Service |
db8eaa |
* \param mode Stream mode
|
|
Packit Service |
db8eaa |
* \retval zero on success otherwise a negative error code
|
|
Packit Service |
db8eaa |
* \warning Using of this function might be dangerous in the sense
|
|
Packit Service |
db8eaa |
* of compatibility reasons. The prototype might be freely
|
|
Packit Service |
db8eaa |
* changed in future.
|
|
Packit Service |
db8eaa |
*/
|
|
Packit Service |
db8eaa |
int _snd_pcm_linear_open(snd_pcm_t **pcmp, const char *name,
|
|
Packit Service |
db8eaa |
snd_config_t *root, snd_config_t *conf,
|
|
Packit Service |
db8eaa |
snd_pcm_stream_t stream, int mode)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
snd_config_iterator_t i, next;
|
|
Packit Service |
db8eaa |
int err;
|
|
Packit Service |
db8eaa |
snd_pcm_t *spcm;
|
|
Packit Service |
db8eaa |
snd_config_t *slave = NULL, *sconf;
|
|
Packit Service |
db8eaa |
snd_pcm_format_t sformat;
|
|
Packit Service |
db8eaa |
snd_config_for_each(i, next, conf) {
|
|
Packit Service |
db8eaa |
snd_config_t *n = snd_config_iterator_entry(i);
|
|
Packit Service |
db8eaa |
const char *id;
|
|
Packit Service |
db8eaa |
if (snd_config_get_id(n, &id) < 0)
|
|
Packit Service |
db8eaa |
continue;
|
|
Packit Service |
db8eaa |
if (snd_pcm_conf_generic_id(id))
|
|
Packit Service |
db8eaa |
continue;
|
|
Packit Service |
db8eaa |
if (strcmp(id, "slave") == 0) {
|
|
Packit Service |
db8eaa |
slave = n;
|
|
Packit Service |
db8eaa |
continue;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
SNDERR("Unknown field %s", id);
|
|
Packit Service |
db8eaa |
return -EINVAL;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
if (!slave) {
|
|
Packit Service |
db8eaa |
SNDERR("slave is not defined");
|
|
Packit Service |
db8eaa |
return -EINVAL;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
err = snd_pcm_slave_conf(root, slave, &sconf, 1,
|
|
Packit Service |
db8eaa |
SND_PCM_HW_PARAM_FORMAT, SCONF_MANDATORY, &sformat);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
if (snd_pcm_format_linear(sformat) != 1) {
|
|
Packit Service |
db8eaa |
snd_config_delete(sconf);
|
|
Packit Service |
db8eaa |
SNDERR("slave format is not linear");
|
|
Packit Service |
db8eaa |
return -EINVAL;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
err = snd_pcm_open_slave(&spcm, root, sconf, stream, mode, conf);
|
|
Packit Service |
db8eaa |
snd_config_delete(sconf);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
err = snd_pcm_linear_open(pcmp, name, sformat, spcm, 1);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
snd_pcm_close(spcm);
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
#ifndef DOC_HIDDEN
|
|
Packit Service |
db8eaa |
SND_DLSYM_BUILD_VERSION(_snd_pcm_linear_open, SND_PCM_DLSYM_VERSION);
|
|
Packit Service |
db8eaa |
#endif
|