Blame src/pcm/pcm_lfloat.c

Packit 4a16fb
/**
Packit 4a16fb
 * \file pcm/pcm_lfloat.c
Packit 4a16fb
 * \ingroup PCM_Plugins
Packit 4a16fb
 * \brief PCM Linear<->Float Conversion Plugin Interface
Packit 4a16fb
 * \author Jaroslav Kysela <perex@perex.cz>
Packit 4a16fb
 * \date 2001
Packit 4a16fb
 */
Packit 4a16fb
/*
Packit 4a16fb
 *  PCM - Linear Integer <-> Linear Float conversion
Packit 4a16fb
 *  Copyright (c) 2001 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
  
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 DOC_HIDDEN
Packit 4a16fb
Packit 4a16fb
typedef float float_t;
Packit 4a16fb
typedef double double_t;
Packit 4a16fb
Packit 4a16fb
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ <= 91)
Packit 4a16fb
#define BUGGY_GCC
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
#ifndef PIC
Packit 4a16fb
/* entry for static linking */
Packit 4a16fb
const char *_snd_module_pcm_lfloat = "";
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
typedef struct {
Packit 4a16fb
	/* This field need to be the first */
Packit 4a16fb
	snd_pcm_plugin_t plug;
Packit 4a16fb
	unsigned int int32_idx;
Packit 4a16fb
	unsigned int float32_idx;
Packit 4a16fb
	snd_pcm_format_t sformat;
Packit 4a16fb
	void (*func)(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 get32idx, unsigned int put32floatidx);
Packit 4a16fb
} snd_pcm_lfloat_t;
Packit 4a16fb
Packit 4a16fb
int snd_pcm_lfloat_get_s32_index(snd_pcm_format_t format)
Packit 4a16fb
{
Packit 4a16fb
	int width, endian;
Packit 4a16fb
Packit 4a16fb
	switch (format) {
Packit 4a16fb
	case SND_PCM_FORMAT_FLOAT_LE:
Packit 4a16fb
	case SND_PCM_FORMAT_FLOAT_BE:
Packit 4a16fb
		width = 32;
Packit 4a16fb
		break;
Packit 4a16fb
	case SND_PCM_FORMAT_FLOAT64_LE:
Packit 4a16fb
	case SND_PCM_FORMAT_FLOAT64_BE:
Packit 4a16fb
		width = 64;
Packit 4a16fb
		break;
Packit 4a16fb
	default:
Packit 4a16fb
		return -EINVAL;
Packit 4a16fb
	}
Packit 4a16fb
#ifdef SND_LITTLE_ENDIAN
Packit 4a16fb
	endian = snd_pcm_format_big_endian(format);
Packit 4a16fb
#else
Packit 4a16fb
	endian = snd_pcm_format_little_endian(format);
Packit 4a16fb
#endif
Packit 4a16fb
	return ((width / 32)-1) * 2 + endian;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_lfloat_put_s32_index(snd_pcm_format_t format)
Packit 4a16fb
{
Packit 4a16fb
	return snd_pcm_lfloat_get_s32_index(format);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
#endif /* DOC_HIDDEN */
Packit 4a16fb
Packit 4a16fb
#ifndef BUGGY_GCC
Packit 4a16fb
Packit 4a16fb
#ifndef DOC_HIDDEN
Packit 4a16fb
Packit 4a16fb
void snd_pcm_lfloat_convert_integer_float(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 get32idx, unsigned int put32floatidx)
Packit 4a16fb
{
Packit 4a16fb
#define GET32_LABELS
Packit 4a16fb
#define PUT32F_LABELS
Packit 4a16fb
#include "plugin_ops.h"
Packit 4a16fb
#undef PUT32F_LABELS
Packit 4a16fb
#undef GET32_LABELS
Packit 4a16fb
	void *get32 = get32_labels[get32idx];
Packit 4a16fb
	void *put32float = put32float_labels[put32floatidx];
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
		int32_t sample = 0;
Packit 4a16fb
		snd_tmp_float_t tmp_float;
Packit 4a16fb
		snd_tmp_double_t tmp_double;
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 *get32;
Packit 4a16fb
#define GET32_END sample_loaded
Packit 4a16fb
#include "plugin_ops.h"
Packit 4a16fb
#undef GET32_END
Packit 4a16fb
		sample_loaded:
Packit 4a16fb
			goto *put32float;
Packit 4a16fb
#define PUT32F_END sample_put
Packit 4a16fb
#include "plugin_ops.h"
Packit 4a16fb
#undef PUT32F_END
Packit 4a16fb
		sample_put:
Packit 4a16fb
			src += src_step;
Packit 4a16fb
			dst += dst_step;
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
void snd_pcm_lfloat_convert_float_integer(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 put32idx, unsigned int get32floatidx)
Packit 4a16fb
{
Packit 4a16fb
#define PUT32_LABELS
Packit 4a16fb
#define GET32F_LABELS
Packit 4a16fb
#include "plugin_ops.h"
Packit 4a16fb
#undef GET32F_LABELS
Packit 4a16fb
#undef PUT32_LABELS
Packit 4a16fb
	void *put32 = put32_labels[put32idx];
Packit 4a16fb
	void *get32float = get32float_labels[get32floatidx];
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
		int32_t sample = 0;
Packit 4a16fb
		snd_tmp_float_t tmp_float;
Packit 4a16fb
		snd_tmp_double_t tmp_double;
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 *get32float;
Packit 4a16fb
#define GET32F_END sample_loaded
Packit 4a16fb
#include "plugin_ops.h"
Packit 4a16fb
#undef GET32F_END
Packit 4a16fb
		sample_loaded:
Packit 4a16fb
			goto *put32;
Packit 4a16fb
#define PUT32_END sample_put
Packit 4a16fb
#include "plugin_ops.h"
Packit 4a16fb
#undef PUT32_END
Packit 4a16fb
		sample_put:
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_lfloat_hw_refine_cprepare(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_lfloat_t *lfloat = 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 lformat_mask = { SND_PCM_FMTBIT_LINEAR };
Packit 4a16fb
	snd_pcm_format_mask_t fformat_mask = { SND_PCM_FMTBIT_FLOAT };
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
					 snd_pcm_format_linear(lfloat->sformat) ?
Packit 4a16fb
					 &fformat_mask : &lformat_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_lfloat_hw_refine_sprepare(snd_pcm_t *pcm, snd_pcm_hw_params_t *sparams)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_lfloat_t *lfloat = 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, lfloat->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_lfloat_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_lfloat_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_lfloat_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_lfloat_hw_refine_cprepare,
Packit 4a16fb
				       snd_pcm_lfloat_hw_refine_cchange,
Packit 4a16fb
				       snd_pcm_lfloat_hw_refine_sprepare,
Packit 4a16fb
				       snd_pcm_lfloat_hw_refine_schange,
Packit 4a16fb
				       snd_pcm_generic_hw_refine);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_pcm_lfloat_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_lfloat_t *lfloat = pcm->private_data;
Packit 4a16fb
	snd_pcm_t *slave = lfloat->plug.gen.slave;
Packit 4a16fb
	snd_pcm_format_t src_format, dst_format;
Packit 4a16fb
	int err = snd_pcm_hw_params_slave(pcm, params,
Packit 4a16fb
					  snd_pcm_lfloat_hw_refine_cchange,
Packit 4a16fb
					  snd_pcm_lfloat_hw_refine_sprepare,
Packit 4a16fb
					  snd_pcm_lfloat_hw_refine_schange,
Packit 4a16fb
					  snd_pcm_generic_hw_params);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
Packit 4a16fb
		err = INTERNAL(snd_pcm_hw_params_get_format)(params, &src_format);
Packit 4a16fb
		dst_format = slave->format;
Packit 4a16fb
	} else {
Packit 4a16fb
		src_format = slave->format;
Packit 4a16fb
		err = INTERNAL(snd_pcm_hw_params_get_format)(params, &dst_format);
Packit 4a16fb
	}
Packit 4a16fb
	if (snd_pcm_format_linear(src_format)) {
Packit 4a16fb
		lfloat->int32_idx = snd_pcm_linear_get_index(src_format, SND_PCM_FORMAT_S32);
Packit 4a16fb
		lfloat->float32_idx = snd_pcm_lfloat_put_s32_index(dst_format);
Packit 4a16fb
		lfloat->func = snd_pcm_lfloat_convert_integer_float;
Packit 4a16fb
	} else {
Packit 4a16fb
		lfloat->int32_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_S32, dst_format);
Packit 4a16fb
		lfloat->float32_idx = snd_pcm_lfloat_get_s32_index(src_format);
Packit 4a16fb
		lfloat->func = snd_pcm_lfloat_convert_float_integer;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static snd_pcm_uframes_t
Packit 4a16fb
snd_pcm_lfloat_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_lfloat_t *lfloat = pcm->private_data;
Packit 4a16fb
	if (size > *slave_sizep)
Packit 4a16fb
		size = *slave_sizep;
Packit 4a16fb
	lfloat->func(slave_areas, slave_offset,
Packit 4a16fb
		     areas, offset, 
Packit 4a16fb
		     pcm->channels, size,
Packit 4a16fb
		     lfloat->int32_idx, lfloat->float32_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_lfloat_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_lfloat_t *lfloat = pcm->private_data;
Packit 4a16fb
	if (size > *slave_sizep)
Packit 4a16fb
		size = *slave_sizep;
Packit 4a16fb
	lfloat->func(areas, offset, 
Packit 4a16fb
		     slave_areas, slave_offset,
Packit 4a16fb
		     pcm->channels, size,
Packit 4a16fb
		     lfloat->int32_idx, lfloat->float32_idx);
Packit 4a16fb
	*slave_sizep = size;
Packit 4a16fb
	return size;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static void snd_pcm_lfloat_dump(snd_pcm_t *pcm, snd_output_t *out)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_lfloat_t *lfloat = pcm->private_data;
Packit 4a16fb
	snd_output_printf(out, "Linear Integer <-> Linear Float conversion PCM (%s)\n", 
Packit 4a16fb
		snd_pcm_format_name(lfloat->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(lfloat->plug.gen.slave, out);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static const snd_pcm_ops_t snd_pcm_lfloat_ops = {
Packit 4a16fb
	.close = snd_pcm_generic_close,
Packit 4a16fb
	.info = snd_pcm_generic_info,
Packit 4a16fb
	.hw_refine = snd_pcm_lfloat_hw_refine,
Packit 4a16fb
	.hw_params = snd_pcm_lfloat_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_lfloat_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 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_lfloat_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_lfloat_t *lfloat;
Packit 4a16fb
	int err;
Packit 4a16fb
	assert(pcmp && slave);
Packit 4a16fb
	if (snd_pcm_format_linear(sformat) != 1 &&
Packit 4a16fb
	    snd_pcm_format_float(sformat) != 1)
Packit 4a16fb
		return -EINVAL;
Packit 4a16fb
	lfloat = calloc(1, sizeof(snd_pcm_lfloat_t));
Packit 4a16fb
	if (!lfloat) {
Packit 4a16fb
		return -ENOMEM;
Packit 4a16fb
	}
Packit 4a16fb
	snd_pcm_plugin_init(&lfloat->plug);
Packit 4a16fb
	lfloat->sformat = sformat;
Packit 4a16fb
	lfloat->plug.read = snd_pcm_lfloat_read_areas;
Packit 4a16fb
	lfloat->plug.write = snd_pcm_lfloat_write_areas;
Packit 4a16fb
	lfloat->plug.undo_read = snd_pcm_plugin_undo_read_generic;
Packit 4a16fb
	lfloat->plug.undo_write = snd_pcm_plugin_undo_write_generic;
Packit 4a16fb
	lfloat->plug.gen.slave = slave;
Packit 4a16fb
	lfloat->plug.gen.close_slave = close_slave;
Packit 4a16fb
Packit 4a16fb
	err = snd_pcm_new(&pcm, SND_PCM_TYPE_LINEAR_FLOAT, name, slave->stream, slave->mode);
Packit 4a16fb
	if (err < 0) {
Packit 4a16fb
		free(lfloat);
Packit 4a16fb
		return err;
Packit 4a16fb
	}
Packit 4a16fb
	pcm->ops = &snd_pcm_lfloat_ops;
Packit 4a16fb
	pcm->fast_ops = &snd_pcm_plugin_fast_ops;
Packit 4a16fb
	pcm->private_data = lfloat;
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, &lfloat->plug.hw_ptr, -1, 0);
Packit 4a16fb
	snd_pcm_set_appl_ptr(pcm, &lfloat->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_lfloat Plugin: linear<->float
Packit 4a16fb
Packit 4a16fb
This plugin converts linear to float samples and float to linear samples from master
Packit 4a16fb
linear<->float conversion PCM to given slave PCM. The channel count, format and rate must
Packit 4a16fb
match for both of them.
Packit 4a16fb
Packit 4a16fb
\code
Packit 4a16fb
pcm.name {
Packit 4a16fb
        type lfloat             # Linear<->Float 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_lfloat_funcref Function reference
Packit 4a16fb
Packit 4a16fb
    Packit 4a16fb
      
  • snd_pcm_lfloat_open()
  • Packit 4a16fb
      
  • _snd_pcm_lfloat_open()
  • Packit 4a16fb
    Packit 4a16fb
    Packit 4a16fb
    */
    Packit 4a16fb
    Packit 4a16fb
    /**
    Packit 4a16fb
     * \brief Creates a new linear<->float 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_lfloat_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_pcm_format_float(sformat) != 1) {
    Packit 4a16fb
    		snd_config_delete(sconf);
    Packit 4a16fb
    		SNDERR("slave format is not linear integer or linear float");
    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_lfloat_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_lfloat_open, SND_PCM_DLSYM_VERSION);
    Packit 4a16fb
    #endif
    Packit 4a16fb
    Packit 4a16fb
    #else /* BUGGY_GCC */
    Packit 4a16fb
    Packit 4a16fb
    int snd_pcm_lfloat_open(snd_pcm_t **pcmp ATTRIBUTE_UNUSED,
    Packit 4a16fb
    			const char *name ATTRIBUTE_UNUSED,
    Packit 4a16fb
    			snd_pcm_format_t sformat ATTRIBUTE_UNUSED,
    Packit 4a16fb
    			snd_pcm_t *slave ATTRIBUTE_UNUSED,
    Packit 4a16fb
    			int close_slave ATTRIBUTE_UNUSED)
    Packit 4a16fb
    {
    Packit 4a16fb
    	SNDERR("please, upgrade your GCC to use lfloat plugin");
    Packit 4a16fb
    	return -EINVAL;
    Packit 4a16fb
    }
    Packit 4a16fb
    Packit 4a16fb
    int _snd_pcm_lfloat_open(snd_pcm_t **pcmp ATTRIBUTE_UNUSED,
    Packit 4a16fb
    			 const char *name ATTRIBUTE_UNUSED,
    Packit 4a16fb
    			 snd_config_t *root ATTRIBUTE_UNUSED,
    Packit 4a16fb
    			 snd_config_t *conf ATTRIBUTE_UNUSED, 
    Packit 4a16fb
    			 snd_pcm_stream_t stream ATTRIBUTE_UNUSED,
    Packit 4a16fb
    			 int mode ATTRIBUTE_UNUSED)
    Packit 4a16fb
    {
    Packit 4a16fb
    	SNDERR("please, upgrade your GCC to use lfloat plugin");
    Packit 4a16fb
    	return -EINVAL;
    Packit 4a16fb
    }
    Packit 4a16fb
    Packit 4a16fb
    #endif /* BUGGY_GCC */