Blame src/pcm/pcm_rate.c

Packit 4a16fb
/**
Packit 4a16fb
 * \file pcm/pcm_rate.c
Packit 4a16fb
 * \ingroup PCM_Plugins
Packit 4a16fb
 * \brief PCM Rate Plugin Interface
Packit 4a16fb
 * \author Abramo Bagnara <abramo@alsa-project.org>
Packit 4a16fb
 * \author Jaroslav Kysela <perex@perex.cz>
Packit 4a16fb
 * \date 2000-2004
Packit 4a16fb
 */
Packit 4a16fb
/*
Packit 4a16fb
 *  PCM - Rate conversion
Packit 4a16fb
 *  Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
Packit 4a16fb
 *                2004 by Jaroslav Kysela <perex@perex.cz>
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
#include <inttypes.h>
Packit 4a16fb
#include "bswap.h"
Packit 4a16fb
#include "pcm_local.h"
Packit 4a16fb
#include "pcm_plugin.h"
Packit 4a16fb
#include "pcm_rate.h"
Packit 4a16fb
Packit 4a16fb
#include "plugin_ops.h"
Packit 4a16fb
Packit 4a16fb
#if 0
Packit 4a16fb
#define DEBUG_REFINE
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
#ifndef PIC
Packit 4a16fb
/* entry for static linking */
Packit 4a16fb
const char *_snd_module_pcm_rate = "";
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
#ifndef DOC_HIDDEN
Packit 4a16fb
Packit 4a16fb
typedef struct _snd_pcm_rate snd_pcm_rate_t;
Packit 4a16fb
Packit 4a16fb
struct _snd_pcm_rate {
Packit 4a16fb
	snd_pcm_generic_t gen;
Packit 4a16fb
	snd_pcm_uframes_t appl_ptr, hw_ptr, last_slave_hw_ptr;
Packit 4a16fb
	snd_pcm_uframes_t last_commit_ptr;
Packit 4a16fb
	snd_pcm_uframes_t orig_avail_min;
Packit 4a16fb
	snd_pcm_sw_params_t sw_params;
Packit 4a16fb
	snd_pcm_format_t sformat;
Packit 4a16fb
	unsigned int srate;
Packit 4a16fb
	snd_pcm_channel_area_t *pareas;	/* areas for splitted period (rate pcm) */
Packit 4a16fb
	snd_pcm_channel_area_t *sareas;	/* areas for splitted period (slave pcm) */
Packit 4a16fb
	snd_pcm_rate_info_t info;
Packit 4a16fb
	void *open_func;
Packit 4a16fb
	void *obj;
Packit 4a16fb
	snd_pcm_rate_ops_t ops;
Packit 4a16fb
	unsigned int get_idx;
Packit 4a16fb
	unsigned int put_idx;
Packit 4a16fb
	int16_t *src_buf;
Packit 4a16fb
	int16_t *dst_buf;
Packit 4a16fb
	int start_pending; /* start is triggered but not commited to slave */
Packit 4a16fb
	snd_htimestamp_t trigger_tstamp;
Packit 4a16fb
	unsigned int plugin_version;
Packit 4a16fb
	unsigned int rate_min, rate_max;
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
#define SND_PCM_RATE_PLUGIN_VERSION_OLD	0x010001	/* old rate plugin */
Packit 4a16fb
Packit 4a16fb
#endif /* DOC_HIDDEN */
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_hw_refine_cprepare(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
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
	if (rate->rate_min) {
Packit 4a16fb
		err = _snd_pcm_hw_param_set_min(params, SND_PCM_HW_PARAM_RATE,
Packit 4a16fb
						rate->rate_min, 0);
Packit 4a16fb
		if (err < 0)
Packit 4a16fb
			return err;
Packit 4a16fb
	}
Packit 4a16fb
	if (rate->rate_max) {
Packit 4a16fb
		err = _snd_pcm_hw_param_set_max(params, SND_PCM_HW_PARAM_RATE,
Packit 4a16fb
						rate->rate_max, 0);
Packit 4a16fb
		if (err < 0)
Packit 4a16fb
			return err;
Packit 4a16fb
	}
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_rate_hw_refine_sprepare(snd_pcm_t *pcm, snd_pcm_hw_params_t *sparams)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = 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
	if (rate->sformat != SND_PCM_FORMAT_UNKNOWN) {
Packit 4a16fb
		_snd_pcm_hw_params_set_format(sparams, rate->sformat);
Packit 4a16fb
		_snd_pcm_hw_params_set_subformat(sparams, SND_PCM_SUBFORMAT_STD);
Packit 4a16fb
	}
Packit 4a16fb
	_snd_pcm_hw_param_set_minmax(sparams, SND_PCM_HW_PARAM_RATE,
Packit 4a16fb
				     rate->srate, 0, rate->srate + 1, -1);
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_hw_refine_schange(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
Packit 4a16fb
					  snd_pcm_hw_params_t *sparams)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	snd_interval_t t, buffer_size;
Packit 4a16fb
	const snd_interval_t *srate, *crate;
Packit 4a16fb
	int err;
Packit 4a16fb
	unsigned int links = (SND_PCM_HW_PARBIT_CHANNELS |
Packit 4a16fb
			      SND_PCM_HW_PARBIT_PERIOD_TIME |
Packit 4a16fb
			      SND_PCM_HW_PARBIT_TICK_TIME);
Packit 4a16fb
	if (rate->sformat == SND_PCM_FORMAT_UNKNOWN)
Packit 4a16fb
		links |= (SND_PCM_HW_PARBIT_FORMAT |
Packit 4a16fb
			  SND_PCM_HW_PARBIT_SUBFORMAT |
Packit 4a16fb
			  SND_PCM_HW_PARBIT_SAMPLE_BITS |
Packit 4a16fb
			  SND_PCM_HW_PARBIT_FRAME_BITS);
Packit 4a16fb
	snd_interval_copy(&buffer_size, snd_pcm_hw_param_get_interval(params, SND_PCM_HW_PARAM_BUFFER_SIZE));
Packit 4a16fb
	snd_interval_unfloor(&buffer_size);
Packit 4a16fb
	crate = snd_pcm_hw_param_get_interval(params, SND_PCM_HW_PARAM_RATE);
Packit 4a16fb
	srate = snd_pcm_hw_param_get_interval(sparams, SND_PCM_HW_PARAM_RATE);
Packit 4a16fb
	snd_interval_muldiv(&buffer_size, srate, crate, &t);
Packit 4a16fb
	err = _snd_pcm_hw_param_set_interval(sparams, SND_PCM_HW_PARAM_BUFFER_SIZE, &t);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
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_rate_hw_refine_cchange(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
Packit 4a16fb
					  snd_pcm_hw_params_t *sparams)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	snd_interval_t t;
Packit 4a16fb
#ifdef DEBUG_REFINE
Packit 4a16fb
	snd_output_t *out;
Packit 4a16fb
#endif
Packit 4a16fb
	const snd_interval_t *sbuffer_size, *buffer_size;
Packit 4a16fb
	const snd_interval_t *srate, *crate;
Packit 4a16fb
	int err;
Packit 4a16fb
	unsigned int links = (SND_PCM_HW_PARBIT_CHANNELS |
Packit 4a16fb
			      SND_PCM_HW_PARBIT_PERIOD_TIME |
Packit 4a16fb
			      SND_PCM_HW_PARBIT_TICK_TIME);
Packit 4a16fb
	if (rate->sformat == SND_PCM_FORMAT_UNKNOWN)
Packit 4a16fb
		links |= (SND_PCM_HW_PARBIT_FORMAT |
Packit 4a16fb
			  SND_PCM_HW_PARBIT_SUBFORMAT |
Packit 4a16fb
			  SND_PCM_HW_PARBIT_SAMPLE_BITS |
Packit 4a16fb
			  SND_PCM_HW_PARBIT_FRAME_BITS);
Packit 4a16fb
	sbuffer_size = snd_pcm_hw_param_get_interval(sparams, SND_PCM_HW_PARAM_BUFFER_SIZE);
Packit 4a16fb
	crate = snd_pcm_hw_param_get_interval(params, SND_PCM_HW_PARAM_RATE);
Packit 4a16fb
	srate = snd_pcm_hw_param_get_interval(sparams, SND_PCM_HW_PARAM_RATE);
Packit 4a16fb
	snd_interval_muldiv(sbuffer_size, crate, srate, &t);
Packit 4a16fb
	snd_interval_floor(&t);
Packit 4a16fb
	err = _snd_pcm_hw_param_set_interval(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &t);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	buffer_size = snd_pcm_hw_param_get_interval(params, SND_PCM_HW_PARAM_BUFFER_SIZE);
Packit 4a16fb
	/*
Packit 4a16fb
	 * this condition probably needs more work:
Packit 4a16fb
	 *   in case when the buffer_size is known and we are looking
Packit 4a16fb
	 *   for best period_size, we should prefer situation when
Packit 4a16fb
	 *   (buffer_size / period_size) * period_size == buffer_size
Packit 4a16fb
	 */
Packit 4a16fb
	if (snd_interval_single(buffer_size) && buffer_size->integer) {
Packit 4a16fb
		snd_interval_t *period_size;
Packit 4a16fb
		period_size = (snd_interval_t *)snd_pcm_hw_param_get_interval(params, SND_PCM_HW_PARAM_PERIOD_SIZE);
Packit 4a16fb
		if (!snd_interval_checkempty(period_size) &&
Packit 4a16fb
		    period_size->openmin && period_size->openmax &&
Packit 4a16fb
		    period_size->min + 1 == period_size->max) {
Packit 4a16fb
			if (period_size->min > 0 && (buffer_size->min / period_size->min) * period_size->min == buffer_size->min) {
Packit 4a16fb
		    		snd_interval_set_value(period_size, period_size->min);
Packit 4a16fb
		    	} else if ((buffer_size->max / period_size->max) * period_size->max == buffer_size->max) {
Packit 4a16fb
		    		snd_interval_set_value(period_size, period_size->max);
Packit 4a16fb
		    	}
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
#ifdef DEBUG_REFINE
Packit 4a16fb
	snd_output_stdio_attach(&out, stderr, 0);
Packit 4a16fb
	snd_output_printf(out, "REFINE (params):\n");
Packit 4a16fb
	snd_pcm_hw_params_dump(params, out);
Packit 4a16fb
	snd_output_printf(out, "REFINE (slave params):\n");
Packit 4a16fb
	snd_pcm_hw_params_dump(sparams, out);
Packit 4a16fb
	snd_output_close(out);
Packit 4a16fb
#endif
Packit 4a16fb
	err = _snd_pcm_hw_params_refine(params, links, sparams);
Packit 4a16fb
#ifdef DEBUG_REFINE
Packit 4a16fb
	snd_output_stdio_attach(&out, stderr, 0);
Packit 4a16fb
	snd_output_printf(out, "********************\n");
Packit 4a16fb
	snd_output_printf(out, "REFINE (params) (%i):\n", err);
Packit 4a16fb
	snd_pcm_hw_params_dump(params, out);
Packit 4a16fb
	snd_output_printf(out, "REFINE (slave params):\n");
Packit 4a16fb
	snd_pcm_hw_params_dump(sparams, out);
Packit 4a16fb
	snd_output_close(out);
Packit 4a16fb
#endif
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_hw_refine(snd_pcm_t *pcm, 
Packit 4a16fb
				  snd_pcm_hw_params_t *params)
Packit 4a16fb
{
Packit 4a16fb
	return snd_pcm_hw_refine_slave(pcm, params,
Packit 4a16fb
				       snd_pcm_rate_hw_refine_cprepare,
Packit 4a16fb
				       snd_pcm_rate_hw_refine_cchange,
Packit 4a16fb
				       snd_pcm_rate_hw_refine_sprepare,
Packit 4a16fb
				       snd_pcm_rate_hw_refine_schange,
Packit 4a16fb
				       snd_pcm_generic_hw_refine);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	snd_pcm_t *slave = rate->gen.slave;
Packit 4a16fb
	snd_pcm_rate_side_info_t *sinfo, *cinfo;
Packit 4a16fb
	unsigned int channels, cwidth, swidth, chn;
Packit 4a16fb
	int err = snd_pcm_hw_params_slave(pcm, params,
Packit 4a16fb
					  snd_pcm_rate_hw_refine_cchange,
Packit 4a16fb
					  snd_pcm_rate_hw_refine_sprepare,
Packit 4a16fb
					  snd_pcm_rate_hw_refine_schange,
Packit 4a16fb
					  snd_pcm_generic_hw_params);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
Packit 4a16fb
	if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
Packit 4a16fb
		cinfo = &rate->info.in;
Packit 4a16fb
		sinfo = &rate->info.out;
Packit 4a16fb
	} else {
Packit 4a16fb
		sinfo = &rate->info.in;
Packit 4a16fb
		cinfo = &rate->info.out;
Packit 4a16fb
	}
Packit 4a16fb
	err = INTERNAL(snd_pcm_hw_params_get_format)(params, &cinfo->format);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	err = INTERNAL(snd_pcm_hw_params_get_rate)(params, &cinfo->rate, 0);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	err = INTERNAL(snd_pcm_hw_params_get_period_size)(params, &cinfo->period_size, 0);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(params, &cinfo->buffer_size);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	err = INTERNAL(snd_pcm_hw_params_get_channels)(params, &channels);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
Packit 4a16fb
	rate->info.channels = channels;
Packit 4a16fb
	sinfo->format = slave->format;
Packit 4a16fb
	sinfo->rate = slave->rate;
Packit 4a16fb
	sinfo->buffer_size = slave->buffer_size;
Packit 4a16fb
	sinfo->period_size = slave->period_size;
Packit 4a16fb
Packit 4a16fb
	if (CHECK_SANITY(rate->pareas)) {
Packit 4a16fb
		SNDMSG("rate plugin already in use");
Packit 4a16fb
		return -EBUSY;
Packit 4a16fb
	}
Packit 4a16fb
	err = rate->ops.init(rate->obj, &rate->info);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
Packit 4a16fb
	rate->pareas = malloc(2 * channels * sizeof(*rate->pareas));
Packit 4a16fb
	if (rate->pareas == NULL)
Packit 4a16fb
		goto error;
Packit 4a16fb
Packit 4a16fb
	cwidth = snd_pcm_format_physical_width(cinfo->format);
Packit 4a16fb
	swidth = snd_pcm_format_physical_width(sinfo->format);
Packit 4a16fb
	rate->pareas[0].addr = malloc(((cwidth * channels * cinfo->period_size) / 8) +
Packit 4a16fb
				      ((swidth * channels * sinfo->period_size) / 8));
Packit 4a16fb
	if (rate->pareas[0].addr == NULL)
Packit 4a16fb
		goto error;
Packit 4a16fb
Packit 4a16fb
	rate->sareas = rate->pareas + channels;
Packit 4a16fb
	rate->sareas[0].addr = (char *)rate->pareas[0].addr + ((cwidth * channels * cinfo->period_size) / 8);
Packit 4a16fb
	for (chn = 0; chn < channels; chn++) {
Packit 4a16fb
		rate->pareas[chn].addr = (char *)rate->pareas[0].addr + (cwidth * chn * cinfo->period_size) / 8;
Packit 4a16fb
		rate->pareas[chn].first = 0;
Packit 4a16fb
		rate->pareas[chn].step = cwidth;
Packit 4a16fb
		rate->sareas[chn].addr = (char *)rate->sareas[0].addr + (swidth * chn * sinfo->period_size) / 8;
Packit 4a16fb
		rate->sareas[chn].first = 0;
Packit 4a16fb
		rate->sareas[chn].step = swidth;
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	if (rate->ops.convert_s16) {
Packit 4a16fb
		rate->get_idx = snd_pcm_linear_get_index(rate->info.in.format, SND_PCM_FORMAT_S16);
Packit 4a16fb
		rate->put_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_S16, rate->info.out.format);
Packit 4a16fb
		free(rate->src_buf);
Packit 4a16fb
		rate->src_buf = malloc(channels * rate->info.in.period_size * 2);
Packit 4a16fb
		free(rate->dst_buf);
Packit 4a16fb
		rate->dst_buf = malloc(channels * rate->info.out.period_size * 2);
Packit 4a16fb
		if (! rate->src_buf || ! rate->dst_buf)
Packit 4a16fb
			goto error;
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	return 0;
Packit 4a16fb
Packit 4a16fb
 error:
Packit 4a16fb
	if (rate->pareas) {
Packit 4a16fb
		free(rate->pareas[0].addr);
Packit 4a16fb
		free(rate->pareas);
Packit 4a16fb
		rate->pareas = NULL;
Packit 4a16fb
	}
Packit 4a16fb
	if (rate->ops.free)
Packit 4a16fb
		rate->ops.free(rate->obj);
Packit 4a16fb
	return -ENOMEM;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_hw_free(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	if (rate->pareas) {
Packit 4a16fb
		free(rate->pareas[0].addr);
Packit 4a16fb
		free(rate->pareas);
Packit 4a16fb
		rate->pareas = NULL;
Packit 4a16fb
		rate->sareas = NULL;
Packit 4a16fb
	}
Packit 4a16fb
	if (rate->ops.free)
Packit 4a16fb
		rate->ops.free(rate->obj);
Packit 4a16fb
	free(rate->src_buf);
Packit 4a16fb
	free(rate->dst_buf);
Packit 4a16fb
	rate->src_buf = rate->dst_buf = NULL;
Packit 4a16fb
	return snd_pcm_hw_free(rate->gen.slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static void recalc(snd_pcm_t *pcm, snd_pcm_uframes_t *val)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	snd_pcm_t *slave = rate->gen.slave;
Packit 4a16fb
	unsigned long div;
Packit 4a16fb
Packit 4a16fb
	if (*val == pcm->buffer_size) {
Packit 4a16fb
		*val = slave->buffer_size;
Packit 4a16fb
	} else {
Packit 4a16fb
		div = *val / pcm->period_size;
Packit 4a16fb
		if (div * pcm->period_size == *val)
Packit 4a16fb
			*val = div * slave->period_size;
Packit 4a16fb
		else
Packit 4a16fb
			*val = muldiv_near(*val, slave->period_size, pcm->period_size);
Packit 4a16fb
	}
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t * params)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	snd_pcm_t *slave = rate->gen.slave;
Packit 4a16fb
	snd_pcm_sw_params_t *sparams;
Packit 4a16fb
	snd_pcm_uframes_t boundary1, boundary2, sboundary;
Packit 4a16fb
	int err;
Packit 4a16fb
Packit 4a16fb
	sparams = &rate->sw_params;
Packit 4a16fb
	err = snd_pcm_sw_params_current(slave, sparams);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	sboundary = sparams->boundary;
Packit 4a16fb
	*sparams = *params;
Packit 4a16fb
	boundary1 = pcm->buffer_size;
Packit 4a16fb
	boundary2 = slave->buffer_size;
Packit 4a16fb
	while (boundary1 * 2 <= LONG_MAX - pcm->buffer_size &&
Packit 4a16fb
	       boundary2 * 2 <= LONG_MAX - slave->buffer_size) {
Packit 4a16fb
		boundary1 *= 2;
Packit 4a16fb
		boundary2 *= 2;
Packit 4a16fb
	}
Packit 4a16fb
	params->boundary = boundary1;
Packit 4a16fb
	sparams->boundary = sboundary;
Packit 4a16fb
Packit 4a16fb
	if (rate->ops.adjust_pitch)
Packit 4a16fb
		rate->ops.adjust_pitch(rate->obj, &rate->info);
Packit 4a16fb
Packit 4a16fb
	recalc(pcm, &sparams->avail_min);
Packit 4a16fb
	rate->orig_avail_min = sparams->avail_min;
Packit 4a16fb
	recalc(pcm, &sparams->start_threshold);
Packit 4a16fb
	if (sparams->avail_min < 1) sparams->avail_min = 1;
Packit 4a16fb
	if (sparams->start_threshold <= slave->buffer_size) {
Packit 4a16fb
		if (sparams->start_threshold > (slave->buffer_size / sparams->avail_min) * sparams->avail_min)
Packit 4a16fb
			sparams->start_threshold = (slave->buffer_size / sparams->avail_min) * sparams->avail_min;
Packit 4a16fb
	}
Packit 4a16fb
	if (sparams->stop_threshold >= params->boundary) {
Packit 4a16fb
		sparams->stop_threshold = sparams->boundary;
Packit 4a16fb
	} else {
Packit 4a16fb
		recalc(pcm, &sparams->stop_threshold);
Packit 4a16fb
	}
Packit 4a16fb
	recalc(pcm, &sparams->silence_threshold);
Packit 4a16fb
	if (sparams->silence_size >= params->boundary) {
Packit 4a16fb
		sparams->silence_size = sparams->boundary;
Packit 4a16fb
	} else {
Packit 4a16fb
		recalc(pcm, &sparams->silence_size);
Packit 4a16fb
	}
Packit 4a16fb
	return snd_pcm_sw_params(slave, sparams);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_init(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
Packit 4a16fb
	if (rate->ops.reset)
Packit 4a16fb
		rate->ops.reset(rate->obj);
Packit 4a16fb
	rate->last_commit_ptr = 0;
Packit 4a16fb
	rate->start_pending = 0;
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static void convert_to_s16(snd_pcm_rate_t *rate, int16_t *buf,
Packit 4a16fb
			   const snd_pcm_channel_area_t *areas,
Packit 4a16fb
			   snd_pcm_uframes_t offset, unsigned int frames,
Packit 4a16fb
			   unsigned int channels)
Packit 4a16fb
{
Packit 4a16fb
#ifndef DOC_HIDDEN
Packit 4a16fb
#define GET16_LABELS
Packit 4a16fb
#include "plugin_ops.h"
Packit 4a16fb
#undef GET16_LABELS
Packit 4a16fb
#endif /* DOC_HIDDEN */
Packit 4a16fb
	void *get = get16_labels[rate->get_idx];
Packit 4a16fb
	const char *src;
Packit 4a16fb
	int16_t sample;
Packit 4a16fb
	const char *srcs[channels];
Packit 4a16fb
	int src_step[channels];
Packit 4a16fb
	unsigned int c;
Packit 4a16fb
Packit 4a16fb
	for (c = 0; c < channels; c++) {
Packit 4a16fb
		srcs[c] = snd_pcm_channel_area_addr(areas + c, offset);
Packit 4a16fb
		src_step[c] = snd_pcm_channel_area_step(areas + c);
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	while (frames--) {
Packit 4a16fb
		for (c = 0; c < channels; c++) {
Packit 4a16fb
			src = srcs[c];
Packit 4a16fb
			goto *get;
Packit 4a16fb
#ifndef DOC_HIDDEN
Packit 4a16fb
#define GET16_END after_get
Packit 4a16fb
#include "plugin_ops.h"
Packit 4a16fb
#undef GET16_END
Packit 4a16fb
#endif /* DOC_HIDDEN */
Packit 4a16fb
		after_get:
Packit 4a16fb
			*buf++ = sample;
Packit 4a16fb
			srcs[c] += src_step[c];
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static void convert_from_s16(snd_pcm_rate_t *rate, const int16_t *buf,
Packit 4a16fb
			     const snd_pcm_channel_area_t *areas,
Packit 4a16fb
			     snd_pcm_uframes_t offset, unsigned int frames,
Packit 4a16fb
			     unsigned int channels)
Packit 4a16fb
{
Packit 4a16fb
#ifndef DOC_HIDDEN
Packit 4a16fb
#define PUT16_LABELS
Packit 4a16fb
#include "plugin_ops.h"
Packit 4a16fb
#undef PUT16_LABELS
Packit 4a16fb
#endif /* DOC_HIDDEN */
Packit 4a16fb
	void *put = put16_labels[rate->put_idx];
Packit 4a16fb
	char *dst;
Packit 4a16fb
	int16_t sample;
Packit 4a16fb
	char *dsts[channels];
Packit 4a16fb
	int dst_step[channels];
Packit 4a16fb
	unsigned int c;
Packit 4a16fb
Packit 4a16fb
	for (c = 0; c < channels; c++) {
Packit 4a16fb
		dsts[c] = snd_pcm_channel_area_addr(areas + c, offset);
Packit 4a16fb
		dst_step[c] = snd_pcm_channel_area_step(areas + c);
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	while (frames--) {
Packit 4a16fb
		for (c = 0; c < channels; c++) {
Packit 4a16fb
			dst = dsts[c];
Packit 4a16fb
			sample = *buf++;
Packit 4a16fb
			goto *put;
Packit 4a16fb
#ifndef DOC_HIDDEN
Packit 4a16fb
#define PUT16_END after_put
Packit 4a16fb
#include "plugin_ops.h"
Packit 4a16fb
#undef PUT16_END
Packit 4a16fb
#endif /* DOC_HIDDEN */
Packit 4a16fb
		after_put:
Packit 4a16fb
			dsts[c] += dst_step[c];
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static void do_convert(const snd_pcm_channel_area_t *dst_areas,
Packit 4a16fb
		       snd_pcm_uframes_t dst_offset, unsigned int dst_frames,
Packit 4a16fb
		       const snd_pcm_channel_area_t *src_areas,
Packit 4a16fb
		       snd_pcm_uframes_t src_offset, unsigned int src_frames,
Packit 4a16fb
		       unsigned int channels,
Packit 4a16fb
		       snd_pcm_rate_t *rate)
Packit 4a16fb
{
Packit 4a16fb
	if (rate->ops.convert_s16) {
Packit 4a16fb
		const int16_t *src;
Packit 4a16fb
		int16_t *dst;
Packit 4a16fb
		if (! rate->src_buf)
Packit 4a16fb
			src = (int16_t *)src_areas->addr + src_offset * channels;
Packit 4a16fb
		else {
Packit 4a16fb
			convert_to_s16(rate, rate->src_buf, src_areas, src_offset,
Packit 4a16fb
				       src_frames, channels);
Packit 4a16fb
			src = rate->src_buf;
Packit 4a16fb
		}
Packit 4a16fb
		if (! rate->dst_buf)
Packit 4a16fb
			dst = (int16_t *)dst_areas->addr + dst_offset * channels;
Packit 4a16fb
		else
Packit 4a16fb
			dst = rate->dst_buf;
Packit 4a16fb
		rate->ops.convert_s16(rate->obj, dst, dst_frames, src, src_frames);
Packit 4a16fb
		if (dst == rate->dst_buf)
Packit 4a16fb
			convert_from_s16(rate, rate->dst_buf, dst_areas, dst_offset,
Packit 4a16fb
					 dst_frames, channels);
Packit 4a16fb
	} else {
Packit 4a16fb
		rate->ops.convert(rate->obj, dst_areas, dst_offset, dst_frames,
Packit 4a16fb
				   src_areas, src_offset, src_frames);
Packit 4a16fb
	}
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static inline void
Packit 4a16fb
snd_pcm_rate_write_areas1(snd_pcm_t *pcm,
Packit 4a16fb
			 const snd_pcm_channel_area_t *areas,
Packit 4a16fb
			 snd_pcm_uframes_t offset,
Packit 4a16fb
			 const snd_pcm_channel_area_t *slave_areas,
Packit 4a16fb
			 snd_pcm_uframes_t slave_offset)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	do_convert(slave_areas, slave_offset, rate->gen.slave->period_size,
Packit 4a16fb
		   areas, offset, pcm->period_size,
Packit 4a16fb
		   pcm->channels, rate);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static inline void
Packit 4a16fb
snd_pcm_rate_read_areas1(snd_pcm_t *pcm,
Packit 4a16fb
			 const snd_pcm_channel_area_t *areas,
Packit 4a16fb
			 snd_pcm_uframes_t offset,
Packit 4a16fb
			 const snd_pcm_channel_area_t *slave_areas,
Packit 4a16fb
			 snd_pcm_uframes_t slave_offset)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	do_convert(areas, offset, pcm->period_size,
Packit 4a16fb
		   slave_areas, slave_offset, rate->gen.slave->period_size,
Packit 4a16fb
		   pcm->channels, rate);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static inline void snd_pcm_rate_sync_hwptr0(snd_pcm_t *pcm, snd_pcm_uframes_t slave_hw_ptr)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
Packit 4a16fb
	snd_pcm_sframes_t slave_hw_ptr_diff = slave_hw_ptr - rate->last_slave_hw_ptr;
Packit 4a16fb
	snd_pcm_sframes_t last_slave_hw_ptr_frac;
Packit 4a16fb
Packit 4a16fb
	if (pcm->stream != SND_PCM_STREAM_PLAYBACK)
Packit 4a16fb
		return;
Packit 4a16fb
Packit 4a16fb
	if (slave_hw_ptr_diff < 0)
Packit 4a16fb
		slave_hw_ptr_diff += rate->gen.slave->boundary; /* slave boundary wraparound */
Packit 4a16fb
	else if (slave_hw_ptr_diff == 0)
Packit 4a16fb
		return;
Packit 4a16fb
	last_slave_hw_ptr_frac = rate->last_slave_hw_ptr % rate->gen.slave->period_size;
Packit 4a16fb
	/* While handling fraction part fo slave period, rounded value will be
Packit 4a16fb
	 * introduced by input_frames().
Packit 4a16fb
	 * To eliminate rounding issue on rate->hw_ptr, subtract last rounded
Packit 4a16fb
	 * value from rate->hw_ptr and add new rounded value of present
Packit 4a16fb
	 * slave_hw_ptr fraction part to rate->hw_ptr. Hence,
Packit 4a16fb
	 * rate->hw_ptr += [ (no. of updated slave periods * pcm rate period size) -
Packit 4a16fb
	 * 	fractional part of last_slave_hw_ptr rounded value +
Packit 4a16fb
	 * 	fractional part of updated slave hw ptr's rounded value ]
Packit 4a16fb
	 */
Packit 4a16fb
	rate->hw_ptr += (
Packit 4a16fb
			(((last_slave_hw_ptr_frac + slave_hw_ptr_diff) / rate->gen.slave->period_size) * pcm->period_size) -
Packit 4a16fb
			rate->ops.input_frames(rate->obj, last_slave_hw_ptr_frac) +
Packit 4a16fb
			rate->ops.input_frames(rate->obj, (last_slave_hw_ptr_frac + slave_hw_ptr_diff) % rate->gen.slave->period_size));
Packit 4a16fb
	rate->last_slave_hw_ptr = slave_hw_ptr;
Packit 4a16fb
Packit 4a16fb
	rate->hw_ptr %= pcm->boundary;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static inline void snd_pcm_rate_sync_hwptr(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	snd_pcm_rate_sync_hwptr0(pcm, *rate->gen.slave->hw.ptr);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_hwsync(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	int err = snd_pcm_hwsync(rate->gen.slave);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	snd_pcm_rate_sync_hwptr(pcm);
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static snd_pcm_uframes_t snd_pcm_rate_playback_internal_delay(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
Packit 4a16fb
	if (rate->appl_ptr < rate->last_commit_ptr) {
Packit 4a16fb
		return rate->appl_ptr - rate->last_commit_ptr + pcm->boundary;
Packit 4a16fb
	} else {
Packit 4a16fb
		return rate->appl_ptr - rate->last_commit_ptr;
Packit 4a16fb
	}
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	snd_pcm_sframes_t slave_delay;
Packit 4a16fb
	int err;
Packit 4a16fb
Packit 4a16fb
	snd_pcm_rate_hwsync(pcm);
Packit 4a16fb
Packit 4a16fb
	err = snd_pcm_delay(rate->gen.slave, &slave_delay);
Packit 4a16fb
	if (err < 0) {
Packit 4a16fb
		return err;
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
Packit 4a16fb
		*delayp = rate->ops.input_frames(rate->obj, slave_delay)
Packit 4a16fb
				+ snd_pcm_rate_playback_internal_delay(pcm);
Packit 4a16fb
	} else {
Packit 4a16fb
		*delayp = rate->ops.output_frames(rate->obj, slave_delay)
Packit 4a16fb
				+ snd_pcm_mmap_capture_hw_avail(pcm);
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_prepare(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	int err;
Packit 4a16fb
Packit 4a16fb
	err = snd_pcm_prepare(rate->gen.slave);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	*pcm->hw.ptr = 0;
Packit 4a16fb
	*pcm->appl.ptr = 0;
Packit 4a16fb
	rate->last_slave_hw_ptr = 0;
Packit 4a16fb
	err = snd_pcm_rate_init(pcm);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_reset(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	int err;
Packit 4a16fb
	err = snd_pcm_reset(rate->gen.slave);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	*pcm->hw.ptr = 0;
Packit 4a16fb
	*pcm->appl.ptr = 0;
Packit 4a16fb
	rate->last_slave_hw_ptr = 0;
Packit 4a16fb
	err = snd_pcm_rate_init(pcm);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static snd_pcm_sframes_t snd_pcm_rate_rewindable(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
Packit 4a16fb
{
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static snd_pcm_sframes_t snd_pcm_rate_forwardable(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
Packit 4a16fb
{
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static snd_pcm_sframes_t snd_pcm_rate_rewind(snd_pcm_t *pcm ATTRIBUTE_UNUSED,
Packit 4a16fb
                                             snd_pcm_uframes_t frames ATTRIBUTE_UNUSED)
Packit 4a16fb
{
Packit 4a16fb
        return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static snd_pcm_sframes_t snd_pcm_rate_forward(snd_pcm_t *pcm ATTRIBUTE_UNUSED,
Packit 4a16fb
                                              snd_pcm_uframes_t frames ATTRIBUTE_UNUSED)
Packit 4a16fb
{
Packit 4a16fb
        return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_commit_area(snd_pcm_t *pcm, snd_pcm_rate_t *rate,
Packit 4a16fb
				    snd_pcm_uframes_t appl_offset,
Packit 4a16fb
				    snd_pcm_uframes_t size,
Packit 4a16fb
				    snd_pcm_uframes_t slave_size)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_uframes_t cont = pcm->buffer_size - appl_offset;
Packit 4a16fb
	const snd_pcm_channel_area_t *areas;
Packit 4a16fb
	const snd_pcm_channel_area_t *slave_areas;
Packit 4a16fb
	snd_pcm_uframes_t slave_offset, xfer;
Packit 4a16fb
	snd_pcm_uframes_t slave_frames = ULONG_MAX;
Packit 4a16fb
	snd_pcm_sframes_t result;
Packit 4a16fb
Packit 4a16fb
	areas = snd_pcm_mmap_areas(pcm);
Packit 4a16fb
	if (cont >= size) {
Packit 4a16fb
		result = snd_pcm_mmap_begin(rate->gen.slave, &slave_areas, &slave_offset, &slave_frames);
Packit 4a16fb
		if (result < 0)
Packit 4a16fb
			return result;
Packit 4a16fb
		if (slave_frames < slave_size) {
Packit 4a16fb
			snd_pcm_rate_write_areas1(pcm, areas, appl_offset, rate->sareas, 0);
Packit 4a16fb
			goto __partial;
Packit 4a16fb
		}
Packit 4a16fb
		snd_pcm_rate_write_areas1(pcm, areas, appl_offset,
Packit 4a16fb
					  slave_areas, slave_offset);
Packit 4a16fb
		result = snd_pcm_mmap_commit(rate->gen.slave, slave_offset, slave_size);
Packit 4a16fb
		if (result < (snd_pcm_sframes_t)slave_size) {
Packit 4a16fb
			if (result < 0)
Packit 4a16fb
				return result;
Packit 4a16fb
			result = snd_pcm_rewind(rate->gen.slave, result);
Packit 4a16fb
			if (result < 0)
Packit 4a16fb
				return result;
Packit 4a16fb
			return 0;
Packit 4a16fb
		}
Packit 4a16fb
	} else {
Packit 4a16fb
		snd_pcm_areas_copy(rate->pareas, 0,
Packit 4a16fb
				   areas, appl_offset,
Packit 4a16fb
				   pcm->channels, cont,
Packit 4a16fb
				   pcm->format);
Packit 4a16fb
		snd_pcm_areas_copy(rate->pareas, cont,
Packit 4a16fb
				   areas, 0,
Packit 4a16fb
				   pcm->channels, size - cont,
Packit 4a16fb
				   pcm->format);
Packit 4a16fb
Packit 4a16fb
		snd_pcm_rate_write_areas1(pcm, rate->pareas, 0, rate->sareas, 0);
Packit 4a16fb
Packit 4a16fb
		/* ok, commit first fragment */
Packit 4a16fb
		result = snd_pcm_mmap_begin(rate->gen.slave, &slave_areas, &slave_offset, &slave_frames);
Packit 4a16fb
		if (result < 0)
Packit 4a16fb
			return result;
Packit 4a16fb
	      __partial:
Packit 4a16fb
		xfer = 0;
Packit 4a16fb
		cont = slave_frames;
Packit 4a16fb
		if (cont > slave_size)
Packit 4a16fb
			cont = slave_size;
Packit 4a16fb
		snd_pcm_areas_copy(slave_areas, slave_offset,
Packit 4a16fb
				   rate->sareas, 0,
Packit 4a16fb
				   pcm->channels, cont,
Packit 4a16fb
				   rate->gen.slave->format);
Packit 4a16fb
		result = snd_pcm_mmap_commit(rate->gen.slave, slave_offset, cont);
Packit 4a16fb
		if (result < (snd_pcm_sframes_t)cont) {
Packit 4a16fb
			if (result < 0)
Packit 4a16fb
				return result;
Packit 4a16fb
			result = snd_pcm_rewind(rate->gen.slave, result);
Packit 4a16fb
			if (result < 0)
Packit 4a16fb
				return result;
Packit 4a16fb
			return 0;
Packit 4a16fb
		}
Packit 4a16fb
		xfer = cont;
Packit 4a16fb
Packit 4a16fb
		if (xfer == slave_size)
Packit 4a16fb
			goto commit_done;
Packit 4a16fb
		
Packit 4a16fb
		/* commit second fragment */
Packit 4a16fb
		cont = slave_size - cont;
Packit 4a16fb
		slave_frames = cont;
Packit 4a16fb
		result = snd_pcm_mmap_begin(rate->gen.slave, &slave_areas, &slave_offset, &slave_frames);
Packit 4a16fb
		if (result < 0)
Packit 4a16fb
			return result;
Packit 4a16fb
#if 0
Packit 4a16fb
		if (slave_offset) {
Packit 4a16fb
			SNDERR("non-zero slave_offset %ld", slave_offset);
Packit 4a16fb
			return -EIO;
Packit 4a16fb
		}
Packit 4a16fb
#endif
Packit 4a16fb
		snd_pcm_areas_copy(slave_areas, slave_offset,
Packit 4a16fb
				   rate->sareas, xfer,
Packit 4a16fb
				   pcm->channels, cont,
Packit 4a16fb
				   rate->gen.slave->format);
Packit 4a16fb
		result = snd_pcm_mmap_commit(rate->gen.slave, slave_offset, cont);
Packit 4a16fb
		if (result < (snd_pcm_sframes_t)cont) {
Packit 4a16fb
			if (result < 0)
Packit 4a16fb
				return result;
Packit 4a16fb
			result = snd_pcm_rewind(rate->gen.slave, result + xfer);
Packit 4a16fb
			if (result < 0)
Packit 4a16fb
				return result;
Packit 4a16fb
			return 0;
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
 commit_done:
Packit 4a16fb
	if (rate->start_pending) {
Packit 4a16fb
		/* we have pending start-trigger.  let's issue it now */
Packit 4a16fb
		snd_pcm_start(rate->gen.slave);
Packit 4a16fb
		rate->start_pending = 0;
Packit 4a16fb
	}
Packit 4a16fb
	return 1;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_commit_next_period(snd_pcm_t *pcm, snd_pcm_uframes_t appl_offset)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
Packit 4a16fb
	return snd_pcm_rate_commit_area(pcm, rate, appl_offset, pcm->period_size,
Packit 4a16fb
					rate->gen.slave->period_size);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_grab_next_period(snd_pcm_t *pcm, snd_pcm_uframes_t hw_offset)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	snd_pcm_uframes_t cont = pcm->buffer_size - hw_offset;
Packit 4a16fb
	const snd_pcm_channel_area_t *areas;
Packit 4a16fb
	const snd_pcm_channel_area_t *slave_areas;
Packit 4a16fb
	snd_pcm_uframes_t slave_offset, xfer;
Packit 4a16fb
	snd_pcm_uframes_t slave_frames = ULONG_MAX;
Packit 4a16fb
	snd_pcm_sframes_t result;
Packit 4a16fb
Packit 4a16fb
	areas = snd_pcm_mmap_areas(pcm);
Packit 4a16fb
	if (cont >= pcm->period_size) {
Packit 4a16fb
		result = snd_pcm_mmap_begin(rate->gen.slave, &slave_areas, &slave_offset, &slave_frames);
Packit 4a16fb
		if (result < 0)
Packit 4a16fb
			return result;
Packit 4a16fb
		if (slave_frames < rate->gen.slave->period_size)
Packit 4a16fb
			goto __partial;
Packit 4a16fb
		snd_pcm_rate_read_areas1(pcm, areas, hw_offset,
Packit 4a16fb
					 slave_areas, slave_offset);
Packit 4a16fb
		result = snd_pcm_mmap_commit(rate->gen.slave, slave_offset, rate->gen.slave->period_size);
Packit 4a16fb
		if (result < (snd_pcm_sframes_t)rate->gen.slave->period_size) {
Packit 4a16fb
			if (result < 0)
Packit 4a16fb
				return result;
Packit 4a16fb
			result = snd_pcm_rewind(rate->gen.slave, result);
Packit 4a16fb
			if (result < 0)
Packit 4a16fb
				return result;
Packit 4a16fb
			return 0;
Packit 4a16fb
		}
Packit 4a16fb
	} else {
Packit 4a16fb
		/* ok, grab first fragment */
Packit 4a16fb
		result = snd_pcm_mmap_begin(rate->gen.slave, &slave_areas, &slave_offset, &slave_frames);
Packit 4a16fb
		if (result < 0)
Packit 4a16fb
			return result;
Packit 4a16fb
	      __partial:
Packit 4a16fb
		xfer = 0;
Packit 4a16fb
		cont = slave_frames;
Packit 4a16fb
		if (cont > rate->gen.slave->period_size)
Packit 4a16fb
			cont = rate->gen.slave->period_size;
Packit 4a16fb
		snd_pcm_areas_copy(rate->sareas, 0,
Packit 4a16fb
				   slave_areas, slave_offset,
Packit 4a16fb
				   pcm->channels, cont,
Packit 4a16fb
				   rate->gen.slave->format);
Packit 4a16fb
		result = snd_pcm_mmap_commit(rate->gen.slave, slave_offset, cont);
Packit 4a16fb
		if (result < (snd_pcm_sframes_t)cont) {
Packit 4a16fb
			if (result < 0)
Packit 4a16fb
				return result;
Packit 4a16fb
			result = snd_pcm_rewind(rate->gen.slave, result);
Packit 4a16fb
			if (result < 0)
Packit 4a16fb
				return result;
Packit 4a16fb
			return 0;
Packit 4a16fb
		}
Packit 4a16fb
		xfer = cont;
Packit 4a16fb
Packit 4a16fb
		if (xfer == rate->gen.slave->period_size)
Packit 4a16fb
			goto __transfer;
Packit 4a16fb
Packit 4a16fb
		/* grab second fragment */
Packit 4a16fb
		cont = rate->gen.slave->period_size - cont;
Packit 4a16fb
		slave_frames = cont;
Packit 4a16fb
		result = snd_pcm_mmap_begin(rate->gen.slave, &slave_areas, &slave_offset, &slave_frames);
Packit 4a16fb
		if (result < 0)
Packit 4a16fb
			return result;
Packit 4a16fb
#if 0
Packit 4a16fb
		if (slave_offset) {
Packit 4a16fb
			SNDERR("non-zero slave_offset %ld", slave_offset);
Packit 4a16fb
			return -EIO;
Packit 4a16fb
		}
Packit 4a16fb
#endif
Packit 4a16fb
		snd_pcm_areas_copy(rate->sareas, xfer,
Packit 4a16fb
		                   slave_areas, slave_offset,
Packit 4a16fb
				   pcm->channels, cont,
Packit 4a16fb
				   rate->gen.slave->format);
Packit 4a16fb
		result = snd_pcm_mmap_commit(rate->gen.slave, slave_offset, cont);
Packit 4a16fb
		if (result < (snd_pcm_sframes_t)cont) {
Packit 4a16fb
			if (result < 0)
Packit 4a16fb
				return result;
Packit 4a16fb
			result = snd_pcm_rewind(rate->gen.slave, result + xfer);
Packit 4a16fb
			if (result < 0)
Packit 4a16fb
				return result;
Packit 4a16fb
			return 0;
Packit 4a16fb
		}
Packit 4a16fb
Packit 4a16fb
	      __transfer:
Packit 4a16fb
		cont = pcm->buffer_size - hw_offset;
Packit 4a16fb
		if (cont >= pcm->period_size) {
Packit 4a16fb
			snd_pcm_rate_read_areas1(pcm, areas, hw_offset,
Packit 4a16fb
						 rate->sareas, 0);
Packit 4a16fb
		} else {
Packit 4a16fb
			snd_pcm_rate_read_areas1(pcm,
Packit 4a16fb
						 rate->pareas, 0,
Packit 4a16fb
						 rate->sareas, 0);
Packit 4a16fb
			snd_pcm_areas_copy(areas, hw_offset,
Packit 4a16fb
					   rate->pareas, 0,
Packit 4a16fb
					   pcm->channels, cont,
Packit 4a16fb
					   pcm->format);
Packit 4a16fb
			snd_pcm_areas_copy(areas, 0,
Packit 4a16fb
					   rate->pareas, cont,
Packit 4a16fb
					   pcm->channels, pcm->period_size - cont,
Packit 4a16fb
					   pcm->format);
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
	return 1;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_sync_playback_area(snd_pcm_t *pcm, snd_pcm_uframes_t appl_ptr)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	snd_pcm_t *slave = rate->gen.slave;
Packit 4a16fb
	snd_pcm_uframes_t xfer;
Packit 4a16fb
	snd_pcm_sframes_t slave_size;
Packit 4a16fb
	int err;
Packit 4a16fb
Packit 4a16fb
	slave_size = snd_pcm_avail_update(slave);
Packit 4a16fb
	if (slave_size < 0)
Packit 4a16fb
		return slave_size;
Packit 4a16fb
Packit 4a16fb
	if (appl_ptr < rate->last_commit_ptr)
Packit 4a16fb
		xfer = appl_ptr - rate->last_commit_ptr + pcm->boundary;
Packit 4a16fb
	else
Packit 4a16fb
		xfer = appl_ptr - rate->last_commit_ptr;
Packit 4a16fb
	while (xfer >= pcm->period_size &&
Packit 4a16fb
	       (snd_pcm_uframes_t)slave_size >= rate->gen.slave->period_size) {
Packit 4a16fb
		err = snd_pcm_rate_commit_next_period(pcm, rate->last_commit_ptr % pcm->buffer_size);
Packit 4a16fb
		if (err == 0)
Packit 4a16fb
			break;
Packit 4a16fb
		if (err < 0)
Packit 4a16fb
			return err;
Packit 4a16fb
		xfer -= pcm->period_size;
Packit 4a16fb
		slave_size -= rate->gen.slave->period_size;
Packit 4a16fb
		rate->last_commit_ptr += pcm->period_size;
Packit 4a16fb
		if (rate->last_commit_ptr >= pcm->boundary)
Packit 4a16fb
			rate->last_commit_ptr = 0;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static snd_pcm_sframes_t snd_pcm_rate_mmap_commit(snd_pcm_t *pcm,
Packit 4a16fb
						  snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
Packit 4a16fb
						  snd_pcm_uframes_t size)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	int err;
Packit 4a16fb
Packit 4a16fb
	if (size == 0)
Packit 4a16fb
		return 0;
Packit 4a16fb
	if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
Packit 4a16fb
		err = snd_pcm_rate_sync_playback_area(pcm, rate->appl_ptr + size);
Packit 4a16fb
		if (err < 0)
Packit 4a16fb
			return err;
Packit 4a16fb
	}
Packit 4a16fb
	snd_pcm_mmap_appl_forward(pcm, size);
Packit 4a16fb
	return size;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static snd_pcm_sframes_t snd_pcm_rate_avail_update(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	snd_pcm_t *slave = rate->gen.slave;
Packit 4a16fb
	snd_pcm_sframes_t slave_size;
Packit 4a16fb
Packit 4a16fb
	slave_size = snd_pcm_avail_update(slave);
Packit 4a16fb
	if (slave_size < 0)
Packit 4a16fb
		return slave_size;
Packit 4a16fb
Packit 4a16fb
	if (pcm->stream == SND_PCM_STREAM_CAPTURE)
Packit 4a16fb
		goto _capture;
Packit 4a16fb
	snd_pcm_rate_sync_hwptr(pcm);
Packit 4a16fb
	snd_pcm_rate_sync_playback_area(pcm, rate->appl_ptr);
Packit 4a16fb
	return snd_pcm_mmap_avail(pcm);
Packit 4a16fb
 _capture: {
Packit 4a16fb
	snd_pcm_uframes_t xfer, hw_offset, size;
Packit 4a16fb
	
Packit 4a16fb
	xfer = snd_pcm_mmap_capture_avail(pcm);
Packit 4a16fb
	size = pcm->buffer_size - xfer;
Packit 4a16fb
	hw_offset = snd_pcm_mmap_hw_offset(pcm);
Packit 4a16fb
	while (size >= pcm->period_size &&
Packit 4a16fb
	       (snd_pcm_uframes_t)slave_size >= rate->gen.slave->period_size) {
Packit 4a16fb
		int err = snd_pcm_rate_grab_next_period(pcm, hw_offset);
Packit 4a16fb
		if (err < 0)
Packit 4a16fb
			return err;
Packit 4a16fb
		if (err == 0)
Packit 4a16fb
			return (snd_pcm_sframes_t)xfer;
Packit 4a16fb
		xfer += pcm->period_size;
Packit 4a16fb
		size -= pcm->period_size;
Packit 4a16fb
		slave_size -= rate->gen.slave->period_size;
Packit 4a16fb
		hw_offset += pcm->period_size;
Packit 4a16fb
		hw_offset %= pcm->buffer_size;
Packit 4a16fb
		snd_pcm_mmap_hw_forward(pcm, pcm->period_size);
Packit 4a16fb
	}
Packit 4a16fb
	return (snd_pcm_sframes_t)xfer;
Packit 4a16fb
 }
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_htimestamp(snd_pcm_t *pcm,
Packit 4a16fb
				   snd_pcm_uframes_t *avail,
Packit 4a16fb
				   snd_htimestamp_t *tstamp)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	snd_pcm_sframes_t avail1;
Packit 4a16fb
	snd_pcm_uframes_t tmp;
Packit 4a16fb
	int ok = 0, err;
Packit 4a16fb
Packit 4a16fb
	while (1) {
Packit 4a16fb
		/* the position is from this plugin itself */
Packit 4a16fb
		avail1 = snd_pcm_avail_update(pcm);
Packit 4a16fb
		if (avail1 < 0)
Packit 4a16fb
			return avail1;
Packit 4a16fb
		if (ok && (snd_pcm_uframes_t)avail1 == *avail)
Packit 4a16fb
			break;
Packit 4a16fb
		*avail = avail1;
Packit 4a16fb
		/* timestamp is taken from the slave PCM */
Packit 4a16fb
		err = snd_pcm_htimestamp(rate->gen.slave, &tmp, tstamp);
Packit 4a16fb
		if (err < 0)
Packit 4a16fb
			return err;
Packit 4a16fb
		ok = 1;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
Packit 4a16fb
		/* Try to sync as much as possible */
Packit 4a16fb
		snd_pcm_rate_hwsync(pcm);
Packit 4a16fb
		snd_pcm_rate_sync_playback_area(pcm, rate->appl_ptr);
Packit 4a16fb
	}
Packit 4a16fb
	return snd_pcm_poll_descriptors_revents(rate->gen.slave, pfds, nfds, revents);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/* locking */
Packit 4a16fb
static int snd_pcm_rate_drain(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
Packit 4a16fb
	if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
Packit 4a16fb
		/* commit the remaining fraction (if any) */
Packit 4a16fb
		snd_pcm_uframes_t size, ofs, saved_avail_min;
Packit 4a16fb
		snd_pcm_sw_params_t sw_params;
Packit 4a16fb
Packit 4a16fb
		__snd_pcm_lock(pcm);
Packit 4a16fb
		/* temporarily set avail_min to one */
Packit 4a16fb
		sw_params = rate->sw_params;
Packit 4a16fb
		saved_avail_min = sw_params.avail_min;
Packit 4a16fb
		sw_params.avail_min = 1;
Packit 4a16fb
		snd_pcm_sw_params(rate->gen.slave, &sw_params);
Packit 4a16fb
Packit 4a16fb
		size = rate->appl_ptr - rate->last_commit_ptr;
Packit 4a16fb
		ofs = rate->last_commit_ptr % pcm->buffer_size;
Packit 4a16fb
		while (size > 0) {
Packit 4a16fb
			snd_pcm_uframes_t psize, spsize;
Packit 4a16fb
			int err;
Packit 4a16fb
Packit 4a16fb
			err = __snd_pcm_wait_in_lock(rate->gen.slave, -1);
Packit 4a16fb
			if (err < 0)
Packit 4a16fb
				break;
Packit 4a16fb
			if (size > pcm->period_size) {
Packit 4a16fb
				psize = pcm->period_size;
Packit 4a16fb
				spsize = rate->gen.slave->period_size;
Packit 4a16fb
			} else {
Packit 4a16fb
				psize = size;
Packit 4a16fb
				spsize = rate->ops.output_frames(rate->obj, size);
Packit 4a16fb
				if (! spsize)
Packit 4a16fb
					break;
Packit 4a16fb
			}
Packit 4a16fb
			snd_pcm_rate_commit_area(pcm, rate, ofs,
Packit 4a16fb
						 psize, spsize);
Packit 4a16fb
			ofs = (ofs + psize) % pcm->buffer_size;
Packit 4a16fb
			size -= psize;
Packit 4a16fb
		}
Packit 4a16fb
		sw_params.avail_min = saved_avail_min;
Packit 4a16fb
		snd_pcm_sw_params(rate->gen.slave, &sw_params);
Packit 4a16fb
		__snd_pcm_unlock(pcm);
Packit 4a16fb
	}
Packit 4a16fb
	return snd_pcm_drain(rate->gen.slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static snd_pcm_state_t snd_pcm_rate_state(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	if (rate->start_pending) /* pseudo-state */
Packit 4a16fb
		return SND_PCM_STATE_RUNNING;
Packit 4a16fb
	return snd_pcm_state(rate->gen.slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_start(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	snd_pcm_sframes_t avail;
Packit 4a16fb
		
Packit 4a16fb
	if (pcm->stream == SND_PCM_STREAM_CAPTURE)
Packit 4a16fb
		return snd_pcm_start(rate->gen.slave);
Packit 4a16fb
Packit 4a16fb
	if (snd_pcm_state(rate->gen.slave) != SND_PCM_STATE_PREPARED)
Packit 4a16fb
		return -EBADFD;
Packit 4a16fb
Packit 4a16fb
	gettimestamp(&rate->trigger_tstamp, pcm->tstamp_type);
Packit 4a16fb
Packit 4a16fb
	avail = snd_pcm_mmap_playback_hw_avail(rate->gen.slave);
Packit 4a16fb
	if (avail < 0) /* can't happen on healthy drivers */
Packit 4a16fb
		return -EBADFD;
Packit 4a16fb
Packit 4a16fb
	if (avail == 0) {
Packit 4a16fb
		/* postpone the trigger since we have no data committed yet */
Packit 4a16fb
		rate->start_pending = 1;
Packit 4a16fb
		return 0;
Packit 4a16fb
	}
Packit 4a16fb
	rate->start_pending = 0;
Packit 4a16fb
	return snd_pcm_start(rate->gen.slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	snd_pcm_sframes_t err;
Packit 4a16fb
Packit 4a16fb
	err = snd_pcm_status(rate->gen.slave, status);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
Packit 4a16fb
		if (rate->start_pending)
Packit 4a16fb
			status->state = SND_PCM_STATE_RUNNING;
Packit 4a16fb
		status->trigger_tstamp = rate->trigger_tstamp;
Packit 4a16fb
	}
Packit 4a16fb
	snd_pcm_rate_sync_hwptr0(pcm, status->hw_ptr);
Packit 4a16fb
	status->appl_ptr = *pcm->appl.ptr;
Packit 4a16fb
	status->hw_ptr = *pcm->hw.ptr;
Packit 4a16fb
	if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
Packit 4a16fb
		status->delay = rate->ops.input_frames(rate->obj, status->delay)
Packit 4a16fb
					+ snd_pcm_rate_playback_internal_delay(pcm);
Packit 4a16fb
		status->avail = snd_pcm_mmap_playback_avail(pcm);
Packit 4a16fb
		status->avail_max = rate->ops.input_frames(rate->obj, status->avail_max);
Packit 4a16fb
	} else {
Packit 4a16fb
		/* FIXME: Maybe possible to somthing similar to
Packit 4a16fb
		 * snd_pcm_rate_playback_internal_delay()
Packit 4a16fb
		 * for the capture case.
Packit 4a16fb
		 */
Packit 4a16fb
		status->delay = rate->ops.output_frames(rate->obj, status->delay)
Packit 4a16fb
					+ snd_pcm_mmap_capture_hw_avail(pcm);
Packit 4a16fb
		status->avail = snd_pcm_mmap_capture_avail(pcm);
Packit 4a16fb
		status->avail_max = rate->ops.output_frames(rate->obj, status->avail_max);
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static void snd_pcm_rate_dump(snd_pcm_t *pcm, snd_output_t *out)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
	if (rate->sformat == SND_PCM_FORMAT_UNKNOWN)
Packit 4a16fb
		snd_output_printf(out, "Rate conversion PCM (%d)\n", 
Packit 4a16fb
			rate->srate);
Packit 4a16fb
	else
Packit 4a16fb
		snd_output_printf(out, "Rate conversion PCM (%d, sformat=%s)\n", 
Packit 4a16fb
			rate->srate,
Packit 4a16fb
			snd_pcm_format_name(rate->sformat));
Packit 4a16fb
	if (rate->ops.dump)
Packit 4a16fb
		rate->ops.dump(rate->obj, out);
Packit 4a16fb
	snd_output_printf(out, "Protocol version: %x\n", rate->plugin_version);
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(rate->gen.slave, out);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_rate_close(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_rate_t *rate = pcm->private_data;
Packit 4a16fb
Packit 4a16fb
	if (rate->ops.close)
Packit 4a16fb
		rate->ops.close(rate->obj);
Packit 4a16fb
	if (rate->open_func)
Packit 4a16fb
		snd_dlobj_cache_put(rate->open_func);
Packit 4a16fb
	return snd_pcm_generic_close(pcm);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static const snd_pcm_fast_ops_t snd_pcm_rate_fast_ops = {
Packit 4a16fb
	.status = snd_pcm_rate_status,
Packit 4a16fb
	.state = snd_pcm_rate_state,
Packit 4a16fb
	.hwsync = snd_pcm_rate_hwsync,
Packit 4a16fb
	.delay = snd_pcm_rate_delay,
Packit 4a16fb
	.prepare = snd_pcm_rate_prepare,
Packit 4a16fb
	.reset = snd_pcm_rate_reset,
Packit 4a16fb
	.start = snd_pcm_rate_start,
Packit 4a16fb
	.drop = snd_pcm_generic_drop,
Packit 4a16fb
	.drain = snd_pcm_rate_drain,
Packit 4a16fb
	.pause = snd_pcm_generic_pause,
Packit 4a16fb
	.rewindable = snd_pcm_rate_rewindable,
Packit 4a16fb
	.rewind = snd_pcm_rate_rewind,
Packit 4a16fb
	.forwardable = snd_pcm_rate_forwardable,
Packit 4a16fb
	.forward = snd_pcm_rate_forward,
Packit 4a16fb
	.resume = snd_pcm_generic_resume,
Packit 4a16fb
	.writei = snd_pcm_mmap_writei,
Packit 4a16fb
	.writen = snd_pcm_mmap_writen,
Packit 4a16fb
	.readi = snd_pcm_mmap_readi,
Packit 4a16fb
	.readn = snd_pcm_mmap_readn,
Packit 4a16fb
	.avail_update = snd_pcm_rate_avail_update,
Packit 4a16fb
	.mmap_commit = snd_pcm_rate_mmap_commit,
Packit 4a16fb
	.htimestamp = snd_pcm_rate_htimestamp,
Packit 4a16fb
	.poll_descriptors_count = snd_pcm_generic_poll_descriptors_count,
Packit 4a16fb
	.poll_descriptors = snd_pcm_generic_poll_descriptors,
Packit 4a16fb
	.poll_revents = snd_pcm_rate_poll_revents,
Packit 4a16fb
	.may_wait_for_avail_min = snd_pcm_plugin_may_wait_for_avail_min,
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
static const snd_pcm_ops_t snd_pcm_rate_ops = {
Packit 4a16fb
	.close = snd_pcm_rate_close,
Packit 4a16fb
	.info = snd_pcm_generic_info,
Packit 4a16fb
	.hw_refine = snd_pcm_rate_hw_refine,
Packit 4a16fb
	.hw_params = snd_pcm_rate_hw_params,
Packit 4a16fb
	.hw_free = snd_pcm_rate_hw_free,
Packit 4a16fb
	.sw_params = snd_pcm_rate_sw_params,
Packit 4a16fb
	.channel_info = snd_pcm_generic_channel_info,
Packit 4a16fb
	.dump = snd_pcm_rate_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
 * \brief Get a default converter string
Packit 4a16fb
 * \param root Root configuration node
Packit 4a16fb
 * \retval A const config item if found, or NULL
Packit 4a16fb
 */
Packit 4a16fb
const snd_config_t *snd_pcm_rate_get_default_converter(snd_config_t *root)
Packit 4a16fb
{
Packit 4a16fb
	snd_config_t *n;
Packit 4a16fb
	/* look for default definition */
Packit 4a16fb
	if (snd_config_search(root, "defaults.pcm.rate_converter", &n) >= 0)
Packit 4a16fb
		return n;
Packit 4a16fb
	return NULL;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
#ifdef PIC
Packit 4a16fb
static int is_builtin_plugin(const char *type)
Packit 4a16fb
{
Packit 4a16fb
	return strcmp(type, "linear") == 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static const char *const default_rate_plugins[] = {
Packit 4a16fb
	"speexrate", "linear", NULL
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
static int rate_open_func(snd_pcm_rate_t *rate, const char *type, const snd_config_t *converter_conf, int verbose)
Packit 4a16fb
{
Packit 4a16fb
	char open_name[64], open_conf_name[64], lib_name[128], *lib = NULL;
Packit 4a16fb
	snd_pcm_rate_open_func_t open_func;
Packit 4a16fb
	snd_pcm_rate_open_conf_func_t open_conf_func;
Packit 4a16fb
	int err;
Packit 4a16fb
Packit 4a16fb
	snprintf(open_name, sizeof(open_name), "_snd_pcm_rate_%s_open", type);
Packit 4a16fb
	snprintf(open_conf_name, sizeof(open_conf_name), "_snd_pcm_rate_%s_open_conf", type);
Packit 4a16fb
	if (!is_builtin_plugin(type)) {
Packit 4a16fb
		snprintf(lib_name, sizeof(lib_name),
Packit 4a16fb
				 "%s/libasound_module_rate_%s.so", ALSA_PLUGIN_DIR, type);
Packit 4a16fb
		lib = lib_name;
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	rate->rate_min = SND_PCM_PLUGIN_RATE_MIN;
Packit 4a16fb
	rate->rate_max = SND_PCM_PLUGIN_RATE_MAX;
Packit 4a16fb
	rate->plugin_version = SND_PCM_RATE_PLUGIN_VERSION;
Packit 4a16fb
Packit 4a16fb
	open_conf_func = snd_dlobj_cache_get(lib, open_conf_name, NULL, verbose && converter_conf != NULL);
Packit 4a16fb
	if (open_conf_func) {
Packit 4a16fb
		err = open_conf_func(SND_PCM_RATE_PLUGIN_VERSION,
Packit 4a16fb
				     &rate->obj, &rate->ops, converter_conf);
Packit 4a16fb
		if (!err) {
Packit 4a16fb
			rate->plugin_version = rate->ops.version;
Packit 4a16fb
			if (rate->ops.get_supported_rates)
Packit 4a16fb
				rate->ops.get_supported_rates(rate->obj,
Packit 4a16fb
							      &rate->rate_min,
Packit 4a16fb
							      &rate->rate_max);
Packit 4a16fb
			rate->open_func = open_conf_func;
Packit 4a16fb
			return 0;
Packit 4a16fb
		} else {
Packit 4a16fb
			snd_dlobj_cache_put(open_conf_func);
Packit 4a16fb
			return err;
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	open_func = snd_dlobj_cache_get(lib, open_name, NULL, verbose);
Packit 4a16fb
	if (!open_func)
Packit 4a16fb
		return -ENOENT;
Packit 4a16fb
Packit 4a16fb
	rate->open_func = open_func;
Packit 4a16fb
Packit 4a16fb
	err = open_func(SND_PCM_RATE_PLUGIN_VERSION, &rate->obj, &rate->ops);
Packit 4a16fb
	if (!err) {
Packit 4a16fb
		rate->plugin_version = rate->ops.version;
Packit 4a16fb
		if (rate->ops.get_supported_rates)
Packit 4a16fb
			rate->ops.get_supported_rates(rate->obj,
Packit 4a16fb
						      &rate->rate_min,
Packit 4a16fb
						      &rate->rate_max);
Packit 4a16fb
		return 0;
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	/* try to open with the old protocol version */
Packit 4a16fb
	rate->plugin_version = SND_PCM_RATE_PLUGIN_VERSION_OLD;
Packit 4a16fb
	err = open_func(SND_PCM_RATE_PLUGIN_VERSION_OLD,
Packit 4a16fb
			&rate->obj, &rate->ops);
Packit 4a16fb
	if (err) {
Packit 4a16fb
		snd_dlobj_cache_put(open_func);
Packit 4a16fb
		rate->open_func = NULL;
Packit 4a16fb
	}
Packit 4a16fb
	return err;
Packit 4a16fb
}
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
/*
Packit 4a16fb
 * If the conf is an array of alternatives then the id of
Packit 4a16fb
 * the first element will be "0" (or maybe NULL). Otherwise assume it is
Packit 4a16fb
 * a structure.
Packit 4a16fb
 */
Packit 4a16fb
static int is_string_array(const snd_config_t *conf)
Packit 4a16fb
{
Packit 4a16fb
	snd_config_iterator_t i;
Packit 4a16fb
Packit 4a16fb
	if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND)
Packit 4a16fb
		return 0;
Packit 4a16fb
Packit 4a16fb
	i = snd_config_iterator_first(conf);
Packit 4a16fb
	if (i && i != snd_config_iterator_end(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
			return 0;
Packit 4a16fb
		if (id && strcmp(id, "0") != 0)
Packit 4a16fb
			return 0;
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	return 1;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief Creates a new rate PCM
Packit 4a16fb
 * \param pcmp Returns created PCM handle
Packit 4a16fb
 * \param name Name of PCM
Packit 4a16fb
 * \param sformat Slave format
Packit 4a16fb
 * \param srate Slave rate
Packit 4a16fb
 * \param converter SRC type string node
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_rate_open(snd_pcm_t **pcmp, const char *name,
Packit 4a16fb
		      snd_pcm_format_t sformat, unsigned int srate,
Packit 4a16fb
		      const snd_config_t *converter,
Packit 4a16fb
		      snd_pcm_t *slave, int close_slave)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_t *pcm;
Packit 4a16fb
	snd_pcm_rate_t *rate;
Packit 4a16fb
	const char *type = NULL;
Packit 4a16fb
	int err;
Packit 4a16fb
#ifndef PIC
Packit 4a16fb
	snd_pcm_rate_open_func_t open_func;
Packit 4a16fb
	extern int SND_PCM_RATE_PLUGIN_ENTRY(linear) (unsigned int version, void **objp, snd_pcm_rate_ops_t *ops);
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
	assert(pcmp && slave);
Packit 4a16fb
	if (sformat != SND_PCM_FORMAT_UNKNOWN &&
Packit 4a16fb
	    snd_pcm_format_linear(sformat) != 1)
Packit 4a16fb
		return -EINVAL;
Packit 4a16fb
	rate = calloc(1, sizeof(snd_pcm_rate_t));
Packit 4a16fb
	if (!rate) {
Packit 4a16fb
		return -ENOMEM;
Packit 4a16fb
	}
Packit 4a16fb
	rate->gen.slave = slave;
Packit 4a16fb
	rate->gen.close_slave = close_slave;
Packit 4a16fb
	rate->srate = srate;
Packit 4a16fb
	rate->sformat = sformat;
Packit 4a16fb
Packit 4a16fb
	err = snd_pcm_new(&pcm, SND_PCM_TYPE_RATE, name, slave->stream, slave->mode);
Packit 4a16fb
	if (err < 0) {
Packit 4a16fb
		free(rate);
Packit 4a16fb
		return err;
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
#ifdef PIC
Packit 4a16fb
	err = -ENOENT;
Packit 4a16fb
	if (!converter) {
Packit 4a16fb
		const char *const *types;
Packit 4a16fb
		for (types = default_rate_plugins; *types; types++) {
Packit 4a16fb
			err = rate_open_func(rate, *types, NULL, 0);
Packit 4a16fb
			if (!err) {
Packit 4a16fb
				type = *types;
Packit 4a16fb
				break;
Packit 4a16fb
			}
Packit 4a16fb
		}
Packit 4a16fb
	} else if (!snd_config_get_string(converter, &type))
Packit 4a16fb
		err = rate_open_func(rate, type, NULL, 1);
Packit 4a16fb
	else if (is_string_array(converter)) {
Packit 4a16fb
		snd_config_iterator_t i, next;
Packit 4a16fb
		snd_config_for_each(i, next, converter) {
Packit 4a16fb
			snd_config_t *n = snd_config_iterator_entry(i);
Packit 4a16fb
			if (snd_config_get_string(n, &type) < 0)
Packit 4a16fb
				break;
Packit 4a16fb
			err = rate_open_func(rate, type, NULL, 0);
Packit 4a16fb
			if (!err)
Packit 4a16fb
				break;
Packit 4a16fb
		}
Packit 4a16fb
	} else if (snd_config_get_type(converter) == SND_CONFIG_TYPE_COMPOUND) {
Packit 4a16fb
		snd_config_iterator_t i, next;
Packit 4a16fb
		snd_config_for_each(i, next, converter) {
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 (strcmp(id, "name") != 0)
Packit 4a16fb
				continue;
Packit 4a16fb
			snd_config_get_string(n, &type);
Packit 4a16fb
			break;
Packit 4a16fb
		}
Packit 4a16fb
		if (!type) {
Packit 4a16fb
			SNDERR("No name given for rate converter");
Packit 4a16fb
			snd_pcm_free(pcm);
Packit 4a16fb
			free(rate);
Packit 4a16fb
			return -EINVAL;
Packit 4a16fb
		}
Packit 4a16fb
		err = rate_open_func(rate, type, converter, 1);
Packit 4a16fb
	} else {
Packit 4a16fb
		SNDERR("Invalid type for rate converter");
Packit 4a16fb
		snd_pcm_free(pcm);
Packit 4a16fb
		free(rate);
Packit 4a16fb
		return -EINVAL;
Packit 4a16fb
	}
Packit 4a16fb
	if (err < 0) {
Packit 4a16fb
		SNDERR("Cannot find rate converter");
Packit 4a16fb
		snd_pcm_free(pcm);
Packit 4a16fb
		free(rate);
Packit 4a16fb
		return -ENOENT;
Packit 4a16fb
	}
Packit 4a16fb
#else
Packit 4a16fb
	type = "linear";
Packit 4a16fb
	open_func = SND_PCM_RATE_PLUGIN_ENTRY(linear);
Packit 4a16fb
	err = open_func(SND_PCM_RATE_PLUGIN_VERSION, &rate->obj, &rate->ops);
Packit 4a16fb
	if (err < 0) {
Packit 4a16fb
		snd_pcm_free(pcm);
Packit 4a16fb
		free(rate);
Packit 4a16fb
		return err;
Packit 4a16fb
	}
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
	if (! rate->ops.init || ! (rate->ops.convert || rate->ops.convert_s16) ||
Packit 4a16fb
	    ! rate->ops.input_frames || ! rate->ops.output_frames) {
Packit 4a16fb
		SNDERR("Inproper rate plugin %s initialization", type);
Packit 4a16fb
		snd_pcm_free(pcm);
Packit 4a16fb
		free(rate);
Packit 4a16fb
		return err;
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	pcm->ops = &snd_pcm_rate_ops;
Packit 4a16fb
	pcm->fast_ops = &snd_pcm_rate_fast_ops;
Packit 4a16fb
	pcm->private_data = rate;
Packit 4a16fb
	pcm->poll_fd = slave->poll_fd;
Packit 4a16fb
	pcm->poll_events = slave->poll_events;
Packit 4a16fb
	pcm->mmap_rw = 1;
Packit 4a16fb
	pcm->tstamp_type = slave->tstamp_type;
Packit 4a16fb
	snd_pcm_set_hw_ptr(pcm, &rate->hw_ptr, -1, 0);
Packit 4a16fb
	snd_pcm_set_appl_ptr(pcm, &rate->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_rate Plugin: Rate
Packit 4a16fb
Packit 4a16fb
This plugin converts a stream rate. The input and output formats must be linear.
Packit 4a16fb
Packit 4a16fb
\code
Packit 4a16fb
pcm.name {
Packit 4a16fb
	type rate               # Rate 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
                rate INT        # Slave rate
Packit 4a16fb
                [format STR]    # Slave format
Packit 4a16fb
        }
Packit 4a16fb
	converter STR			# optional
Packit 4a16fb
	# or
Packit 4a16fb
	converter [ STR1 STR2 ... ]	# optional
Packit 4a16fb
				# Converter type, default is taken from
Packit 4a16fb
				# defaults.pcm.rate_converter
Packit 4a16fb
	# or
Packit 4a16fb
	converter {		# optional
Packit 4a16fb
		name STR	# Convertor type
Packit 4a16fb
		xxx yyy		# optional convertor-specific configuration
Packit 4a16fb
	}
Packit 4a16fb
}
Packit 4a16fb
\endcode
Packit 4a16fb
Packit 4a16fb
\subsection pcm_plugins_rate_funcref Function reference
Packit 4a16fb
Packit 4a16fb
    Packit 4a16fb
      
  • snd_pcm_rate_open()
  • Packit 4a16fb
      
  • _snd_pcm_rate_open()
  • Packit 4a16fb
    Packit 4a16fb
    Packit 4a16fb
    */
    Packit 4a16fb
    Packit 4a16fb
    /**
    Packit 4a16fb
     * \brief Creates a new rate 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 rate 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_rate_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 = SND_PCM_FORMAT_UNKNOWN;
    Packit 4a16fb
    	int srate = -1;
    Packit 4a16fb
    	const snd_config_t *converter = NULL;
    Packit 4a16fb
    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
    		if (strcmp(id, "converter") == 0) {
    Packit 4a16fb
    			converter = 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
    Packit 4a16fb
    	err = snd_pcm_slave_conf(root, slave, &sconf, 2,
    Packit 4a16fb
    				 SND_PCM_HW_PARAM_FORMAT, 0, &sformat,
    Packit 4a16fb
    				 SND_PCM_HW_PARAM_RATE, SCONF_MANDATORY, &srate);
    Packit 4a16fb
    	if (err < 0)
    Packit 4a16fb
    		return err;
    Packit 4a16fb
    	if (sformat != SND_PCM_FORMAT_UNKNOWN &&
    Packit 4a16fb
    	    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_rate_open(pcmp, name, sformat, (unsigned int) srate,
    Packit 4a16fb
    				converter, 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_rate_open, SND_PCM_DLSYM_VERSION);
    Packit 4a16fb
    #endif