aboutsummaryrefslogtreecommitdiff
path: root/sound/core/oss/linear.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-16 10:13:38 -0700
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-16 10:13:38 -0700
commitfc8a327db6c46de783b1a4276d846841b9abc24c (patch)
treebee512c142cccea93511debd98ef954581693727 /sound/core/oss/linear.c
parent92d15c2ccbb3e31a3fc71ad28fdb55e1319383c0 (diff)
parent24837e6f249a2c83667552e6871c1543b4a6b934 (diff)
Merge branch 'linus' of master.kernel.org:/pub/scm/linux/kernel/git/perex/alsa
* 'linus' of master.kernel.org:/pub/scm/linux/kernel/git/perex/alsa: (264 commits) [ALSA] version 1.0.15 [ALSA] Fix thinko in cs4231 mce down check [ALSA] sun-cs4231: improved waiting after MCE down [ALSA] sun-cs4231: use cs4231-regs.h [ALSA] This simplifies and fixes waiting loops of the mce_down() [ALSA] This patch adds support for a wavetable chip on [ALSA] This patch removes open_mutex from the ad1848-lib as [ALSA] fix bootup crash in snd_gus_interrupt() [ALSA] hda-codec - Fix SKU ID function for realtek codecs [ALSA] Support ASUS P701 eeepc [0x1043 0x82a1] support [ALSA] hda-codec - Add array terminator for dmic in STAC codec [ALSA] hdsp - Fix zero division [ALSA] usb-audio - Fix double comment [ALSA] hda-codec - Fix STAC922x volume knob control [ALSA] Changed Jaroslav Kysela's e-mail from perex@suse.cz to perex@perex.cz [ALSA] hda-codec - Fix for Fujitsu Lifebook C1410 [ALSA] mpu-401: remove MPU401_INFO_UART_ONLY flag [ALSA] mpu-401: do not require an ACK byte for the ENTER_UART command [ALSA] via82xx - Add DXS quirk for Shuttle AK31v2 [ALSA] hda-codec - Fix input_mux numbers for vaio stac92xx ...
Diffstat (limited to 'sound/core/oss/linear.c')
-rw-r--r--sound/core/oss/linear.c91
1 files changed, 52 insertions, 39 deletions
diff --git a/sound/core/oss/linear.c b/sound/core/oss/linear.c
index 5b1bcdc64779..06f96a3e86f6 100644
--- a/sound/core/oss/linear.c
+++ b/sound/core/oss/linear.c
@@ -1,6 +1,6 @@
/*
* Linear conversion Plug-In
- * Copyright (c) 1999 by Jaroslav Kysela <perex@suse.cz>,
+ * Copyright (c) 1999 by Jaroslav Kysela <perex@perex.cz>,
* Abramo Bagnara <abramo@alsa-project.org>
*
*
@@ -21,9 +21,6 @@
*/
#include <sound/driver.h>
-
-#ifdef CONFIG_SND_PCM_OSS_PLUGINS
-
#include <linux/time.h>
#include <sound/core.h>
#include <sound/pcm.h>
@@ -34,19 +31,34 @@
*/
struct linear_priv {
- int conv;
+ int cvt_endian; /* need endian conversion? */
+ unsigned int src_ofs; /* byte offset in source format */
+ unsigned int dst_ofs; /* byte soffset in destination format */
+ unsigned int copy_ofs; /* byte offset in temporary u32 data */
+ unsigned int dst_bytes; /* byte size of destination format */
+ unsigned int copy_bytes; /* bytes to copy per conversion */
+ unsigned int flip; /* MSB flip for signeness, done after endian conv */
};
+static inline void do_convert(struct linear_priv *data,
+ unsigned char *dst, unsigned char *src)
+{
+ unsigned int tmp = 0;
+ unsigned char *p = (unsigned char *)&tmp;
+
+ memcpy(p + data->copy_ofs, src + data->src_ofs, data->copy_bytes);
+ if (data->cvt_endian)
+ tmp = swab32(tmp);
+ tmp ^= data->flip;
+ memcpy(dst, p + data->dst_ofs, data->dst_bytes);
+}
+
static void convert(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)
{
-#define CONV_LABELS
-#include "plugin_ops.h"
-#undef CONV_LABELS
struct linear_priv *data = (struct linear_priv *)plugin->extra_data;
- void *conv = conv_labels[data->conv];
int channel;
int nchannels = plugin->src_format.channels;
for (channel = 0; channel < nchannels; ++channel) {
@@ -67,11 +79,7 @@ static void convert(struct snd_pcm_plugin *plugin,
dst_step = dst_channels[channel].area.step / 8;
frames1 = frames;
while (frames1-- > 0) {
- goto *conv;
-#define CONV_END after
-#include "plugin_ops.h"
-#undef CONV_END
- after:
+ do_convert(data, dst, src);
src += src_step;
dst += dst_step;
}
@@ -106,29 +114,36 @@ static snd_pcm_sframes_t linear_transfer(struct snd_pcm_plugin *plugin,
return frames;
}
-static int conv_index(int src_format, int dst_format)
+static void init_data(struct linear_priv *data, int src_format, int dst_format)
{
- int src_endian, dst_endian, sign, src_width, dst_width;
-
- sign = (snd_pcm_format_signed(src_format) !=
- snd_pcm_format_signed(dst_format));
-#ifdef SNDRV_LITTLE_ENDIAN
- src_endian = snd_pcm_format_big_endian(src_format);
- dst_endian = snd_pcm_format_big_endian(dst_format);
-#else
- src_endian = snd_pcm_format_little_endian(src_format);
- dst_endian = snd_pcm_format_little_endian(dst_format);
-#endif
-
- if (src_endian < 0)
- src_endian = 0;
- if (dst_endian < 0)
- dst_endian = 0;
-
- src_width = snd_pcm_format_width(src_format) / 8 - 1;
- dst_width = snd_pcm_format_width(dst_format) / 8 - 1;
-
- return src_width * 32 + src_endian * 16 + sign * 8 + dst_width * 2 + dst_endian;
+ int src_le, dst_le, src_bytes, dst_bytes;
+
+ src_bytes = snd_pcm_format_width(src_format) / 8;
+ dst_bytes = snd_pcm_format_width(dst_format) / 8;
+ src_le = snd_pcm_format_little_endian(src_format) > 0;
+ dst_le = snd_pcm_format_little_endian(dst_format) > 0;
+
+ data->dst_bytes = dst_bytes;
+ data->cvt_endian = src_le != dst_le;
+ data->copy_bytes = src_bytes < dst_bytes ? src_bytes : dst_bytes;
+ if (src_le) {
+ data->copy_ofs = 4 - data->copy_bytes;
+ data->src_ofs = src_bytes - data->copy_bytes;
+ } else
+ data->src_ofs = snd_pcm_format_physical_width(src_format) / 8 -
+ src_bytes;
+ if (dst_le)
+ data->dst_ofs = 4 - data->dst_bytes;
+ else
+ data->dst_ofs = snd_pcm_format_physical_width(dst_format) / 8 -
+ dst_bytes;
+ if (snd_pcm_format_signed(src_format) !=
+ snd_pcm_format_signed(dst_format)) {
+ if (dst_le)
+ data->flip = cpu_to_le32(0x80000000);
+ else
+ data->flip = cpu_to_be32(0x80000000);
+ }
}
int snd_pcm_plugin_build_linear(struct snd_pcm_substream *plug,
@@ -154,10 +169,8 @@ int snd_pcm_plugin_build_linear(struct snd_pcm_substream *plug,
if (err < 0)
return err;
data = (struct linear_priv *)plugin->extra_data;
- data->conv = conv_index(src_format->format, dst_format->format);
+ init_data(data, src_format->format, dst_format->format);
plugin->transfer = linear_transfer;
*r_plugin = plugin;
return 0;
}
-
-#endif