1999-12-11 11:46:05 +00:00
|
|
|
/*
|
|
|
|
|
* PCM Plug-In shared (kernel/library) code
|
|
|
|
|
* Copyright (c) 1999 by Jaroslav Kysela <perex@suse.cz>
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
1999-12-12 20:25:53 +00:00
|
|
|
#if 0
|
1999-12-11 11:46:05 +00:00
|
|
|
#define PLUGIN_DEBUG
|
1999-12-12 20:25:53 +00:00
|
|
|
#endif
|
1999-12-11 11:46:05 +00:00
|
|
|
#include "../include/driver.h"
|
|
|
|
|
#include "../include/pcm.h"
|
|
|
|
|
#define snd_pcm_plugin_first(pb, channel) ((pb)->oss.plugin_first)
|
|
|
|
|
#define snd_pcm_plugin_last(pb, channel) ((pb)->oss.plugin_last)
|
|
|
|
|
#define snd_pcm_plugin_append(pb, channel, plugin) snd_pcm_oss_plugin_append(pb, plugin)
|
2000-03-22 16:18:04 +00:00
|
|
|
#define my_calloc(size) snd_kcalloc(size, GFP_KERNEL)
|
|
|
|
|
#define my_free(ptr) snd_kfree(ptr)
|
2000-03-29 20:26:06 +00:00
|
|
|
#define my_strdup(str) snd_kmalloc_strdup(str, GFP_KERNEL)
|
1999-12-11 11:46:05 +00:00
|
|
|
#else
|
2000-03-22 16:18:04 +00:00
|
|
|
#include <malloc.h>
|
1999-12-11 11:46:05 +00:00
|
|
|
#include <errno.h>
|
2000-03-29 20:26:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
1999-12-11 11:46:05 +00:00
|
|
|
#include "pcm_local.h"
|
2000-03-22 16:18:04 +00:00
|
|
|
#define my_calloc(size) calloc(1, size)
|
|
|
|
|
#define my_free(ptr) free(ptr)
|
2000-03-29 20:26:06 +00:00
|
|
|
#define my_strdup(str) strdup(str)
|
1999-12-11 11:46:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
2000-03-29 20:26:06 +00:00
|
|
|
ssize_t snd_pcm_plugin_src_samples_to_size(snd_pcm_plugin_t *plugin, size_t samples)
|
|
|
|
|
{
|
|
|
|
|
ssize_t result;
|
|
|
|
|
|
|
|
|
|
if (plugin == NULL)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
result = samples * plugin->src_format.voices * plugin->src_width;
|
|
|
|
|
if ((result % 8) != 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
return result / 8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ssize_t snd_pcm_plugin_dst_samples_to_size(snd_pcm_plugin_t *plugin, size_t samples)
|
|
|
|
|
{
|
|
|
|
|
ssize_t result;
|
|
|
|
|
|
|
|
|
|
if (plugin == NULL)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
result = samples * plugin->dst_format.voices * plugin->dst_width;
|
|
|
|
|
if ((result % 8) != 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
return result / 8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ssize_t snd_pcm_plugin_src_size_to_samples(snd_pcm_plugin_t *plugin, size_t size)
|
|
|
|
|
{
|
|
|
|
|
ssize_t result;
|
|
|
|
|
long tmp;
|
|
|
|
|
|
|
|
|
|
if (plugin == NULL)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
result = size * 8;
|
|
|
|
|
tmp = plugin->src_format.voices * plugin->src_width;
|
|
|
|
|
if ((result % tmp) != 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
return result / tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ssize_t snd_pcm_plugin_dst_size_to_samples(snd_pcm_plugin_t *plugin, size_t size)
|
|
|
|
|
{
|
|
|
|
|
ssize_t result;
|
|
|
|
|
long tmp;
|
|
|
|
|
|
|
|
|
|
if (plugin == NULL)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
result = size * 8;
|
|
|
|
|
tmp = plugin->dst_format.voices * plugin->dst_width;
|
|
|
|
|
if ((result % tmp) != 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
return result / tmp;
|
|
|
|
|
}
|
1999-12-11 11:46:05 +00:00
|
|
|
|
2000-03-29 20:26:06 +00:00
|
|
|
ssize_t snd_pcm_plugin_client_samples(snd_pcm_plugin_handle_t *pb, int channel, size_t drv_samples)
|
1999-12-11 11:46:05 +00:00
|
|
|
{
|
|
|
|
|
snd_pcm_plugin_t *plugin, *plugin_prev, *plugin_next;
|
|
|
|
|
|
2000-01-08 20:11:33 +00:00
|
|
|
if (pb == NULL || (channel != SND_PCM_CHANNEL_PLAYBACK &&
|
2000-03-29 20:26:06 +00:00
|
|
|
channel != SND_PCM_CHANNEL_CAPTURE))
|
1999-12-11 11:46:05 +00:00
|
|
|
return -EINVAL;
|
2000-03-29 20:26:06 +00:00
|
|
|
if (drv_samples == 0)
|
1999-12-11 11:46:05 +00:00
|
|
|
return 0;
|
2000-03-29 20:26:06 +00:00
|
|
|
if (drv_samples < 0)
|
1999-12-11 11:46:05 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
if (channel == SND_PCM_CHANNEL_PLAYBACK) {
|
2000-03-29 20:26:06 +00:00
|
|
|
plugin = snd_pcm_plugin_last(pb, SND_PCM_CHANNEL_PLAYBACK);
|
|
|
|
|
while (plugin && drv_samples > 0) {
|
1999-12-11 11:46:05 +00:00
|
|
|
plugin_prev = plugin->prev;
|
2000-03-29 20:26:06 +00:00
|
|
|
if (plugin->src_samples)
|
|
|
|
|
drv_samples = plugin->src_samples(plugin, drv_samples);
|
1999-12-11 11:46:05 +00:00
|
|
|
plugin = plugin_prev;
|
|
|
|
|
}
|
|
|
|
|
} else if (channel == SND_PCM_CHANNEL_CAPTURE) {
|
2000-03-29 20:26:06 +00:00
|
|
|
plugin = snd_pcm_plugin_first(pb, SND_PCM_CHANNEL_CAPTURE);
|
|
|
|
|
while (plugin && drv_samples > 0) {
|
1999-12-11 11:46:05 +00:00
|
|
|
plugin_next = plugin->next;
|
2000-03-29 20:26:06 +00:00
|
|
|
if (plugin->dst_samples)
|
|
|
|
|
drv_samples = plugin->dst_samples(plugin, drv_samples);
|
1999-12-11 11:46:05 +00:00
|
|
|
plugin = plugin_next;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-03-29 20:26:06 +00:00
|
|
|
return drv_samples;
|
1999-12-11 11:46:05 +00:00
|
|
|
}
|
|
|
|
|
|
2000-03-29 20:26:06 +00:00
|
|
|
ssize_t snd_pcm_plugin_hardware_samples(snd_pcm_plugin_handle_t *pb, int channel, size_t clt_samples)
|
1999-12-11 11:46:05 +00:00
|
|
|
{
|
|
|
|
|
snd_pcm_plugin_t *plugin, *plugin_prev, *plugin_next;
|
|
|
|
|
|
2000-01-08 20:11:33 +00:00
|
|
|
if (pb == NULL || (channel != SND_PCM_CHANNEL_PLAYBACK &&
|
2000-03-29 20:26:06 +00:00
|
|
|
channel != SND_PCM_CHANNEL_CAPTURE))
|
1999-12-11 11:46:05 +00:00
|
|
|
return -EINVAL;
|
2000-03-29 20:26:06 +00:00
|
|
|
if (clt_samples == 0)
|
1999-12-11 11:46:05 +00:00
|
|
|
return 0;
|
2000-03-29 20:26:06 +00:00
|
|
|
if (clt_samples < 0)
|
1999-12-11 11:46:05 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
if (channel == SND_PCM_CHANNEL_PLAYBACK) {
|
2000-03-29 20:26:06 +00:00
|
|
|
plugin = snd_pcm_plugin_first(pb, SND_PCM_CHANNEL_PLAYBACK);
|
|
|
|
|
while (plugin && clt_samples > 0) {
|
1999-12-11 11:46:05 +00:00
|
|
|
plugin_next = plugin->next;
|
2000-03-29 20:26:06 +00:00
|
|
|
if (plugin->dst_samples)
|
|
|
|
|
clt_samples = plugin->dst_samples(plugin, clt_samples);
|
1999-12-11 11:46:05 +00:00
|
|
|
plugin = plugin_next;
|
|
|
|
|
}
|
2000-03-29 20:26:06 +00:00
|
|
|
if (clt_samples < 0)
|
|
|
|
|
return clt_samples;
|
1999-12-11 11:46:05 +00:00
|
|
|
} else if (channel == SND_PCM_CHANNEL_CAPTURE) {
|
2000-03-29 20:26:06 +00:00
|
|
|
plugin = snd_pcm_plugin_last(pb, SND_PCM_CHANNEL_CAPTURE);
|
1999-12-11 11:46:05 +00:00
|
|
|
while (plugin) {
|
|
|
|
|
plugin_prev = plugin->prev;
|
2000-03-29 20:26:06 +00:00
|
|
|
if (plugin->src_samples)
|
|
|
|
|
clt_samples = plugin->src_samples(plugin, clt_samples);
|
1999-12-11 11:46:05 +00:00
|
|
|
plugin = plugin_prev;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-03-29 20:26:06 +00:00
|
|
|
return clt_samples;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ssize_t snd_pcm_plugin_client_size(snd_pcm_plugin_handle_t *pb, int channel, size_t drv_size)
|
|
|
|
|
{
|
|
|
|
|
snd_pcm_plugin_t *plugin;
|
|
|
|
|
ssize_t result = 0;
|
|
|
|
|
|
|
|
|
|
if (pb == NULL || (channel != SND_PCM_CHANNEL_PLAYBACK &&
|
|
|
|
|
channel != SND_PCM_CHANNEL_CAPTURE))
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (drv_size == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
if (drv_size < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (channel == SND_PCM_CHANNEL_PLAYBACK) {
|
|
|
|
|
plugin = snd_pcm_plugin_last(pb, SND_PCM_CHANNEL_PLAYBACK);
|
|
|
|
|
result = snd_pcm_plugin_src_size_to_samples(plugin, drv_size);
|
|
|
|
|
result = snd_pcm_plugin_client_samples(pb, SND_PCM_CHANNEL_PLAYBACK, result);
|
|
|
|
|
if (result < 0)
|
|
|
|
|
return result;
|
|
|
|
|
plugin = snd_pcm_plugin_first(pb, SND_PCM_CHANNEL_PLAYBACK);
|
|
|
|
|
result = snd_pcm_plugin_src_samples_to_size(plugin, result);
|
|
|
|
|
} else if (channel == SND_PCM_CHANNEL_CAPTURE) {
|
|
|
|
|
plugin = snd_pcm_plugin_first(pb, SND_PCM_CHANNEL_CAPTURE);
|
|
|
|
|
result = snd_pcm_plugin_src_size_to_samples(plugin, drv_size);
|
|
|
|
|
result = snd_pcm_plugin_client_samples(pb, SND_PCM_CHANNEL_PLAYBACK, result);
|
|
|
|
|
plugin = snd_pcm_plugin_last(pb, SND_PCM_CHANNEL_CAPTURE);
|
|
|
|
|
result = snd_pcm_plugin_dst_samples_to_size(plugin, result);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ssize_t snd_pcm_plugin_hardware_size(snd_pcm_plugin_handle_t *pb, int channel, size_t clt_size)
|
|
|
|
|
{
|
|
|
|
|
snd_pcm_plugin_t *plugin;
|
|
|
|
|
ssize_t result = 0;
|
|
|
|
|
|
|
|
|
|
if (pb == NULL || (channel != SND_PCM_CHANNEL_PLAYBACK &&
|
|
|
|
|
channel != SND_PCM_CHANNEL_CAPTURE))
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (clt_size == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
if (clt_size < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (channel == SND_PCM_CHANNEL_PLAYBACK) {
|
|
|
|
|
plugin = snd_pcm_plugin_first(pb, SND_PCM_CHANNEL_PLAYBACK);
|
|
|
|
|
result = snd_pcm_plugin_src_size_to_samples(plugin, clt_size);
|
|
|
|
|
result = snd_pcm_plugin_hardware_samples(pb, SND_PCM_CHANNEL_PLAYBACK, result);
|
|
|
|
|
if (result < 0)
|
|
|
|
|
return result;
|
|
|
|
|
plugin = snd_pcm_plugin_last(pb, SND_PCM_CHANNEL_PLAYBACK);
|
|
|
|
|
result = snd_pcm_plugin_dst_samples_to_size(plugin, result);
|
|
|
|
|
} else if (channel == SND_PCM_CHANNEL_CAPTURE) {
|
|
|
|
|
plugin = snd_pcm_plugin_last(pb, SND_PCM_CHANNEL_CAPTURE);
|
|
|
|
|
result = snd_pcm_plugin_src_size_to_samples(plugin, clt_size);
|
|
|
|
|
result = snd_pcm_plugin_hardware_samples(pb, SND_PCM_CHANNEL_PLAYBACK, result);
|
|
|
|
|
if (result < 0)
|
|
|
|
|
return result;
|
|
|
|
|
plugin = snd_pcm_plugin_first(pb, SND_PCM_CHANNEL_CAPTURE);
|
|
|
|
|
result = snd_pcm_plugin_dst_samples_to_size(plugin, result);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
1999-12-11 11:46:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int snd_pcm_plugin_formats(unsigned int formats)
|
|
|
|
|
{
|
1999-12-25 15:25:46 +00:00
|
|
|
int linfmts = (SND_PCM_FMT_U8 | SND_PCM_FMT_S8 |
|
|
|
|
|
SND_PCM_FMT_U16_LE | SND_PCM_FMT_S16_LE |
|
|
|
|
|
SND_PCM_FMT_U16_BE | SND_PCM_FMT_S16_BE |
|
1999-12-28 14:51:00 +00:00
|
|
|
SND_PCM_FMT_U24_LE | SND_PCM_FMT_S24_LE |
|
|
|
|
|
SND_PCM_FMT_U24_BE | SND_PCM_FMT_S24_BE |
|
1999-12-25 15:25:46 +00:00
|
|
|
SND_PCM_FMT_U32_LE | SND_PCM_FMT_S32_LE |
|
|
|
|
|
SND_PCM_FMT_U32_BE | SND_PCM_FMT_S32_BE);
|
1999-12-11 20:08:34 +00:00
|
|
|
formats |= SND_PCM_FMT_MU_LAW;
|
|
|
|
|
#ifndef __KERNEL__
|
|
|
|
|
formats |= SND_PCM_FMT_A_LAW | SND_PCM_FMT_IMA_ADPCM;
|
|
|
|
|
#endif
|
1999-12-25 15:25:46 +00:00
|
|
|
|
|
|
|
|
if (formats & linfmts)
|
|
|
|
|
formats |= linfmts;
|
1999-12-11 11:46:05 +00:00
|
|
|
return formats;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-25 15:25:46 +00:00
|
|
|
static int preferred_formats[] = {
|
|
|
|
|
SND_PCM_SFMT_S16_LE,
|
|
|
|
|
SND_PCM_SFMT_S16_BE,
|
|
|
|
|
SND_PCM_SFMT_U16_LE,
|
|
|
|
|
SND_PCM_SFMT_U16_BE,
|
|
|
|
|
SND_PCM_SFMT_S24_LE,
|
|
|
|
|
SND_PCM_SFMT_S24_BE,
|
|
|
|
|
SND_PCM_SFMT_U24_LE,
|
|
|
|
|
SND_PCM_SFMT_U24_BE,
|
|
|
|
|
SND_PCM_SFMT_S32_LE,
|
|
|
|
|
SND_PCM_SFMT_S32_BE,
|
|
|
|
|
SND_PCM_SFMT_U32_LE,
|
|
|
|
|
SND_PCM_SFMT_U32_BE,
|
|
|
|
|
SND_PCM_SFMT_S8,
|
|
|
|
|
SND_PCM_SFMT_U8
|
|
|
|
|
};
|
|
|
|
|
|
1999-12-11 11:46:05 +00:00
|
|
|
int snd_pcm_plugin_hwparams(snd_pcm_channel_params_t *params,
|
|
|
|
|
snd_pcm_channel_info_t *hwinfo,
|
|
|
|
|
snd_pcm_channel_params_t *hwparams)
|
|
|
|
|
{
|
|
|
|
|
memcpy(hwparams, params, sizeof(*hwparams));
|
|
|
|
|
if ((hwinfo->formats & (1 << params->format.format)) == 0) {
|
1999-12-25 15:25:46 +00:00
|
|
|
int format = params->format.format;
|
|
|
|
|
if ((snd_pcm_plugin_formats(hwinfo->formats) & (1 << format)) == 0)
|
1999-12-11 11:46:05 +00:00
|
|
|
return -EINVAL;
|
1999-12-25 15:25:46 +00:00
|
|
|
if (snd_pcm_format_linear(format)) {
|
|
|
|
|
int width = snd_pcm_format_width(format);
|
|
|
|
|
int unsignd = snd_pcm_format_unsigned(format);
|
|
|
|
|
int big = snd_pcm_format_big_endian(format);
|
|
|
|
|
int format1;
|
|
|
|
|
int wid, width1=width;
|
1999-12-28 14:51:00 +00:00
|
|
|
int dwidth1 = 8;
|
1999-12-25 15:25:46 +00:00
|
|
|
for (wid = 0; wid < 4; ++wid) {
|
|
|
|
|
int end, big1 = big;
|
|
|
|
|
for (end = 0; end < 2; ++end) {
|
|
|
|
|
int sgn, unsignd1 = unsignd;
|
|
|
|
|
for (sgn = 0; sgn < 2; ++sgn) {
|
|
|
|
|
format1 = snd_pcm_build_linear_format(width1, unsignd1, big1);
|
|
|
|
|
if (format1 >= 0 &&
|
|
|
|
|
hwinfo->formats & (1 << format1))
|
|
|
|
|
goto _found;
|
|
|
|
|
unsignd1 = !unsignd1;
|
|
|
|
|
}
|
|
|
|
|
big1 = !big1;
|
|
|
|
|
}
|
1999-12-28 14:51:00 +00:00
|
|
|
if (width1 == 32) {
|
|
|
|
|
dwidth1 = -dwidth1;
|
|
|
|
|
width1 = width;
|
|
|
|
|
}
|
|
|
|
|
width1 += dwidth1;
|
1999-12-11 11:46:05 +00:00
|
|
|
}
|
1999-12-25 15:25:46 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
_found:
|
|
|
|
|
hwparams->format.format = format1;
|
|
|
|
|
} else {
|
|
|
|
|
int i;
|
|
|
|
|
switch (format) {
|
|
|
|
|
case SND_PCM_SFMT_MU_LAW:
|
1999-12-11 11:46:05 +00:00
|
|
|
#ifndef __KERNEL__
|
1999-12-25 15:25:46 +00:00
|
|
|
case SND_PCM_SFMT_A_LAW:
|
|
|
|
|
case SND_PCM_SFMT_IMA_ADPCM:
|
|
|
|
|
#endif
|
|
|
|
|
for (i = 0; i < sizeof(preferred_formats) / sizeof(preferred_formats[0]); ++i) {
|
|
|
|
|
int format1 = preferred_formats[i];
|
|
|
|
|
if (hwinfo->formats & (1 << format1)) {
|
|
|
|
|
hwparams->format.format = format1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (i == sizeof(preferred_formats)/sizeof(preferred_formats[0]))
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
1999-12-11 11:46:05 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* voices */
|
|
|
|
|
if (params->format.voices < hwinfo->min_voices ||
|
|
|
|
|
params->format.voices > hwinfo->max_voices) {
|
|
|
|
|
int dst_voices = params->format.voices < hwinfo->min_voices ?
|
|
|
|
|
hwinfo->min_voices : hwinfo->max_voices;
|
|
|
|
|
if ((params->format.rate < hwinfo->min_rate ||
|
|
|
|
|
params->format.rate > hwinfo->max_rate) &&
|
|
|
|
|
dst_voices > 2)
|
|
|
|
|
dst_voices = 2;
|
|
|
|
|
hwparams->format.voices = dst_voices;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* rate */
|
|
|
|
|
if (params->format.rate < hwinfo->min_rate ||
|
|
|
|
|
params->format.rate > hwinfo->max_rate) {
|
|
|
|
|
int dst_rate = params->format.rate < hwinfo->min_rate ?
|
|
|
|
|
hwinfo->min_rate : hwinfo->max_rate;
|
|
|
|
|
hwparams->format.rate = dst_rate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* interleave */
|
|
|
|
|
if (!(hwinfo->flags & SND_PCM_CHNINFO_INTERLEAVE))
|
|
|
|
|
hwparams->format.interleave = 0;
|
|
|
|
|
if (!(hwinfo->flags & SND_PCM_CHNINFO_NONINTERLEAVE))
|
|
|
|
|
hwparams->format.interleave = 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-22 16:18:04 +00:00
|
|
|
#define ROUTE_PLUGIN_RESOLUTION 16
|
1999-12-11 11:46:05 +00:00
|
|
|
|
2000-03-29 20:26:06 +00:00
|
|
|
int snd_pcm_plugin_format(snd_pcm_plugin_handle_t *pb,
|
1999-12-11 11:46:05 +00:00
|
|
|
snd_pcm_channel_params_t *params,
|
|
|
|
|
snd_pcm_channel_params_t *hwparams,
|
1999-12-12 17:23:44 +00:00
|
|
|
snd_pcm_channel_info_t *hwinfo)
|
1999-12-11 11:46:05 +00:00
|
|
|
{
|
1999-12-11 20:08:34 +00:00
|
|
|
snd_pcm_channel_params_t tmpparams;
|
1999-12-12 17:23:44 +00:00
|
|
|
snd_pcm_channel_params_t dstparams;
|
|
|
|
|
snd_pcm_channel_params_t *srcparams;
|
1999-12-11 11:46:05 +00:00
|
|
|
snd_pcm_plugin_t *plugin;
|
|
|
|
|
int err;
|
1999-12-11 21:20:03 +00:00
|
|
|
|
2000-01-08 20:11:33 +00:00
|
|
|
switch (params->channel) {
|
|
|
|
|
case SND_PCM_CHANNEL_PLAYBACK:
|
1999-12-12 17:23:44 +00:00
|
|
|
memcpy(&dstparams, hwparams, sizeof(*hwparams));
|
|
|
|
|
srcparams = hwparams;
|
|
|
|
|
memcpy(srcparams, params, sizeof(*params));
|
2000-01-08 20:11:33 +00:00
|
|
|
break;
|
|
|
|
|
case SND_PCM_CHANNEL_CAPTURE:
|
1999-12-12 17:23:44 +00:00
|
|
|
memcpy(&dstparams, params, sizeof(*params));
|
|
|
|
|
srcparams = params;
|
|
|
|
|
memcpy(srcparams, hwparams, sizeof(*hwparams));
|
2000-01-08 20:11:33 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -EINVAL;
|
1999-12-11 11:46:05 +00:00
|
|
|
}
|
1999-12-12 17:23:44 +00:00
|
|
|
memcpy(&tmpparams, srcparams, sizeof(*srcparams));
|
|
|
|
|
|
|
|
|
|
pdprintf("srcparams: interleave=%i, format=%i, rate=%i, voices=%i\n",
|
|
|
|
|
srcparams->format.interleave,
|
|
|
|
|
srcparams->format.format,
|
|
|
|
|
srcparams->format.rate,
|
|
|
|
|
srcparams->format.voices);
|
1999-12-11 11:46:05 +00:00
|
|
|
pdprintf("dstparams: interleave=%i, format=%i, rate=%i, voices=%i\n",
|
1999-12-12 17:23:44 +00:00
|
|
|
dstparams.format.interleave,
|
|
|
|
|
dstparams.format.format,
|
|
|
|
|
dstparams.format.rate,
|
|
|
|
|
dstparams.format.voices);
|
2000-03-22 16:18:04 +00:00
|
|
|
|
|
|
|
|
/* voices reduction */
|
|
|
|
|
if (srcparams->format.voices > dstparams.format.voices) {
|
2000-03-29 20:26:06 +00:00
|
|
|
#if 0
|
2000-03-22 16:18:04 +00:00
|
|
|
int sv = srcparams->format.voices;
|
|
|
|
|
int dv = dstparams.format.voices;
|
|
|
|
|
int *ttable = my_calloc(dv*sv*sizeof(*ttable));
|
|
|
|
|
#if 1
|
|
|
|
|
if (sv == 2 && dv == 1) {
|
|
|
|
|
ttable[0] = ROUTE_PLUGIN_RESOLUTION / 2;
|
|
|
|
|
ttable[1] = ROUTE_PLUGIN_RESOLUTION / 2;
|
|
|
|
|
} else
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
int v;
|
|
|
|
|
for (v = 0; v < dv; ++v)
|
|
|
|
|
ttable[v * sv + v] = ROUTE_PLUGIN_RESOLUTION;
|
|
|
|
|
}
|
|
|
|
|
tmpparams.format.voices = dstparams.format.voices;
|
|
|
|
|
err = snd_pcm_plugin_build_route(&srcparams->format,
|
|
|
|
|
&tmpparams.format,
|
|
|
|
|
ttable,
|
|
|
|
|
&plugin);
|
|
|
|
|
my_free(ttable);
|
|
|
|
|
pdprintf("params voices reduction: src=%i, dst=%i returns %i\n", srcparams->format.voices, tmpparams.format.voices, err);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
err = snd_pcm_plugin_append(pb, params->channel, plugin);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
srcparams->format.voices = tmpparams.format.voices;
|
2000-03-29 20:26:06 +00:00
|
|
|
#else
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return -EIO;
|
|
|
|
|
#endif
|
2000-03-22 16:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
1999-12-11 11:46:05 +00:00
|
|
|
/* Convert to interleaved format if needed */
|
1999-12-12 17:23:44 +00:00
|
|
|
if (!srcparams->format.interleave &&
|
2000-03-22 16:18:04 +00:00
|
|
|
srcparams->format.voices > 1 &&
|
|
|
|
|
srcparams->format.rate != dstparams.format.rate) {
|
1999-12-11 11:46:05 +00:00
|
|
|
tmpparams.format.interleave = 1;
|
2000-03-29 20:26:06 +00:00
|
|
|
err = snd_pcm_plugin_build_interleave(pb,
|
|
|
|
|
&srcparams->format,
|
1999-12-11 11:46:05 +00:00
|
|
|
&tmpparams.format,
|
|
|
|
|
&plugin);
|
1999-12-12 17:23:44 +00:00
|
|
|
pdprintf("params interleave change: src=%i, dst=%i returns %i\n", srcparams->format.interleave, tmpparams.format.interleave, err);
|
1999-12-11 11:46:05 +00:00
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
err = snd_pcm_plugin_append(pb, params->channel, plugin);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
1999-12-12 17:23:44 +00:00
|
|
|
srcparams->format.interleave = 1;
|
1999-12-11 11:46:05 +00:00
|
|
|
/* Avoid useless interleave revert */
|
|
|
|
|
if (params->channel == SND_PCM_CHANNEL_PLAYBACK &&
|
|
|
|
|
(hwinfo->flags & SND_PCM_CHNINFO_INTERLEAVE))
|
1999-12-12 17:23:44 +00:00
|
|
|
dstparams.format.interleave = 1;
|
1999-12-11 11:46:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* rate down resampling */
|
1999-12-12 17:23:44 +00:00
|
|
|
if (srcparams->format.rate > dstparams.format.rate &&
|
|
|
|
|
snd_pcm_format_linear(srcparams->format.format) &&
|
|
|
|
|
snd_pcm_format_width(srcparams->format.format) <= 16 &&
|
|
|
|
|
snd_pcm_format_width(srcparams->format.format) >= snd_pcm_format_width(srcparams->format.format)) {
|
|
|
|
|
tmpparams.format.rate = dstparams.format.rate;
|
2000-03-29 20:26:06 +00:00
|
|
|
err = snd_pcm_plugin_build_rate(pb,
|
|
|
|
|
&srcparams->format,
|
1999-12-11 11:46:05 +00:00
|
|
|
&tmpparams.format,
|
|
|
|
|
&plugin);
|
1999-12-12 17:23:44 +00:00
|
|
|
pdprintf("params rate down resampling: src=%i, dst=%i returns %i\n", srcparams->format.rate, tmpparams.format.rate, err);
|
1999-12-11 11:46:05 +00:00
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
err = snd_pcm_plugin_append(pb, params->channel, plugin);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
1999-12-12 17:23:44 +00:00
|
|
|
srcparams->format.rate = tmpparams.format.rate;
|
1999-12-11 11:46:05 +00:00
|
|
|
}
|
1999-12-12 17:23:44 +00:00
|
|
|
|
|
|
|
|
/* format change (linearization) */
|
|
|
|
|
if (srcparams->format.format != dstparams.format.format &&
|
|
|
|
|
!snd_pcm_format_linear(srcparams->format.format) &&
|
|
|
|
|
!snd_pcm_format_linear(dstparams.format.format)) {
|
|
|
|
|
tmpparams.format.format = SND_PCM_SFMT_S16_LE;
|
|
|
|
|
switch (srcparams->format.format) {
|
1999-12-11 11:46:05 +00:00
|
|
|
case SND_PCM_SFMT_MU_LAW:
|
2000-03-29 20:26:06 +00:00
|
|
|
err = snd_pcm_plugin_build_mulaw(pb,
|
|
|
|
|
&srcparams->format,
|
1999-12-11 11:46:05 +00:00
|
|
|
&tmpparams.format,
|
|
|
|
|
&plugin);
|
|
|
|
|
break;
|
|
|
|
|
#ifndef __KERNEL__
|
|
|
|
|
case SND_PCM_SFMT_A_LAW:
|
2000-03-29 20:26:06 +00:00
|
|
|
err = snd_pcm_plugin_build_alaw(pb,
|
|
|
|
|
&srcparams->format,
|
1999-12-11 11:46:05 +00:00
|
|
|
&tmpparams.format,
|
|
|
|
|
&plugin);
|
|
|
|
|
break;
|
|
|
|
|
case SND_PCM_SFMT_IMA_ADPCM:
|
2000-03-29 20:26:06 +00:00
|
|
|
err = snd_pcm_plugin_build_adpcm(pb,
|
|
|
|
|
&srcparams->format,
|
1999-12-11 11:46:05 +00:00
|
|
|
&tmpparams.format,
|
|
|
|
|
&plugin);
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
default:
|
1999-12-12 17:23:44 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
pdprintf("params format change: src=%i, dst=%i returns %i\n", srcparams->format.format, tmpparams.format.format, err);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
err = snd_pcm_plugin_append(pb, params->channel, plugin);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
srcparams->format.format = tmpparams.format.format;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* format change */
|
|
|
|
|
if (srcparams->format.format != dstparams.format.format) {
|
|
|
|
|
tmpparams.format.format = dstparams.format.format;
|
|
|
|
|
if (srcparams->format.format == SND_PCM_SFMT_MU_LAW ||
|
|
|
|
|
tmpparams.format.format == SND_PCM_SFMT_MU_LAW) {
|
2000-03-29 20:26:06 +00:00
|
|
|
err = snd_pcm_plugin_build_mulaw(pb,
|
|
|
|
|
&srcparams->format,
|
1999-12-12 17:23:44 +00:00
|
|
|
&tmpparams.format,
|
|
|
|
|
&plugin);
|
|
|
|
|
}
|
|
|
|
|
#ifndef __KERNEL__
|
|
|
|
|
else if (srcparams->format.format == SND_PCM_SFMT_A_LAW ||
|
|
|
|
|
tmpparams.format.format == SND_PCM_SFMT_A_LAW) {
|
2000-03-29 20:26:06 +00:00
|
|
|
err = snd_pcm_plugin_build_alaw(pb,
|
|
|
|
|
&srcparams->format,
|
1999-12-12 17:23:44 +00:00
|
|
|
&tmpparams.format,
|
|
|
|
|
&plugin);
|
|
|
|
|
}
|
|
|
|
|
else if (srcparams->format.format == SND_PCM_SFMT_IMA_ADPCM ||
|
|
|
|
|
tmpparams.format.format == SND_PCM_SFMT_IMA_ADPCM) {
|
2000-03-29 20:26:06 +00:00
|
|
|
err = snd_pcm_plugin_build_adpcm(pb,
|
|
|
|
|
&srcparams->format,
|
1999-12-12 17:23:44 +00:00
|
|
|
&tmpparams.format,
|
|
|
|
|
&plugin);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
else if (snd_pcm_format_linear(srcparams->format.format) &&
|
|
|
|
|
snd_pcm_format_linear(tmpparams.format.format)) {
|
2000-03-29 20:26:06 +00:00
|
|
|
err = snd_pcm_plugin_build_linear(pb,
|
|
|
|
|
&srcparams->format,
|
1999-12-11 11:46:05 +00:00
|
|
|
&tmpparams.format,
|
|
|
|
|
&plugin);
|
|
|
|
|
}
|
1999-12-12 17:23:44 +00:00
|
|
|
else
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
pdprintf("params format change: src=%i, dst=%i returns %i\n", srcparams->format.format, tmpparams.format.format, err);
|
1999-12-11 11:46:05 +00:00
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
err = snd_pcm_plugin_append(pb, params->channel, plugin);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
1999-12-12 17:23:44 +00:00
|
|
|
srcparams->format.format = tmpparams.format.format;
|
1999-12-11 11:46:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* rate resampling */
|
1999-12-12 17:23:44 +00:00
|
|
|
if (srcparams->format.rate != dstparams.format.rate) {
|
|
|
|
|
tmpparams.format.rate = dstparams.format.rate;
|
2000-03-29 20:26:06 +00:00
|
|
|
err = snd_pcm_plugin_build_rate(pb,
|
|
|
|
|
&srcparams->format,
|
1999-12-11 11:46:05 +00:00
|
|
|
&tmpparams.format,
|
|
|
|
|
&plugin);
|
1999-12-12 17:23:44 +00:00
|
|
|
pdprintf("params rate resampling: src=%i, dst=%i return %i\n", srcparams->format.rate, tmpparams.format.rate, err);
|
1999-12-11 11:46:05 +00:00
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
err = snd_pcm_plugin_append(pb, params->channel, plugin);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
1999-12-12 17:23:44 +00:00
|
|
|
srcparams->format.rate = tmpparams.format.rate;
|
1999-12-11 11:46:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* voices extension */
|
2000-03-22 16:18:04 +00:00
|
|
|
if (srcparams->format.voices < dstparams.format.voices) {
|
2000-03-29 20:26:06 +00:00
|
|
|
#if 0
|
2000-03-22 16:18:04 +00:00
|
|
|
int sv = srcparams->format.voices;
|
|
|
|
|
int dv = dstparams.format.voices;
|
|
|
|
|
int *ttable = my_calloc(dv * sv * sizeof(*ttable));
|
|
|
|
|
#if 1
|
|
|
|
|
if (sv == 1 && dv == 2) {
|
|
|
|
|
ttable[0] = ROUTE_PLUGIN_RESOLUTION;
|
|
|
|
|
ttable[1] = ROUTE_PLUGIN_RESOLUTION;
|
|
|
|
|
} else
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
int v;
|
|
|
|
|
for (v = 0; v < sv; ++v)
|
|
|
|
|
ttable[v * sv + v] = ROUTE_PLUGIN_RESOLUTION;
|
|
|
|
|
}
|
1999-12-12 17:23:44 +00:00
|
|
|
tmpparams.format.voices = dstparams.format.voices;
|
2000-03-22 16:18:04 +00:00
|
|
|
err = snd_pcm_plugin_build_route(&srcparams->format,
|
1999-12-11 11:46:05 +00:00
|
|
|
&tmpparams.format,
|
2000-03-22 16:18:04 +00:00
|
|
|
ttable,
|
1999-12-11 11:46:05 +00:00
|
|
|
&plugin);
|
2000-03-22 16:18:04 +00:00
|
|
|
my_free(ttable);
|
1999-12-12 17:23:44 +00:00
|
|
|
pdprintf("params voices extension: src=%i, dst=%i returns %i\n", srcparams->format.voices, tmpparams.format.voices, err);
|
1999-12-11 11:46:05 +00:00
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
err = snd_pcm_plugin_append(pb, params->channel, plugin);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
1999-12-12 17:23:44 +00:00
|
|
|
srcparams->format.voices = tmpparams.format.voices;
|
2000-03-29 20:26:06 +00:00
|
|
|
#else
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return -EIO;
|
|
|
|
|
#endif
|
1999-12-11 11:46:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* interleave change */
|
1999-12-12 17:23:44 +00:00
|
|
|
if (dstparams.format.voices > 1 &&
|
1999-12-11 11:46:05 +00:00
|
|
|
hwinfo->mode == SND_PCM_MODE_BLOCK &&
|
1999-12-12 17:23:44 +00:00
|
|
|
srcparams->format.interleave != dstparams.format.interleave) {
|
|
|
|
|
tmpparams.format.interleave = dstparams.format.interleave;
|
2000-03-29 20:26:06 +00:00
|
|
|
err = snd_pcm_plugin_build_interleave(pb,
|
|
|
|
|
&srcparams->format,
|
1999-12-11 11:46:05 +00:00
|
|
|
&tmpparams.format,
|
|
|
|
|
&plugin);
|
1999-12-12 17:23:44 +00:00
|
|
|
pdprintf("params interleave change: src=%i, dst=%i return %i\n", srcparams->format.interleave, tmpparams.format.interleave, err);
|
1999-12-11 11:46:05 +00:00
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
err = snd_pcm_plugin_append(pb, params->channel, plugin);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plugin_free(plugin);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
1999-12-12 17:23:44 +00:00
|
|
|
srcparams->format.interleave = tmpparams.format.interleave;
|
1999-12-11 11:46:05 +00:00
|
|
|
}
|
1999-12-12 17:23:44 +00:00
|
|
|
pdprintf("newparams: interleave=%i, format=%i, rate=%i, voices=%i\n",
|
|
|
|
|
srcparams->format.interleave,
|
|
|
|
|
srcparams->format.format,
|
|
|
|
|
srcparams->format.rate,
|
|
|
|
|
srcparams->format.voices);
|
1999-12-11 21:20:03 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|