Blame src/pcm/pcm_linear.c

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