From 0534ab4279bd25e2d0a888af07466446dac05d74 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 13 Jan 2006 12:09:12 +0100 Subject: [ALSA] Clean up pcm-oss plugins Modules: ALSA<-OSS emulation Clean up pcm-oss plugin codes. Removed dead codes, and simplified route/rate plugins. Signed-off-by: Takashi Iwai --- sound/core/oss/linear.c | 2 +- sound/core/oss/mulaw.c | 19 ++ sound/core/oss/pcm_plugin.c | 264 ++++-------------------- sound/core/oss/pcm_plugin.h | 26 --- sound/core/oss/plugin_ops.h | 166 --------------- sound/core/oss/rate.c | 80 ++------ sound/core/oss/route.c | 484 ++++---------------------------------------- 7 files changed, 117 insertions(+), 924 deletions(-) (limited to 'sound/core') diff --git a/sound/core/oss/linear.c b/sound/core/oss/linear.c index ef331230b3a6..5b1bcdc64779 100644 --- a/sound/core/oss/linear.c +++ b/sound/core/oss/linear.c @@ -106,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; diff --git a/sound/core/oss/mulaw.c b/sound/core/oss/mulaw.c index ed12c81fcf1b..2eb18807e6d0 100644 --- a/sound/core/oss/mulaw.c +++ b/sound/core/oss/mulaw.c @@ -265,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, diff --git a/sound/core/oss/pcm_plugin.c b/sound/core/oss/pcm_plugin.c index 89bc8f965043..cec2774425ec 100644 --- a/sound/core/oss/pcm_plugin.c +++ b/sound/core/oss/pcm_plugin.c @@ -39,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% @@ -196,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; } @@ -221,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; } @@ -432,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); @@ -463,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); @@ -503,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); @@ -524,52 +467,6 @@ 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; @@ -598,6 +495,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, @@ -653,92 +566,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; @@ -746,9 +573,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) { @@ -793,10 +617,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; } diff --git a/sound/core/oss/pcm_plugin.h b/sound/core/oss/pcm_plugin.h index a8a4f9580435..3be91b3d5377 100644 --- a/sound/core/oss/pcm_plugin.h +++ b/sound/core/oss/pcm_plugin.h @@ -24,13 +24,6 @@ #ifdef CONFIG_SND_PCM_OSS_PLUGINS -#include - -static inline unsigned long *bitmap_alloc(unsigned int nbits) -{ - return kmalloc(BITS_TO_LONGS(nbits), GFP_KERNEL); -} - #define snd_pcm_plug_stream(plug) ((plug)->stream) enum snd_pcm_plugin_action { @@ -71,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, @@ -92,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]; }; @@ -130,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, @@ -183,16 +167,6 @@ 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 - -int getput_index(int format); -int copy_index(int format); -int conv_index(int src_format, int dst_format); - -void zero_channel(struct snd_pcm_plugin *plugin, - const struct snd_pcm_plugin_channel *dst_channel, - size_t samples); - #else 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; } 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 c4b75bff0ee5..18d8a0f4e816 100644 --- a/sound/core/oss/rate.c +++ b/sound/core/oss/rate.c @@ -50,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]; }; @@ -74,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; @@ -101,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) { @@ -112,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; } } @@ -126,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; } @@ -150,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; @@ -177,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) { @@ -201,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--; } @@ -346,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", @@ -358,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; diff --git a/sound/core/oss/route.c b/sound/core/oss/route.c index f99a54e6551a..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 * * @@ -29,496 +29,82 @@ #include #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) +static void zero_areas(struct snd_pcm_plugin_channel *dvp, int ndsts, + snd_pcm_uframes_t frames, int format) { - 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) -{ -#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; } -- cgit v1.2.3-59-g8ed1b