summaryrefslogtreecommitdiff
path: root/sound/core/oss
diff options
context:
space:
mode:
Diffstat (limited to 'sound/core/oss')
-rw-r--r--sound/core/oss/copy.c5
-rw-r--r--sound/core/oss/io.c5
-rw-r--r--sound/core/oss/linear.c7
-rw-r--r--sound/core/oss/mixer_oss.c14
-rw-r--r--sound/core/oss/mulaw.c24
-rw-r--r--sound/core/oss/pcm_oss.c50
-rw-r--r--sound/core/oss/pcm_plugin.c272
-rw-r--r--sound/core/oss/pcm_plugin.h28
-rw-r--r--sound/core/oss/plugin_ops.h166
-rw-r--r--sound/core/oss/rate.c85
-rw-r--r--sound/core/oss/route.c489
11 files changed, 200 insertions, 945 deletions
diff --git a/sound/core/oss/copy.c b/sound/core/oss/copy.c
index d6a04c2d5a75..6658facc5cda 100644
--- a/sound/core/oss/copy.c
+++ b/sound/core/oss/copy.c
@@ -20,6 +20,9 @@
*/
#include <sound/driver.h>
+
+#ifdef CONFIG_SND_PCM_OSS_PLUGINS
+
#include <linux/time.h>
#include <sound/core.h>
#include <sound/pcm.h>
@@ -85,3 +88,5 @@ int snd_pcm_plugin_build_copy(struct snd_pcm_substream *plug,
*r_plugin = plugin;
return 0;
}
+
+#endif
diff --git a/sound/core/oss/io.c b/sound/core/oss/io.c
index 322702e05f3e..b6e7ce30e5a3 100644
--- a/sound/core/oss/io.c
+++ b/sound/core/oss/io.c
@@ -20,6 +20,9 @@
*/
#include <sound/driver.h>
+
+#ifdef CONFIG_SND_PCM_OSS_PLUGINS
+
#include <linux/time.h>
#include <sound/core.h>
#include <sound/pcm.h>
@@ -132,3 +135,5 @@ int snd_pcm_plugin_build_io(struct snd_pcm_substream *plug,
*r_plugin = plugin;
return 0;
}
+
+#endif
diff --git a/sound/core/oss/linear.c b/sound/core/oss/linear.c
index 8cbfa415ce40..5b1bcdc64779 100644
--- a/sound/core/oss/linear.c
+++ b/sound/core/oss/linear.c
@@ -21,6 +21,9 @@
*/
#include <sound/driver.h>
+
+#ifdef CONFIG_SND_PCM_OSS_PLUGINS
+
#include <linux/time.h>
#include <sound/core.h>
#include <sound/pcm.h>
@@ -103,7 +106,7 @@ static snd_pcm_sframes_t linear_transfer(struct snd_pcm_plugin *plugin,
return frames;
}
-int conv_index(int src_format, int dst_format)
+static int conv_index(int src_format, int dst_format)
{
int src_endian, dst_endian, sign, src_width, dst_width;
@@ -156,3 +159,5 @@ int snd_pcm_plugin_build_linear(struct snd_pcm_substream *plug,
*r_plugin = plugin;
return 0;
}
+
+#endif
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index f08e65a2bffe..9c68bc3f97aa 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -1095,7 +1095,7 @@ static void snd_mixer_oss_proc_read(struct snd_info_entry *entry,
struct snd_mixer_oss *mixer = entry->private_data;
int i;
- down(&mixer->reg_mutex);
+ mutex_lock(&mixer->reg_mutex);
for (i = 0; i < SNDRV_OSS_MAX_MIXERS; i++) {
struct slot *p;
@@ -1110,7 +1110,7 @@ static void snd_mixer_oss_proc_read(struct snd_info_entry *entry,
else
snd_iprintf(buffer, "\"\" 0\n");
}
- up(&mixer->reg_mutex);
+ mutex_unlock(&mixer->reg_mutex);
}
static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
@@ -1134,9 +1134,9 @@ static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
cptr = snd_info_get_str(str, cptr, sizeof(str));
if (! *str) {
/* remove the entry */
- down(&mixer->reg_mutex);
+ mutex_lock(&mixer->reg_mutex);
mixer_slot_clear(&mixer->slots[ch]);
- up(&mixer->reg_mutex);
+ mutex_unlock(&mixer->reg_mutex);
continue;
}
snd_info_get_str(idxstr, cptr, sizeof(idxstr));
@@ -1145,7 +1145,7 @@ static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
snd_printk(KERN_ERR "mixer_oss: invalid index %d\n", idx);
continue;
}
- down(&mixer->reg_mutex);
+ mutex_lock(&mixer->reg_mutex);
slot = (struct slot *)mixer->slots[ch].private_data;
if (slot && slot->assigned &&
slot->assigned->index == idx && ! strcmp(slot->assigned->name, str))
@@ -1168,7 +1168,7 @@ static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
kfree(tbl);
}
__unlock:
- up(&mixer->reg_mutex);
+ mutex_unlock(&mixer->reg_mutex);
}
}
@@ -1288,7 +1288,7 @@ static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd)
mixer = kcalloc(2, sizeof(*mixer), GFP_KERNEL);
if (mixer == NULL)
return -ENOMEM;
- init_MUTEX(&mixer->reg_mutex);
+ mutex_init(&mixer->reg_mutex);
sprintf(name, "mixer%i%i", card->number, 0);
if ((err = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER,
card, 0,
diff --git a/sound/core/oss/mulaw.c b/sound/core/oss/mulaw.c
index 14f5578ec7a7..2eb18807e6d0 100644
--- a/sound/core/oss/mulaw.c
+++ b/sound/core/oss/mulaw.c
@@ -22,6 +22,9 @@
*/
#include <sound/driver.h>
+
+#ifdef CONFIG_SND_PCM_OSS_PLUGINS
+
#include <linux/time.h>
#include <sound/core.h>
#include <sound/pcm.h>
@@ -262,6 +265,25 @@ static snd_pcm_sframes_t mulaw_transfer(struct snd_pcm_plugin *plugin,
return frames;
}
+static int getput_index(int format)
+{
+ int sign, width, endian;
+ sign = !snd_pcm_format_signed(format);
+ width = snd_pcm_format_width(format) / 8 - 1;
+ if (width < 0 || width > 3) {
+ snd_printk(KERN_ERR "snd-pcm-oss: invalid format %d\n", format);
+ width = 0;
+ }
+#ifdef SNDRV_LITTLE_ENDIAN
+ endian = snd_pcm_format_big_endian(format);
+#else
+ endian = snd_pcm_format_little_endian(format);
+#endif
+ if (endian < 0)
+ endian = 0;
+ return width * 4 + endian * 2 + sign;
+}
+
int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *plug,
struct snd_pcm_plugin_format *src_format,
struct snd_pcm_plugin_format *dst_format,
@@ -306,3 +328,5 @@ int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *plug,
*r_plugin = plugin;
return 0;
}
+
+#endif
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index 7fd072392c7e..f8302b703a30 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -78,6 +78,7 @@ static inline void snd_leave_user(mm_segment_t fs)
set_fs(fs);
}
+#ifdef CONFIG_SND_PCM_OSS_PLUGINS
static int snd_pcm_oss_plugin_clear(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
@@ -122,6 +123,7 @@ int snd_pcm_plugin_append(struct snd_pcm_plugin *plugin)
}
return 0;
}
+#endif /* CONFIG_SND_PCM_OSS_PLUGINS */
static long snd_pcm_oss_bytes(struct snd_pcm_substream *substream, long frames)
{
@@ -412,6 +414,7 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
oss_frame_size = snd_pcm_format_physical_width(params_format(params)) *
params_channels(params) / 8;
+#ifdef CONFIG_SND_PCM_OSS_PLUGINS
snd_pcm_oss_plugin_clear(substream);
if (!direct) {
/* add necessary plugins */
@@ -441,6 +444,7 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
}
}
}
+#endif
err = snd_pcm_oss_period_size(substream, params, sparams);
if (err < 0)
@@ -498,11 +502,13 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
runtime->oss.periods = params_periods(sparams);
oss_period_size = snd_pcm_plug_client_size(substream, params_period_size(sparams));
snd_assert(oss_period_size >= 0, err = -EINVAL; goto failure);
+#ifdef CONFIG_SND_PCM_OSS_PLUGINS
if (runtime->oss.plugin_first) {
err = snd_pcm_plug_alloc(substream, oss_period_size);
if (err < 0)
goto failure;
}
+#endif
oss_period_size *= oss_frame_size;
oss_buffer_size = oss_period_size * runtime->oss.periods;
@@ -784,6 +790,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
{
struct snd_pcm_runtime *runtime = substream->runtime;
snd_pcm_sframes_t frames, frames1;
+#ifdef CONFIG_SND_PCM_OSS_PLUGINS
if (runtime->oss.plugin_first) {
struct snd_pcm_plugin_channel *channels;
size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
@@ -800,7 +807,9 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
if (frames1 <= 0)
return frames1;
bytes = frames1 * oss_frame_bytes;
- } else {
+ } else
+#endif
+ {
frames = bytes_to_frames(runtime, bytes);
frames1 = snd_pcm_oss_write3(substream, buf, frames, in_kernel);
if (frames1 <= 0)
@@ -871,6 +880,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
{
struct snd_pcm_runtime *runtime = substream->runtime;
snd_pcm_sframes_t frames, frames1;
+#ifdef CONFIG_SND_PCM_OSS_PLUGINS
char __user *final_dst = (char __user *)buf;
if (runtime->oss.plugin_first) {
struct snd_pcm_plugin_channel *channels;
@@ -887,7 +897,9 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
bytes = frames1 * oss_frame_bytes;
if (!in_kernel && copy_to_user(final_dst, buf, bytes))
return -EFAULT;
- } else {
+ } else
+#endif
+ {
frames = bytes_to_frames(runtime, bytes);
frames1 = snd_pcm_oss_read3(substream, buf, frames, in_kernel);
if (frames1 <= 0)
@@ -1631,10 +1643,10 @@ static struct snd_pcm_oss_setup *snd_pcm_oss_look_for_setup(struct snd_pcm *pcm,
const char *ptr, *ptrl;
struct snd_pcm_oss_setup *setup;
- down(&pcm->streams[stream].oss.setup_mutex);
+ mutex_lock(&pcm->streams[stream].oss.setup_mutex);
for (setup = pcm->streams[stream].oss.setup_list; setup; setup = setup->next) {
if (!strcmp(setup->task_name, task_name)) {
- up(&pcm->streams[stream].oss.setup_mutex);
+ mutex_unlock(&pcm->streams[stream].oss.setup_mutex);
return setup;
}
}
@@ -1650,12 +1662,12 @@ static struct snd_pcm_oss_setup *snd_pcm_oss_look_for_setup(struct snd_pcm *pcm,
}
for (setup = pcm->streams[stream].oss.setup_list; setup; setup = setup->next) {
if (!strcmp(setup->task_name, ptrl)) {
- up(&pcm->streams[stream].oss.setup_mutex);
+ mutex_unlock(&pcm->streams[stream].oss.setup_mutex);
return setup;
}
}
__not_found:
- up(&pcm->streams[stream].oss.setup_mutex);
+ mutex_unlock(&pcm->streams[stream].oss.setup_mutex);
return NULL;
}
@@ -1692,7 +1704,9 @@ static void snd_pcm_oss_release_substream(struct snd_pcm_substream *substream)
struct snd_pcm_runtime *runtime;
runtime = substream->runtime;
vfree(runtime->oss.buffer);
+#ifdef CONFIG_SND_PCM_OSS_PLUGINS
snd_pcm_oss_plugin_clear(substream);
+#endif
substream->oss.file = NULL;
substream->oss.oss = 0;
}
@@ -1881,7 +1895,7 @@ static int snd_pcm_oss_open(struct inode *inode, struct file *file)
init_waitqueue_entry(&wait, current);
add_wait_queue(&pcm->open_wait, &wait);
- down(&pcm->open_mutex);
+ mutex_lock(&pcm->open_mutex);
while (1) {
err = snd_pcm_oss_open_file(file, pcm, &pcm_oss_file,
iminor(inode), psetup, csetup);
@@ -1895,16 +1909,16 @@ static int snd_pcm_oss_open(struct inode *inode, struct file *file)
} else
break;
set_current_state(TASK_INTERRUPTIBLE);
- up(&pcm->open_mutex);
+ mutex_unlock(&pcm->open_mutex);
schedule();
- down(&pcm->open_mutex);
+ mutex_lock(&pcm->open_mutex);
if (signal_pending(current)) {
err = -ERESTARTSYS;
break;
}
}
remove_wait_queue(&pcm->open_wait, &wait);
- up(&pcm->open_mutex);
+ mutex_unlock(&pcm->open_mutex);
if (err < 0)
goto __error;
return err;
@@ -1930,9 +1944,9 @@ static int snd_pcm_oss_release(struct inode *inode, struct file *file)
snd_assert(substream != NULL, return -ENXIO);
pcm = substream->pcm;
snd_pcm_oss_sync(pcm_oss_file);
- down(&pcm->open_mutex);
+ mutex_lock(&pcm->open_mutex);
snd_pcm_oss_release_file(pcm_oss_file);
- up(&pcm->open_mutex);
+ mutex_unlock(&pcm->open_mutex);
wake_up(&pcm->open_wait);
module_put(pcm->card->module);
snd_card_file_remove(pcm->card, file);
@@ -2246,8 +2260,10 @@ static int snd_pcm_oss_mmap(struct file *file, struct vm_area_struct *area)
if ((err = snd_pcm_oss_change_params(substream)) < 0)
return err;
}
+#ifdef CONFIG_SND_PCM_OSS_PLUGINS
if (runtime->oss.plugin_first != NULL)
return -EIO;
+#endif
if (area->vm_pgoff != 0)
return -EINVAL;
@@ -2277,7 +2293,7 @@ static void snd_pcm_oss_proc_read(struct snd_info_entry *entry,
{
struct snd_pcm_str *pstr = entry->private_data;
struct snd_pcm_oss_setup *setup = pstr->oss.setup_list;
- down(&pstr->oss.setup_mutex);
+ mutex_lock(&pstr->oss.setup_mutex);
while (setup) {
snd_iprintf(buffer, "%s %u %u%s%s%s%s%s%s\n",
setup->task_name,
@@ -2291,7 +2307,7 @@ static void snd_pcm_oss_proc_read(struct snd_info_entry *entry,
setup->nosilence ? " no-silence" : "");
setup = setup->next;
}
- up(&pstr->oss.setup_mutex);
+ mutex_unlock(&pstr->oss.setup_mutex);
}
static void snd_pcm_oss_proc_free_setup_list(struct snd_pcm_str * pstr)
@@ -2321,12 +2337,12 @@ static void snd_pcm_oss_proc_write(struct snd_info_entry *entry,
struct snd_pcm_oss_setup *setup, *setup1, template;
while (!snd_info_get_line(buffer, line, sizeof(line))) {
- down(&pstr->oss.setup_mutex);
+ mutex_lock(&pstr->oss.setup_mutex);
memset(&template, 0, sizeof(template));
ptr = snd_info_get_str(task_name, line, sizeof(task_name));
if (!strcmp(task_name, "clear") || !strcmp(task_name, "erase")) {
snd_pcm_oss_proc_free_setup_list(pstr);
- up(&pstr->oss.setup_mutex);
+ mutex_unlock(&pstr->oss.setup_mutex);
continue;
}
for (setup = pstr->oss.setup_list; setup; setup = setup->next) {
@@ -2378,7 +2394,7 @@ static void snd_pcm_oss_proc_write(struct snd_info_entry *entry,
}
if (setup)
*setup = template;
- up(&pstr->oss.setup_mutex);
+ mutex_unlock(&pstr->oss.setup_mutex);
}
}
diff --git a/sound/core/oss/pcm_plugin.c b/sound/core/oss/pcm_plugin.c
index 7e8676880dde..0e67dd280a5d 100644
--- a/sound/core/oss/pcm_plugin.c
+++ b/sound/core/oss/pcm_plugin.c
@@ -25,6 +25,9 @@
#endif
#include <sound/driver.h>
+
+#ifdef CONFIG_SND_PCM_OSS_PLUGINS
+
#include <linux/slab.h>
#include <linux/time.h>
#include <linux/vmalloc.h>
@@ -36,26 +39,6 @@
#define snd_pcm_plug_first(plug) ((plug)->runtime->oss.plugin_first)
#define snd_pcm_plug_last(plug) ((plug)->runtime->oss.plugin_last)
-static int snd_pcm_plugin_src_channels_mask(struct snd_pcm_plugin *plugin,
- unsigned long *dst_vmask,
- unsigned long **src_vmask)
-{
- unsigned long *vmask = plugin->src_vmask;
- bitmap_copy(vmask, dst_vmask, plugin->src_format.channels);
- *src_vmask = vmask;
- return 0;
-}
-
-static int snd_pcm_plugin_dst_channels_mask(struct snd_pcm_plugin *plugin,
- unsigned long *src_vmask,
- unsigned long **dst_vmask)
-{
- unsigned long *vmask = plugin->dst_vmask;
- bitmap_copy(vmask, src_vmask, plugin->dst_format.channels);
- *dst_vmask = vmask;
- return 0;
-}
-
/*
* because some cards might have rates "very close", we ignore
* all "resampling" requests within +-5%
@@ -193,19 +176,7 @@ int snd_pcm_plugin_build(struct snd_pcm_substream *plug,
snd_pcm_plugin_free(plugin);
return -ENOMEM;
}
- plugin->src_vmask = bitmap_alloc(src_format->channels);
- if (plugin->src_vmask == NULL) {
- snd_pcm_plugin_free(plugin);
- return -ENOMEM;
- }
- plugin->dst_vmask = bitmap_alloc(dst_format->channels);
- if (plugin->dst_vmask == NULL) {
- snd_pcm_plugin_free(plugin);
- return -ENOMEM;
- }
plugin->client_channels = snd_pcm_plugin_client_channels;
- plugin->src_channels_mask = snd_pcm_plugin_src_channels_mask;
- plugin->dst_channels_mask = snd_pcm_plugin_dst_channels_mask;
*ret = plugin;
return 0;
}
@@ -218,8 +189,6 @@ int snd_pcm_plugin_free(struct snd_pcm_plugin *plugin)
plugin->private_free(plugin);
kfree(plugin->buf_channels);
vfree(plugin->buf);
- kfree(plugin->src_vmask);
- kfree(plugin->dst_vmask);
kfree(plugin);
return 0;
}
@@ -429,24 +398,14 @@ int snd_pcm_plug_format_plugins(struct snd_pcm_substream *plug,
dstformat.channels);
/* Format change (linearization) */
- if ((srcformat.format != dstformat.format ||
- !rate_match(srcformat.rate, dstformat.rate) ||
- srcformat.channels != dstformat.channels) &&
- !snd_pcm_format_linear(srcformat.format)) {
- if (snd_pcm_format_linear(dstformat.format))
- tmpformat.format = dstformat.format;
- else
- tmpformat.format = SNDRV_PCM_FORMAT_S16;
- switch (srcformat.format) {
- case SNDRV_PCM_FORMAT_MU_LAW:
- err = snd_pcm_plugin_build_mulaw(plug,
- &srcformat, &tmpformat,
- &plugin);
- break;
- default:
+ if (! rate_match(srcformat.rate, dstformat.rate) &&
+ ! snd_pcm_format_linear(srcformat.format)) {
+ if (srcformat.format != SNDRV_PCM_FORMAT_MU_LAW)
return -EINVAL;
- }
- pdprintf("format change: src=%i, dst=%i returns %i\n", srcformat.format, tmpformat.format, err);
+ tmpformat.format = SNDRV_PCM_FORMAT_S16;
+ err = snd_pcm_plugin_build_mulaw(plug,
+ &srcformat, &tmpformat,
+ &plugin);
if (err < 0)
return err;
err = snd_pcm_plugin_append(plugin);
@@ -460,35 +419,11 @@ int snd_pcm_plug_format_plugins(struct snd_pcm_substream *plug,
/* channels reduction */
if (srcformat.channels > dstformat.channels) {
- int sv = srcformat.channels;
- int dv = dstformat.channels;
- int *ttable = kcalloc(dv * sv, sizeof(*ttable), GFP_KERNEL);
- if (ttable == NULL)
- return -ENOMEM;
-#if 1
- if (sv == 2 && dv == 1) {
- ttable[0] = HALF;
- ttable[1] = HALF;
- } else
-#endif
- {
- int v;
- for (v = 0; v < dv; ++v)
- ttable[v * sv + v] = FULL;
- }
tmpformat.channels = dstformat.channels;
- if (rate_match(srcformat.rate, dstformat.rate) &&
- snd_pcm_format_linear(dstformat.format))
- tmpformat.format = dstformat.format;
- err = snd_pcm_plugin_build_route(plug,
- &srcformat, &tmpformat,
- ttable, &plugin);
- kfree(ttable);
+ err = snd_pcm_plugin_build_route(plug, &srcformat, &tmpformat, &plugin);
pdprintf("channels reduction: src=%i, dst=%i returns %i\n", srcformat.channels, tmpformat.channels, err);
- if (err < 0) {
- snd_pcm_plugin_free(plugin);
+ if (err < 0)
return err;
- }
err = snd_pcm_plugin_append(plugin);
if (err < 0) {
snd_pcm_plugin_free(plugin);
@@ -500,18 +435,29 @@ int snd_pcm_plug_format_plugins(struct snd_pcm_substream *plug,
/* rate resampling */
if (!rate_match(srcformat.rate, dstformat.rate)) {
+ if (srcformat.format != SNDRV_PCM_FORMAT_S16) {
+ /* convert to S16 for resampling */
+ tmpformat.format = SNDRV_PCM_FORMAT_S16;
+ err = snd_pcm_plugin_build_linear(plug,
+ &srcformat, &tmpformat,
+ &plugin);
+ if (err < 0)
+ return err;
+ err = snd_pcm_plugin_append(plugin);
+ if (err < 0) {
+ snd_pcm_plugin_free(plugin);
+ return err;
+ }
+ srcformat = tmpformat;
+ src_access = dst_access;
+ }
tmpformat.rate = dstformat.rate;
- if (srcformat.channels == dstformat.channels &&
- snd_pcm_format_linear(dstformat.format))
- tmpformat.format = dstformat.format;
err = snd_pcm_plugin_build_rate(plug,
&srcformat, &tmpformat,
&plugin);
pdprintf("rate down resampling: src=%i, dst=%i returns %i\n", srcformat.rate, tmpformat.rate, err);
- if (err < 0) {
- snd_pcm_plugin_free(plugin);
+ if (err < 0)
return err;
- }
err = snd_pcm_plugin_append(plugin);
if (err < 0) {
snd_pcm_plugin_free(plugin);
@@ -521,56 +467,11 @@ int snd_pcm_plug_format_plugins(struct snd_pcm_substream *plug,
src_access = dst_access;
}
- /* channels extension */
- if (srcformat.channels < dstformat.channels) {
- int sv = srcformat.channels;
- int dv = dstformat.channels;
- int *ttable = kcalloc(dv * sv, sizeof(*ttable), GFP_KERNEL);
- if (ttable == NULL)
- return -ENOMEM;
-#if 0
- {
- int v;
- for (v = 0; v < sv; ++v)
- ttable[v * sv + v] = FULL;
- }
-#else
- {
- /* Playback is spreaded on all channels */
- int vd, vs;
- for (vd = 0, vs = 0; vd < dv; ++vd) {
- ttable[vd * sv + vs] = FULL;
- vs++;
- if (vs == sv)
- vs = 0;
- }
- }
-#endif
- tmpformat.channels = dstformat.channels;
- if (snd_pcm_format_linear(dstformat.format))
- tmpformat.format = dstformat.format;
- err = snd_pcm_plugin_build_route(plug,
- &srcformat, &tmpformat,
- ttable, &plugin);
- kfree(ttable);
- pdprintf("channels extension: src=%i, dst=%i returns %i\n", srcformat.channels, tmpformat.channels, err);
- if (err < 0) {
- snd_pcm_plugin_free(plugin);
- return err;
- }
- err = snd_pcm_plugin_append(plugin);
- if (err < 0) {
- snd_pcm_plugin_free(plugin);
- return err;
- }
- srcformat = tmpformat;
- src_access = dst_access;
- }
-
/* format change */
if (srcformat.format != dstformat.format) {
tmpformat.format = dstformat.format;
- if (tmpformat.format == SNDRV_PCM_FORMAT_MU_LAW) {
+ if (srcformat.format == SNDRV_PCM_FORMAT_MU_LAW ||
+ tmpformat.format == SNDRV_PCM_FORMAT_MU_LAW) {
err = snd_pcm_plugin_build_mulaw(plug,
&srcformat, &tmpformat,
&plugin);
@@ -595,6 +496,22 @@ int snd_pcm_plug_format_plugins(struct snd_pcm_substream *plug,
src_access = dst_access;
}
+ /* channels extension */
+ if (srcformat.channels < dstformat.channels) {
+ tmpformat.channels = dstformat.channels;
+ err = snd_pcm_plugin_build_route(plug, &srcformat, &tmpformat, &plugin);
+ pdprintf("channels extension: src=%i, dst=%i returns %i\n", srcformat.channels, tmpformat.channels, err);
+ if (err < 0)
+ return err;
+ err = snd_pcm_plugin_append(plugin);
+ if (err < 0) {
+ snd_pcm_plugin_free(plugin);
+ return err;
+ }
+ srcformat = tmpformat;
+ src_access = dst_access;
+ }
+
/* de-interleave */
if (src_access != dst_access) {
err = snd_pcm_plugin_build_copy(plug,
@@ -650,92 +567,6 @@ snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(struct snd_pcm_substream *plu
return count;
}
-static int snd_pcm_plug_playback_channels_mask(struct snd_pcm_substream *plug,
- unsigned long *client_vmask)
-{
- struct snd_pcm_plugin *plugin = snd_pcm_plug_last(plug);
- if (plugin == NULL) {
- return 0;
- } else {
- int schannels = plugin->dst_format.channels;
- DECLARE_BITMAP(bs, schannels);
- unsigned long *srcmask;
- unsigned long *dstmask = bs;
- int err;
- bitmap_fill(dstmask, schannels);
-
- while (1) {
- err = plugin->src_channels_mask(plugin, dstmask, &srcmask);
- if (err < 0)
- return err;
- dstmask = srcmask;
- if (plugin->prev == NULL)
- break;
- plugin = plugin->prev;
- }
- bitmap_and(client_vmask, client_vmask, dstmask, plugin->src_format.channels);
- return 0;
- }
-}
-
-static int snd_pcm_plug_playback_disable_useless_channels(struct snd_pcm_substream *plug,
- struct snd_pcm_plugin_channel *src_channels)
-{
- struct snd_pcm_plugin *plugin = snd_pcm_plug_first(plug);
- unsigned int nchannels = plugin->src_format.channels;
- DECLARE_BITMAP(bs, nchannels);
- unsigned long *srcmask = bs;
- int err;
- unsigned int channel;
- for (channel = 0; channel < nchannels; channel++) {
- if (src_channels[channel].enabled)
- set_bit(channel, srcmask);
- else
- clear_bit(channel, srcmask);
- }
- err = snd_pcm_plug_playback_channels_mask(plug, srcmask);
- if (err < 0)
- return err;
- for (channel = 0; channel < nchannels; channel++) {
- if (!test_bit(channel, srcmask))
- src_channels[channel].enabled = 0;
- }
- return 0;
-}
-
-static int snd_pcm_plug_capture_disable_useless_channels(struct snd_pcm_substream *plug,
- struct snd_pcm_plugin_channel *src_channels,
- struct snd_pcm_plugin_channel *client_channels)
-{
- struct snd_pcm_plugin *plugin = snd_pcm_plug_last(plug);
- unsigned int nchannels = plugin->dst_format.channels;
- DECLARE_BITMAP(bs, nchannels);
- unsigned long *dstmask = bs;
- unsigned long *srcmask;
- int err;
- unsigned int channel;
- for (channel = 0; channel < nchannels; channel++) {
- if (client_channels[channel].enabled)
- set_bit(channel, dstmask);
- else
- clear_bit(channel, dstmask);
- }
- while (plugin) {
- err = plugin->src_channels_mask(plugin, dstmask, &srcmask);
- if (err < 0)
- return err;
- dstmask = srcmask;
- plugin = plugin->prev;
- }
- plugin = snd_pcm_plug_first(plug);
- nchannels = plugin->src_format.channels;
- for (channel = 0; channel < nchannels; channel++) {
- if (!test_bit(channel, dstmask))
- src_channels[channel].enabled = 0;
- }
- return 0;
-}
-
snd_pcm_sframes_t snd_pcm_plug_write_transfer(struct snd_pcm_substream *plug, struct snd_pcm_plugin_channel *src_channels, snd_pcm_uframes_t size)
{
struct snd_pcm_plugin *plugin, *next;
@@ -743,9 +574,6 @@ snd_pcm_sframes_t snd_pcm_plug_write_transfer(struct snd_pcm_substream *plug, st
int err;
snd_pcm_sframes_t frames = size;
- if ((err = snd_pcm_plug_playback_disable_useless_channels(plug, src_channels)) < 0)
- return err;
-
plugin = snd_pcm_plug_first(plug);
while (plugin && frames > 0) {
if ((next = plugin->next) != NULL) {
@@ -790,10 +618,6 @@ snd_pcm_sframes_t snd_pcm_plug_read_transfer(struct snd_pcm_substream *plug, str
return err;
}
frames = err;
- if (!plugin->prev) {
- if ((err = snd_pcm_plug_capture_disable_useless_channels(plug, dst_channels, dst_channels_final)) < 0)
- return err;
- }
} else {
dst_channels = dst_channels_final;
}
@@ -916,3 +740,5 @@ int snd_pcm_area_copy(const struct snd_pcm_channel_area *src_area, size_t src_of
}
return 0;
}
+
+#endif
diff --git a/sound/core/oss/pcm_plugin.h b/sound/core/oss/pcm_plugin.h
index 29198da615cd..3be91b3d5377 100644
--- a/sound/core/oss/pcm_plugin.h
+++ b/sound/core/oss/pcm_plugin.h
@@ -22,12 +22,7 @@
*
*/
-#include <linux/bitmap.h>
-
-static inline unsigned long *bitmap_alloc(unsigned int nbits)
-{
- return kmalloc(BITS_TO_LONGS(nbits), GFP_KERNEL);
-}
+#ifdef CONFIG_SND_PCM_OSS_PLUGINS
#define snd_pcm_plug_stream(plug) ((plug)->stream)
@@ -69,12 +64,6 @@ struct snd_pcm_plugin {
snd_pcm_sframes_t (*client_channels)(struct snd_pcm_plugin *plugin,
snd_pcm_uframes_t frames,
struct snd_pcm_plugin_channel **channels);
- int (*src_channels_mask)(struct snd_pcm_plugin *plugin,
- unsigned long *dst_vmask,
- unsigned long **src_vmask);
- int (*dst_channels_mask)(struct snd_pcm_plugin *plugin,
- unsigned long *src_vmask,
- unsigned long **dst_vmask);
snd_pcm_sframes_t (*transfer)(struct snd_pcm_plugin *plugin,
const struct snd_pcm_plugin_channel *src_channels,
struct snd_pcm_plugin_channel *dst_channels,
@@ -90,8 +79,6 @@ struct snd_pcm_plugin {
char *buf;
snd_pcm_uframes_t buf_frames;
struct snd_pcm_plugin_channel *buf_channels;
- unsigned long *src_vmask;
- unsigned long *dst_vmask;
char extra_data[0];
};
@@ -128,7 +115,6 @@ int snd_pcm_plugin_build_rate(struct snd_pcm_substream *handle,
int snd_pcm_plugin_build_route(struct snd_pcm_substream *handle,
struct snd_pcm_plugin_format *src_format,
struct snd_pcm_plugin_format *dst_format,
- int *ttable,
struct snd_pcm_plugin **r_plugin);
int snd_pcm_plugin_build_copy(struct snd_pcm_substream *handle,
struct snd_pcm_plugin_format *src_format,
@@ -181,15 +167,13 @@ snd_pcm_sframes_t snd_pcm_oss_readv3(struct snd_pcm_substream *substream,
void **bufs, snd_pcm_uframes_t frames,
int in_kernel);
-#define ROUTE_PLUGIN_RESOLUTION 16
+#else
-int getput_index(int format);
-int copy_index(int format);
-int conv_index(int src_format, int dst_format);
+static inline snd_pcm_sframes_t snd_pcm_plug_client_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t drv_size) { return drv_size; }
+static inline snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t clt_size) { return clt_size; }
+static inline int snd_pcm_plug_slave_format(int format, struct snd_mask *format_mask) { return format; }
-void zero_channel(struct snd_pcm_plugin *plugin,
- const struct snd_pcm_plugin_channel *dst_channel,
- size_t samples);
+#endif
#ifdef PLUGIN_DEBUG
#define pdprintf( fmt, args... ) printk( "plugin: " fmt, ##args)
diff --git a/sound/core/oss/plugin_ops.h b/sound/core/oss/plugin_ops.h
index 0607e9566084..1f5bde4631f1 100644
--- a/sound/core/oss/plugin_ops.h
+++ b/sound/core/oss/plugin_ops.h
@@ -362,172 +362,6 @@ put_s16_xx12_0029: as_u32(dst) = (u_int32_t)swab16(sample) ^ 0x80; goto PUT_S16_
}
#endif
-#if 0
-#ifdef GET32_LABELS
-/* src_wid src_endswap unsigned */
-static void *get32_labels[4 * 2 * 2] = {
- &&get32_xxx1_1000, /* 8h -> 32h */
- &&get32_xxx1_9000, /* 8h ^> 32h */
- &&get32_xxx1_1000, /* 8s -> 32h */
- &&get32_xxx1_9000, /* 8s ^> 32h */
- &&get32_xx12_1200, /* 16h -> 32h */
- &&get32_xx12_9200, /* 16h ^> 32h */
- &&get32_xx12_2100, /* 16s -> 32h */
- &&get32_xx12_A100, /* 16s ^> 32h */
- &&get32_x123_1230, /* 24h -> 32h */
- &&get32_x123_9230, /* 24h ^> 32h */
- &&get32_123x_3210, /* 24s -> 32h */
- &&get32_123x_B210, /* 24s ^> 32h */
- &&get32_1234_1234, /* 32h -> 32h */
- &&get32_1234_9234, /* 32h ^> 32h */
- &&get32_1234_4321, /* 32s -> 32h */
- &&get32_1234_C321, /* 32s ^> 32h */
-};
-#endif
-
-#ifdef GET32_END
-while (0) {
-get32_xxx1_1000: sample = (u_int32_t)as_u8(src) << 24; goto GET32_END;
-get32_xxx1_9000: sample = (u_int32_t)(as_u8(src) ^ 0x80) << 24; goto GET32_END;
-get32_xx12_1200: sample = (u_int32_t)as_u16(src) << 16; goto GET32_END;
-get32_xx12_9200: sample = (u_int32_t)(as_u16(src) ^ 0x8000) << 16; goto GET32_END;
-get32_xx12_2100: sample = (u_int32_t)swab16(as_u16(src)) << 16; goto GET32_END;
-get32_xx12_A100: sample = (u_int32_t)swab16(as_u16(src) ^ 0x80) << 16; goto GET32_END;
-get32_x123_1230: sample = as_u32(src) << 8; goto GET32_END;
-get32_x123_9230: sample = (as_u32(src) << 8) ^ 0x80000000; goto GET32_END;
-get32_123x_3210: sample = swab32(as_u32(src) >> 8); goto GET32_END;
-get32_123x_B210: sample = swab32((as_u32(src) >> 8) ^ 0x80); goto GET32_END;
-get32_1234_1234: sample = as_u32(src); goto GET32_END;
-get32_1234_9234: sample = as_u32(src) ^ 0x80000000; goto GET32_END;
-get32_1234_4321: sample = swab32(as_u32(src)); goto GET32_END;
-get32_1234_C321: sample = swab32(as_u32(src) ^ 0x80); goto GET32_END;
-}
-#endif
-#endif
-
-#ifdef PUT_U32_LABELS
-/* dst_wid dst_endswap unsigned */
-static void *put_u32_labels[4 * 2 * 2] = {
- &&put_u32_1234_xxx9, /* u32h -> s8h */
- &&put_u32_1234_xxx1, /* u32h -> u8h */
- &&put_u32_1234_xxx9, /* u32h -> s8s */
- &&put_u32_1234_xxx1, /* u32h -> u8s */
- &&put_u32_1234_xx92, /* u32h -> s16h */
- &&put_u32_1234_xx12, /* u32h -> u16h */
- &&put_u32_1234_xx29, /* u32h -> s16s */
- &&put_u32_1234_xx21, /* u32h -> u16s */
- &&put_u32_1234_x923, /* u32h -> s24h */
- &&put_u32_1234_x123, /* u32h -> u24h */
- &&put_u32_1234_329x, /* u32h -> s24s */
- &&put_u32_1234_321x, /* u32h -> u24s */
- &&put_u32_1234_9234, /* u32h -> s32h */
- &&put_u32_1234_1234, /* u32h -> u32h */
- &&put_u32_1234_4329, /* u32h -> s32s */
- &&put_u32_1234_4321, /* u32h -> u32s */
-};
-#endif
-
-#ifdef PUT_U32_END
-while (0) {
-put_u32_1234_xxx1: as_u8(dst) = sample >> 24; goto PUT_U32_END;
-put_u32_1234_xxx9: as_u8(dst) = (sample >> 24) ^ 0x80; goto PUT_U32_END;
-put_u32_1234_xx12: as_u16(dst) = sample >> 16; goto PUT_U32_END;
-put_u32_1234_xx92: as_u16(dst) = (sample >> 16) ^ 0x8000; goto PUT_U32_END;
-put_u32_1234_xx21: as_u16(dst) = swab16(sample >> 16); goto PUT_U32_END;
-put_u32_1234_xx29: as_u16(dst) = swab16(sample >> 16) ^ 0x80; goto PUT_U32_END;
-put_u32_1234_x123: as_u32(dst) = sample >> 8; goto PUT_U32_END;
-put_u32_1234_x923: as_u32(dst) = (sample >> 8) ^ 0x800000; goto PUT_U32_END;
-put_u32_1234_321x: as_u32(dst) = swab32(sample) << 8; goto PUT_U32_END;
-put_u32_1234_329x: as_u32(dst) = (swab32(sample) ^ 0x80) << 8; goto PUT_U32_END;
-put_u32_1234_1234: as_u32(dst) = sample; goto PUT_U32_END;
-put_u32_1234_9234: as_u32(dst) = sample ^ 0x80000000; goto PUT_U32_END;
-put_u32_1234_4321: as_u32(dst) = swab32(sample); goto PUT_U32_END;
-put_u32_1234_4329: as_u32(dst) = swab32(sample) ^ 0x80; goto PUT_U32_END;
-}
-#endif
-
-#ifdef GET_U_LABELS
-/* width endswap unsigned*/
-static void *get_u_labels[4 * 2 * 2] = {
- &&get_u_s8, /* s8 -> u8 */
- &&get_u_u8, /* u8 -> u8 */
- &&get_u_s8, /* s8 -> u8 */
- &&get_u_u8, /* u8 -> u8 */
- &&get_u_s16h, /* s16h -> u16h */
- &&get_u_u16h, /* u16h -> u16h */
- &&get_u_s16s, /* s16s -> u16h */
- &&get_u_u16s, /* u16s -> u16h */
- &&get_u_s24h, /* s24h -> u32h */
- &&get_u_u24h, /* u24h -> u32h */
- &&get_u_s24s, /* s24s -> u32h */
- &&get_u_u24s, /* u24s -> u32h */
- &&get_u_s32h, /* s32h -> u32h */
- &&get_u_u32h, /* u32h -> u32h */
- &&get_u_s32s, /* s32s -> u32h */
- &&get_u_u32s, /* u32s -> u32h */
-};
-#endif
-
-#ifdef GET_U_END
-while (0) {
-get_u_s8: sample = as_u8(src) ^ 0x80; goto GET_U_END;
-get_u_u8: sample = as_u8(src); goto GET_U_END;
-get_u_s16h: sample = as_u16(src) ^ 0x8000; goto GET_U_END;
-get_u_u16h: sample = as_u16(src); goto GET_U_END;
-get_u_s16s: sample = swab16(as_u16(src) ^ 0x80); goto GET_U_END;
-get_u_u16s: sample = swab16(as_u16(src)); goto GET_U_END;
-get_u_s24h: sample = (as_u32(src) ^ 0x800000); goto GET_U_END;
-get_u_u24h: sample = as_u32(src); goto GET_U_END;
-get_u_s24s: sample = swab32(as_u32(src) ^ 0x800000); goto GET_U_END;
-get_u_u24s: sample = swab32(as_u32(src)); goto GET_U_END;
-get_u_s32h: sample = as_u32(src) ^ 0x80000000; goto GET_U_END;
-get_u_u32h: sample = as_u32(src); goto GET_U_END;
-get_u_s32s: sample = swab32(as_u32(src) ^ 0x80); goto GET_U_END;
-get_u_u32s: sample = swab32(as_u32(src)); goto GET_U_END;
-}
-#endif
-
-#if 0
-#ifdef PUT_LABELS
-/* width endswap unsigned */
-static void *put_labels[4 * 2 * 2] = {
- &&put_s8, /* s8 -> s8 */
- &&put_u8, /* u8 -> s8 */
- &&put_s8, /* s8 -> s8 */
- &&put_u8, /* u8 -> s8 */
- &&put_s16h, /* s16h -> s16h */
- &&put_u16h, /* u16h -> s16h */
- &&put_s16s, /* s16s -> s16h */
- &&put_u16s, /* u16s -> s16h */
- &&put_s24h, /* s24h -> s32h */
- &&put_u24h, /* u24h -> s32h */
- &&put_s24s, /* s24s -> s32h */
- &&put_u24s, /* u24s -> s32h */
- &&put_s32h, /* s32h -> s32h */
- &&put_u32h, /* u32h -> s32h */
- &&put_s32s, /* s32s -> s32h */
- &&put_u32s, /* u32s -> s32h */
-};
-#endif
-
-#ifdef PUT_END
-put_s8: as_s8(dst) = sample; goto PUT_END;
-put_u8: as_u8(dst) = sample ^ 0x80; goto PUT_END;
-put_s16h: as_s16(dst) = sample; goto PUT_END;
-put_u16h: as_u16(dst) = sample ^ 0x8000; goto PUT_END;
-put_s16s: as_s16(dst) = swab16(sample); goto PUT_END;
-put_u16s: as_u16(dst) = swab16(sample ^ 0x80); goto PUT_END;
-put_s24h: as_s24(dst) = sample & 0xffffff; goto PUT_END;
-put_u24h: as_u24(dst) = sample ^ 0x80000000; goto PUT_END;
-put_s24s: as_s24(dst) = swab32(sample & 0xffffff); goto PUT_END;
-put_u24s: as_u24(dst) = swab32(sample ^ 0x80); goto PUT_END;
-put_s32h: as_s32(dst) = sample; goto PUT_END;
-put_u32h: as_u32(dst) = sample ^ 0x80000000; goto PUT_END;
-put_s32s: as_s32(dst) = swab32(sample); goto PUT_END;
-put_u32s: as_u32(dst) = swab32(sample ^ 0x80); goto PUT_END;
-#endif
-#endif
-
#undef as_u8
#undef as_u16
#undef as_u32
diff --git a/sound/core/oss/rate.c b/sound/core/oss/rate.c
index 4854cef6fb4f..18d8a0f4e816 100644
--- a/sound/core/oss/rate.c
+++ b/sound/core/oss/rate.c
@@ -20,6 +20,9 @@
*/
#include <sound/driver.h>
+
+#ifdef CONFIG_SND_PCM_OSS_PLUGINS
+
#include <linux/time.h>
#include <sound/core.h>
#include <sound/pcm.h>
@@ -47,7 +50,6 @@ struct rate_priv {
unsigned int pitch;
unsigned int pos;
rate_f func;
- int get, put;
snd_pcm_sframes_t old_src_frames, old_dst_frames;
struct rate_channel channels[0];
};
@@ -71,21 +73,12 @@ static void resample_expand(struct snd_pcm_plugin *plugin,
unsigned int pos = 0;
signed int val;
signed short S1, S2;
- char *src, *dst;
+ signed short *src, *dst;
unsigned int channel;
int src_step, dst_step;
int src_frames1, dst_frames1;
struct rate_priv *data = (struct rate_priv *)plugin->extra_data;
struct rate_channel *rchannels = data->channels;
-
-#define GET_S16_LABELS
-#define PUT_S16_LABELS
-#include "plugin_ops.h"
-#undef GET_S16_LABELS
-#undef PUT_S16_LABELS
- void *get = get_s16_labels[data->get];
- void *put = put_s16_labels[data->put];
- signed short sample = 0;
for (channel = 0; channel < plugin->src_format.channels; channel++) {
pos = data->pos;
@@ -98,10 +91,12 @@ static void resample_expand(struct snd_pcm_plugin *plugin,
continue;
}
dst_channels[channel].enabled = 1;
- src = (char *)src_channels[channel].area.addr + src_channels[channel].area.first / 8;
- dst = (char *)dst_channels[channel].area.addr + dst_channels[channel].area.first / 8;
- src_step = src_channels[channel].area.step / 8;
- dst_step = dst_channels[channel].area.step / 8;
+ src = (signed short *)src_channels[channel].area.addr +
+ src_channels[channel].area.first / 8 / 2;
+ dst = (signed short *)dst_channels[channel].area.addr +
+ dst_channels[channel].area.first / 8 / 2;
+ src_step = src_channels[channel].area.step / 8 / 2;
+ dst_step = dst_channels[channel].area.step / 8 / 2;
src_frames1 = src_frames;
dst_frames1 = dst_frames;
while (dst_frames1-- > 0) {
@@ -109,12 +104,7 @@ static void resample_expand(struct snd_pcm_plugin *plugin,
pos &= R_MASK;
S1 = S2;
if (src_frames1-- > 0) {
- goto *get;
-#define GET_S16_END after_get
-#include "plugin_ops.h"
-#undef GET_S16_END
- after_get:
- S2 = sample;
+ S2 = *src;
src += src_step;
}
}
@@ -123,12 +113,7 @@ static void resample_expand(struct snd_pcm_plugin *plugin,
val = -32768;
else if (val > 32767)
val = 32767;
- sample = val;
- goto *put;
-#define PUT_S16_END after_put
-#include "plugin_ops.h"
-#undef PUT_S16_END
- after_put:
+ *dst = val;
dst += dst_step;
pos += data->pitch;
}
@@ -147,21 +132,12 @@ static void resample_shrink(struct snd_pcm_plugin *plugin,
unsigned int pos = 0;
signed int val;
signed short S1, S2;
- char *src, *dst;
+ signed short *src, *dst;
unsigned int channel;
int src_step, dst_step;
int src_frames1, dst_frames1;
struct rate_priv *data = (struct rate_priv *)plugin->extra_data;
struct rate_channel *rchannels = data->channels;
-
-#define GET_S16_LABELS
-#define PUT_S16_LABELS
-#include "plugin_ops.h"
-#undef GET_S16_LABELS
-#undef PUT_S16_LABELS
- void *get = get_s16_labels[data->get];
- void *put = put_s16_labels[data->put];
- signed short sample = 0;
for (channel = 0; channel < plugin->src_format.channels; ++channel) {
pos = data->pos;
@@ -174,21 +150,18 @@ static void resample_shrink(struct snd_pcm_plugin *plugin,
continue;
}
dst_channels[channel].enabled = 1;
- src = (char *)src_channels[channel].area.addr + src_channels[channel].area.first / 8;
- dst = (char *)dst_channels[channel].area.addr + dst_channels[channel].area.first / 8;
- src_step = src_channels[channel].area.step / 8;
- dst_step = dst_channels[channel].area.step / 8;
+ src = (signed short *)src_channels[channel].area.addr +
+ src_channels[channel].area.first / 8 / 2;
+ dst = (signed short *)dst_channels[channel].area.addr +
+ dst_channels[channel].area.first / 8 / 2;
+ src_step = src_channels[channel].area.step / 8 / 2;
+ dst_step = dst_channels[channel].area.step / 8 / 2;
src_frames1 = src_frames;
dst_frames1 = dst_frames;
while (dst_frames1 > 0) {
S1 = S2;
if (src_frames1-- > 0) {
- goto *get;
-#define GET_S16_END after_get
-#include "plugin_ops.h"
-#undef GET_S16_END
- after_get:
- S2 = sample;
+ S1 = *src;
src += src_step;
}
if (pos & ~R_MASK) {
@@ -198,12 +171,7 @@ static void resample_shrink(struct snd_pcm_plugin *plugin,
val = -32768;
else if (val > 32767)
val = 32767;
- sample = val;
- goto *put;
-#define PUT_S16_END after_put
-#include "plugin_ops.h"
-#undef PUT_S16_END
- after_put:
+ *dst = val;
dst += dst_step;
dst_frames1--;
}
@@ -343,8 +311,8 @@ int snd_pcm_plugin_build_rate(struct snd_pcm_substream *plug,
snd_assert(src_format->channels == dst_format->channels, return -ENXIO);
snd_assert(src_format->channels > 0, return -ENXIO);
- snd_assert(snd_pcm_format_linear(src_format->format) != 0, return -ENXIO);
- snd_assert(snd_pcm_format_linear(dst_format->format) != 0, return -ENXIO);
+ snd_assert(src_format->format == SNDRV_PCM_FORMAT_S16, return -ENXIO);
+ snd_assert(dst_format->format == SNDRV_PCM_FORMAT_S16, return -ENXIO);
snd_assert(src_format->rate != dst_format->rate, return -ENXIO);
err = snd_pcm_plugin_build(plug, "rate conversion",
@@ -355,11 +323,6 @@ int snd_pcm_plugin_build_rate(struct snd_pcm_substream *plug,
if (err < 0)
return err;
data = (struct rate_priv *)plugin->extra_data;
- data->get = getput_index(src_format->format);
- snd_assert(data->get >= 0 && data->get < 4*2*2, return -EINVAL);
- data->put = getput_index(dst_format->format);
- snd_assert(data->put >= 0 && data->put < 4*2*2, return -EINVAL);
-
if (src_format->rate < dst_format->rate) {
data->pitch = ((src_format->rate << SHIFT) + (dst_format->rate >> 1)) / dst_format->rate;
data->func = resample_expand;
@@ -377,3 +340,5 @@ int snd_pcm_plugin_build_rate(struct snd_pcm_substream *plug,
*r_plugin = plugin;
return 0;
}
+
+#endif
diff --git a/sound/core/oss/route.c b/sound/core/oss/route.c
index 726c5caa3fdb..46917dc0196b 100644
--- a/sound/core/oss/route.c
+++ b/sound/core/oss/route.c
@@ -1,5 +1,5 @@
/*
- * Attenuated route Plug-In
+ * Route Plug-In
* Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
*
*
@@ -20,502 +20,93 @@
*/
#include <sound/driver.h>
+
+#ifdef CONFIG_SND_PCM_OSS_PLUGINS
+
#include <linux/slab.h>
#include <linux/time.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include "pcm_plugin.h"
-/* The best possible hack to support missing optimization in gcc 2.7.2.3 */
-#if ROUTE_PLUGIN_RESOLUTION & (ROUTE_PLUGIN_RESOLUTION - 1) != 0
-#define div(a) a /= ROUTE_PLUGIN_RESOLUTION
-#elif ROUTE_PLUGIN_RESOLUTION == 16
-#define div(a) a >>= 4
-#else
-#error "Add some code here"
-#endif
-
-struct ttable_dst;
-
-typedef void (*route_channel_f)(struct snd_pcm_plugin *plugin,
- const struct snd_pcm_plugin_channel *src_channels,
- struct snd_pcm_plugin_channel *dst_channel,
- struct ttable_dst *ttable, snd_pcm_uframes_t frames);
-
-struct ttable_src {
- int channel;
- int as_int;
-};
-
-struct ttable_dst {
- int att; /* Attenuated */
- unsigned int nsrcs;
- struct ttable_src *srcs;
- route_channel_f func;
-};
-
-struct route_priv {
- enum {R_UINT32=0, R_UINT64=1} sum_type;
- int get, put;
- int conv;
- int src_sample_size;
- struct ttable_dst ttable[0];
-};
-
-union sum {
- u_int32_t as_uint32;
- u_int64_t as_uint64;
-};
-
-
-static void route_to_channel_from_zero(struct snd_pcm_plugin *plugin,
- const struct snd_pcm_plugin_channel *src_channels,
- struct snd_pcm_plugin_channel *dst_channel,
- struct ttable_dst *ttable,
- snd_pcm_uframes_t frames)
-{
- if (dst_channel->wanted)
- snd_pcm_area_silence(&dst_channel->area, 0, frames, plugin->dst_format.format);
- dst_channel->enabled = 0;
-}
-
-static void route_to_channel_from_one(struct snd_pcm_plugin *plugin,
- const struct snd_pcm_plugin_channel *src_channels,
- struct snd_pcm_plugin_channel *dst_channel,
- struct ttable_dst *ttable,
- snd_pcm_uframes_t frames)
+static void zero_areas(struct snd_pcm_plugin_channel *dvp, int ndsts,
+ snd_pcm_uframes_t frames, int format)
{
-#define CONV_LABELS
-#include "plugin_ops.h"
-#undef CONV_LABELS
- struct route_priv *data = (struct route_priv *)plugin->extra_data;
- void *conv;
- const struct snd_pcm_plugin_channel *src_channel = NULL;
- unsigned int srcidx;
- char *src, *dst;
- int src_step, dst_step;
- for (srcidx = 0; srcidx < ttable->nsrcs; ++srcidx) {
- src_channel = &src_channels[ttable->srcs[srcidx].channel];
- if (src_channel->area.addr != NULL)
- break;
- }
- if (srcidx == ttable->nsrcs) {
- route_to_channel_from_zero(plugin, src_channels, dst_channel, ttable, frames);
- return;
- }
-
- dst_channel->enabled = 1;
- conv = conv_labels[data->conv];
- src = src_channel->area.addr + src_channel->area.first / 8;
- src_step = src_channel->area.step / 8;
- dst = dst_channel->area.addr + dst_channel->area.first / 8;
- dst_step = dst_channel->area.step / 8;
- while (frames-- > 0) {
- goto *conv;
-#define CONV_END after
-#include "plugin_ops.h"
-#undef CONV_END
- after:
- src += src_step;
- dst += dst_step;
+ int dst = 0;
+ for (; dst < ndsts; ++dst) {
+ if (dvp->wanted)
+ snd_pcm_area_silence(&dvp->area, 0, frames, format);
+ dvp->enabled = 0;
+ dvp++;
}
}
-static void route_to_channel(struct snd_pcm_plugin *plugin,
- const struct snd_pcm_plugin_channel *src_channels,
+static inline void copy_area(const struct snd_pcm_plugin_channel *src_channel,
struct snd_pcm_plugin_channel *dst_channel,
- struct ttable_dst *ttable, snd_pcm_uframes_t frames)
+ snd_pcm_uframes_t frames, int format)
{
-#define GET_U_LABELS
-#define PUT_U32_LABELS
-#include "plugin_ops.h"
-#undef GET_U_LABELS
-#undef PUT_U32_LABELS
- static void *zero_labels[2] = { &&zero_int32, &&zero_int64 };
- /* sum_type att */
- static void *add_labels[2 * 2] = { &&add_int32_noatt, &&add_int32_att,
- &&add_int64_noatt, &&add_int64_att,
- };
- /* sum_type att shift */
- static void *norm_labels[2 * 2 * 4] = { NULL,
- &&norm_int32_8_noatt,
- &&norm_int32_16_noatt,
- &&norm_int32_24_noatt,
- NULL,
- &&norm_int32_8_att,
- &&norm_int32_16_att,
- &&norm_int32_24_att,
- &&norm_int64_0_noatt,
- &&norm_int64_8_noatt,
- &&norm_int64_16_noatt,
- &&norm_int64_24_noatt,
- &&norm_int64_0_att,
- &&norm_int64_8_att,
- &&norm_int64_16_att,
- &&norm_int64_24_att,
- };
- struct route_priv *data = (struct route_priv *)plugin->extra_data;
- void *zero, *get, *add, *norm, *put_u32;
- int nsrcs = ttable->nsrcs;
- char *dst;
- int dst_step;
- char *srcs[nsrcs];
- int src_steps[nsrcs];
- struct ttable_src src_tt[nsrcs];
- u_int32_t sample = 0;
- int srcidx, srcidx1 = 0;
- for (srcidx = 0; srcidx < nsrcs; ++srcidx) {
- const struct snd_pcm_plugin_channel *src_channel = &src_channels[ttable->srcs[srcidx].channel];
- if (!src_channel->enabled)
- continue;
- srcs[srcidx1] = src_channel->area.addr + src_channel->area.first / 8;
- src_steps[srcidx1] = src_channel->area.step / 8;
- src_tt[srcidx1] = ttable->srcs[srcidx];
- srcidx1++;
- }
- nsrcs = srcidx1;
- if (nsrcs == 0) {
- route_to_channel_from_zero(plugin, src_channels, dst_channel, ttable, frames);
- return;
- } else if (nsrcs == 1 && src_tt[0].as_int == ROUTE_PLUGIN_RESOLUTION) {
- route_to_channel_from_one(plugin, src_channels, dst_channel, ttable, frames);
- return;
- }
-
dst_channel->enabled = 1;
- zero = zero_labels[data->sum_type];
- get = get_u_labels[data->get];
- add = add_labels[data->sum_type * 2 + ttable->att];
- norm = norm_labels[data->sum_type * 8 + ttable->att * 4 + 4 - data->src_sample_size];
- put_u32 = put_u32_labels[data->put];
- dst = dst_channel->area.addr + dst_channel->area.first / 8;
- dst_step = dst_channel->area.step / 8;
-
- while (frames-- > 0) {
- struct ttable_src *ttp = src_tt;
- union sum sum;
-
- /* Zero sum */
- goto *zero;
- zero_int32:
- sum.as_uint32 = 0;
- goto zero_end;
- zero_int64:
- sum.as_uint64 = 0;
- goto zero_end;
- zero_end:
- for (srcidx = 0; srcidx < nsrcs; ++srcidx) {
- char *src = srcs[srcidx];
-
- /* Get sample */
- goto *get;
-#define GET_U_END after_get
-#include "plugin_ops.h"
-#undef GET_U_END
- after_get:
-
- /* Sum */
- goto *add;
- add_int32_att:
- sum.as_uint32 += sample * ttp->as_int;
- goto after_sum;
- add_int32_noatt:
- if (ttp->as_int)
- sum.as_uint32 += sample;
- goto after_sum;
- add_int64_att:
- sum.as_uint64 += (u_int64_t) sample * ttp->as_int;
- goto after_sum;
- add_int64_noatt:
- if (ttp->as_int)
- sum.as_uint64 += sample;
- goto after_sum;
- after_sum:
- srcs[srcidx] += src_steps[srcidx];
- ttp++;
- }
-
- /* Normalization */
- goto *norm;
- norm_int32_8_att:
- sum.as_uint64 = sum.as_uint32;
- norm_int64_8_att:
- sum.as_uint64 <<= 8;
- norm_int64_0_att:
- div(sum.as_uint64);
- goto norm_int;
-
- norm_int32_16_att:
- sum.as_uint64 = sum.as_uint32;
- norm_int64_16_att:
- sum.as_uint64 <<= 16;
- div(sum.as_uint64);
- goto norm_int;
-
- norm_int32_24_att:
- sum.as_uint64 = sum.as_uint32;
- norm_int64_24_att:
- sum.as_uint64 <<= 24;
- div(sum.as_uint64);
- goto norm_int;
-
- norm_int32_8_noatt:
- sum.as_uint64 = sum.as_uint32;
- norm_int64_8_noatt:
- sum.as_uint64 <<= 8;
- goto norm_int;
-
- norm_int32_16_noatt:
- sum.as_uint64 = sum.as_uint32;
- norm_int64_16_noatt:
- sum.as_uint64 <<= 16;
- goto norm_int;
-
- norm_int32_24_noatt:
- sum.as_uint64 = sum.as_uint32;
- norm_int64_24_noatt:
- sum.as_uint64 <<= 24;
- goto norm_int;
-
- norm_int64_0_noatt:
- norm_int:
- if (sum.as_uint64 > (u_int32_t)0xffffffff)
- sample = (u_int32_t)0xffffffff;
- else
- sample = sum.as_uint64;
- goto after_norm;
-
- after_norm:
-
- /* Put sample */
- goto *put_u32;
-#define PUT_U32_END after_put_u32
-#include "plugin_ops.h"
-#undef PUT_U32_END
- after_put_u32:
-
- dst += dst_step;
- }
-}
-
-static int route_src_channels_mask(struct snd_pcm_plugin *plugin,
- unsigned long *dst_vmask,
- unsigned long **src_vmask)
-{
- struct route_priv *data = (struct route_priv *)plugin->extra_data;
- int schannels = plugin->src_format.channels;
- int dchannels = plugin->dst_format.channels;
- unsigned long *vmask = plugin->src_vmask;
- int channel;
- struct ttable_dst *dp = data->ttable;
- bitmap_zero(vmask, schannels);
- for (channel = 0; channel < dchannels; channel++, dp++) {
- unsigned int src;
- struct ttable_src *sp;
- if (!test_bit(channel, dst_vmask))
- continue;
- sp = dp->srcs;
- for (src = 0; src < dp->nsrcs; src++, sp++)
- set_bit(sp->channel, vmask);
- }
- *src_vmask = vmask;
- return 0;
-}
-
-static int route_dst_channels_mask(struct snd_pcm_plugin *plugin,
- unsigned long *src_vmask,
- unsigned long **dst_vmask)
-{
- struct route_priv *data = (struct route_priv *)plugin->extra_data;
- int dchannels = plugin->dst_format.channels;
- unsigned long *vmask = plugin->dst_vmask;
- int channel;
- struct ttable_dst *dp = data->ttable;
- bitmap_zero(vmask, dchannels);
- for (channel = 0; channel < dchannels; channel++, dp++) {
- unsigned int src;
- struct ttable_src *sp;
- sp = dp->srcs;
- for (src = 0; src < dp->nsrcs; src++, sp++) {
- if (test_bit(sp->channel, src_vmask)) {
- set_bit(channel, vmask);
- break;
- }
- }
- }
- *dst_vmask = vmask;
- return 0;
-}
-
-static void route_free(struct snd_pcm_plugin *plugin)
-{
- struct route_priv *data = (struct route_priv *)plugin->extra_data;
- unsigned int dst_channel;
- for (dst_channel = 0; dst_channel < plugin->dst_format.channels; ++dst_channel) {
- kfree(data->ttable[dst_channel].srcs);
- }
-}
-
-static int route_load_ttable(struct snd_pcm_plugin *plugin,
- const int *src_ttable)
-{
- struct route_priv *data;
- unsigned int src_channel, dst_channel;
- const int *sptr;
- struct ttable_dst *dptr;
- if (src_ttable == NULL)
- return 0;
- data = (struct route_priv *)plugin->extra_data;
- dptr = data->ttable;
- sptr = src_ttable;
- plugin->private_free = route_free;
- for (dst_channel = 0; dst_channel < plugin->dst_format.channels; ++dst_channel) {
- int t = 0;
- int att = 0;
- int nsrcs = 0;
- struct ttable_src srcs[plugin->src_format.channels];
- for (src_channel = 0; src_channel < plugin->src_format.channels; ++src_channel) {
- snd_assert(*sptr >= 0 || *sptr <= FULL, return -ENXIO);
- if (*sptr != 0) {
- srcs[nsrcs].channel = src_channel;
- srcs[nsrcs].as_int = *sptr;
- if (*sptr != FULL)
- att = 1;
- t += *sptr;
- nsrcs++;
- }
- sptr++;
- }
- dptr->att = att;
- dptr->nsrcs = nsrcs;
- if (nsrcs == 0)
- dptr->func = route_to_channel_from_zero;
- else if (nsrcs == 1 && !att)
- dptr->func = route_to_channel_from_one;
- else
- dptr->func = route_to_channel;
- if (nsrcs > 0) {
- int srcidx;
- dptr->srcs = kcalloc(nsrcs, sizeof(*srcs), GFP_KERNEL);
- for(srcidx = 0; srcidx < nsrcs; srcidx++)
- dptr->srcs[srcidx] = srcs[srcidx];
- } else
- dptr->srcs = NULL;
- dptr++;
- }
- return 0;
+ snd_pcm_area_copy(&src_channel->area, 0, &dst_channel->area, 0, frames, format);
}
static snd_pcm_sframes_t route_transfer(struct snd_pcm_plugin *plugin,
- const struct snd_pcm_plugin_channel *src_channels,
- struct snd_pcm_plugin_channel *dst_channels,
- snd_pcm_uframes_t frames)
+ const struct snd_pcm_plugin_channel *src_channels,
+ struct snd_pcm_plugin_channel *dst_channels,
+ snd_pcm_uframes_t frames)
{
- struct route_priv *data;
- int src_nchannels, dst_nchannels;
- int dst_channel;
- struct ttable_dst *ttp;
+ int nsrcs, ndsts, dst;
struct snd_pcm_plugin_channel *dvp;
+ int format;
snd_assert(plugin != NULL && src_channels != NULL && dst_channels != NULL, return -ENXIO);
if (frames == 0)
return 0;
- data = (struct route_priv *)plugin->extra_data;
- src_nchannels = plugin->src_format.channels;
- dst_nchannels = plugin->dst_format.channels;
+ nsrcs = plugin->src_format.channels;
+ ndsts = plugin->dst_format.channels;
-#ifdef CONFIG_SND_DEBUG
- {
- int src_channel;
- for (src_channel = 0; src_channel < src_nchannels; ++src_channel) {
- snd_assert(src_channels[src_channel].area.first % 8 == 0 ||
- src_channels[src_channel].area.step % 8 == 0,
- return -ENXIO);
- }
- for (dst_channel = 0; dst_channel < dst_nchannels; ++dst_channel) {
- snd_assert(dst_channels[dst_channel].area.first % 8 == 0 ||
- dst_channels[dst_channel].area.step % 8 == 0,
- return -ENXIO);
+ format = plugin->dst_format.format;
+ dvp = dst_channels;
+ if (nsrcs <= 1) {
+ /* expand to all channels */
+ for (dst = 0; dst < ndsts; ++dst) {
+ copy_area(src_channels, dvp, frames, format);
+ dvp++;
}
+ return frames;
}
-#endif
- ttp = data->ttable;
- dvp = dst_channels;
- for (dst_channel = 0; dst_channel < dst_nchannels; ++dst_channel) {
- ttp->func(plugin, src_channels, dvp, ttp, frames);
+ for (dst = 0; dst < ndsts && dst < nsrcs; ++dst) {
+ copy_area(src_channels, dvp, frames, format);
dvp++;
- ttp++;
+ src_channels++;
}
+ if (dst < ndsts)
+ zero_areas(dvp, ndsts - dst, frames, format);
return frames;
}
-int getput_index(int format)
-{
- int sign, width, endian;
- sign = !snd_pcm_format_signed(format);
- width = snd_pcm_format_width(format) / 8 - 1;
- if (width < 0 || width > 3) {
- snd_printk(KERN_ERR "snd-pcm-oss: invalid format %d\n", format);
- width = 0;
- }
-#ifdef SNDRV_LITTLE_ENDIAN
- endian = snd_pcm_format_big_endian(format);
-#else
- endian = snd_pcm_format_little_endian(format);
-#endif
- if (endian < 0)
- endian = 0;
- return width * 4 + endian * 2 + sign;
-}
-
int snd_pcm_plugin_build_route(struct snd_pcm_substream *plug,
struct snd_pcm_plugin_format *src_format,
struct snd_pcm_plugin_format *dst_format,
- int *ttable,
struct snd_pcm_plugin **r_plugin)
{
- struct route_priv *data;
struct snd_pcm_plugin *plugin;
int err;
snd_assert(r_plugin != NULL, return -ENXIO);
*r_plugin = NULL;
snd_assert(src_format->rate == dst_format->rate, return -ENXIO);
- snd_assert(snd_pcm_format_linear(src_format->format) != 0 &&
- snd_pcm_format_linear(dst_format->format) != 0,
- return -ENXIO);
+ snd_assert(src_format->format == dst_format->format, return -ENXIO);
- err = snd_pcm_plugin_build(plug, "attenuated route conversion",
- src_format, dst_format,
- sizeof(struct route_priv) +
- sizeof(data->ttable[0]) * dst_format->channels,
- &plugin);
+ err = snd_pcm_plugin_build(plug, "route conversion",
+ src_format, dst_format, 0, &plugin);
if (err < 0)
return err;
- data = (struct route_priv *)plugin->extra_data;
-
- data->get = getput_index(src_format->format);
- snd_assert(data->get >= 0 && data->get < 4*2*2, return -EINVAL);
- data->put = getput_index(dst_format->format);
- snd_assert(data->get >= 0 && data->get < 4*2*2, return -EINVAL);
- data->conv = conv_index(src_format->format, dst_format->format);
-
- if (snd_pcm_format_width(src_format->format) == 32)
- data->sum_type = R_UINT64;
- else
- data->sum_type = R_UINT32;
- data->src_sample_size = snd_pcm_format_width(src_format->format) / 8;
-
- if ((err = route_load_ttable(plugin, ttable)) < 0) {
- snd_pcm_plugin_free(plugin);
- return err;
- }
plugin->transfer = route_transfer;
- plugin->src_channels_mask = route_src_channels_mask;
- plugin->dst_channels_mask = route_dst_channels_mask;
*r_plugin = plugin;
return 0;
}
+
+#endif