linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / sound / core / oss / route.c
index fadc265..726c5ca 100644 (file)
 #error "Add some code here"
 #endif
 
-typedef struct ttable_dst ttable_dst_t;
-typedef struct route_private_data route_t;
+struct ttable_dst;
 
-typedef void (*route_channel_f)(snd_pcm_plugin_t *plugin,
-                             const snd_pcm_plugin_channel_t *src_channels,
-                             snd_pcm_plugin_channel_t *dst_channel,
-                             ttable_dst_t* ttable, snd_pcm_uframes_t frames);
+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);
 
-typedef struct {
+struct ttable_src {
        int channel;
        int as_int;
-#if ROUTE_PLUGIN_USE_FLOAT
-       float as_float;
-#endif
-} ttable_src_t;
+};
 
 struct ttable_dst {
        int att;        /* Attenuated */
        unsigned int nsrcs;
-       ttable_src_t* srcs;
+       struct ttable_src *srcs;
        route_channel_f func;
 };
 
-struct route_private_data {
-       enum {R_UINT32=0, R_UINT64=1, R_FLOAT=2} sum_type;
+struct route_priv {
+       enum {R_UINT32=0, R_UINT64=1} sum_type;
        int get, put;
        int conv;
        int src_sample_size;
-       ttable_dst_t ttable[0];
+       struct ttable_dst ttable[0];
 };
 
-typedef union {
+union sum {
        u_int32_t as_uint32;
        u_int64_t as_uint64;
-#if ROUTE_PLUGIN_USE_FLOAT
-       float as_float;
-#endif
-} sum_t;
+};
 
 
-static void route_to_channel_from_zero(snd_pcm_plugin_t *plugin,
-                                    const snd_pcm_plugin_channel_t *src_channels ATTRIBUTE_UNUSED,
-                                    snd_pcm_plugin_channel_t *dst_channel,
-                                    ttable_dst_t* ttable ATTRIBUTE_UNUSED, snd_pcm_uframes_t frames)
+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(snd_pcm_plugin_t *plugin,
-                                   const snd_pcm_plugin_channel_t *src_channels,
-                                   snd_pcm_plugin_channel_t *dst_channel,
-                                   ttable_dst_t* ttable, snd_pcm_uframes_t frames)
+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
-       route_t *data = (route_t *)plugin->extra_data;
+       struct route_priv *data = (struct route_priv *)plugin->extra_data;
        void *conv;
-       const snd_pcm_plugin_channel_t *src_channel = 0;
+       const struct snd_pcm_plugin_channel *src_channel = NULL;
        unsigned int srcidx;
        char *src, *dst;
        int src_step, dst_step;
@@ -126,34 +121,27 @@ static void route_to_channel_from_one(snd_pcm_plugin_t *plugin,
        }
 }
 
-static void route_to_channel(snd_pcm_plugin_t *plugin,
-                          const snd_pcm_plugin_channel_t *src_channels,
-                          snd_pcm_plugin_channel_t *dst_channel,
-                          ttable_dst_t* ttable, snd_pcm_uframes_t frames)
+static void route_to_channel(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 GET_U_LABELS
 #define PUT_U32_LABELS
 #include "plugin_ops.h"
 #undef GET_U_LABELS
 #undef PUT_U32_LABELS
-       static void *zero_labels[3] = { &&zero_int32, &&zero_int64,
-#if ROUTE_PLUGIN_USE_FLOAT
-                                &&zero_float
-#endif
-       };
+       static void *zero_labels[2] = { &&zero_int32, &&zero_int64 };
        /* sum_type att */
-       static void *add_labels[3 * 2] = { &&add_int32_noatt, &&add_int32_att,
+       static void *add_labels[2 * 2] = { &&add_int32_noatt, &&add_int32_att,
                                    &&add_int64_noatt, &&add_int64_att,
-#if ROUTE_PLUGIN_USE_FLOAT
-                                   &&add_float_noatt, &&add_float_att
-#endif
        };
        /* sum_type att shift */
-       static void *norm_labels[3 * 2 * 4] = { 0,
+       static void *norm_labels[2 * 2 * 4] = { NULL,
                                         &&norm_int32_8_noatt,
                                         &&norm_int32_16_noatt,
                                         &&norm_int32_24_noatt,
-                                        0,
+                                        NULL,
                                         &&norm_int32_8_att,
                                         &&norm_int32_16_att,
                                         &&norm_int32_24_att,
@@ -165,29 +153,19 @@ static void route_to_channel(snd_pcm_plugin_t *plugin,
                                         &&norm_int64_8_att,
                                         &&norm_int64_16_att,
                                         &&norm_int64_24_att,
-#if ROUTE_PLUGIN_USE_FLOAT
-                                        &&norm_float_0,
-                                        &&norm_float_8,
-                                        &&norm_float_16,
-                                        &&norm_float_24,
-                                        &&norm_float_0,
-                                        &&norm_float_8,
-                                        &&norm_float_16,
-                                        &&norm_float_24,
-#endif
        };
-       route_t *data = (route_t *)plugin->extra_data;
+       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];
-       ttable_src_t src_tt[nsrcs];
+       struct ttable_src src_tt[nsrcs];
        u_int32_t sample = 0;
        int srcidx, srcidx1 = 0;
        for (srcidx = 0; srcidx < nsrcs; ++srcidx) {
-               const snd_pcm_plugin_channel_t *src_channel = &src_channels[ttable->srcs[srcidx].channel];
+               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;
@@ -214,8 +192,8 @@ static void route_to_channel(snd_pcm_plugin_t *plugin,
        dst_step = dst_channel->area.step / 8;
 
        while (frames-- > 0) {
-               ttable_src_t *ttp = src_tt;
-               sum_t sum;
+               struct ttable_src *ttp = src_tt;
+               union sum sum;
 
                /* Zero sum */
                goto *zero;
@@ -225,11 +203,6 @@ static void route_to_channel(snd_pcm_plugin_t *plugin,
        zero_int64: 
                sum.as_uint64 = 0;
                goto zero_end;
-#if ROUTE_PLUGIN_USE_FLOAT
-       zero_float:
-               sum.as_float = 0.0;
-               goto zero_end;
-#endif
        zero_end:
                for (srcidx = 0; srcidx < nsrcs; ++srcidx) {
                        char *src = srcs[srcidx];
@@ -257,15 +230,6 @@ static void route_to_channel(snd_pcm_plugin_t *plugin,
                        if (ttp->as_int)
                                sum.as_uint64 += sample;
                        goto after_sum;
-#if ROUTE_PLUGIN_USE_FLOAT
-               add_float_att:
-                       sum.as_float += sample * ttp->as_float;
-                       goto after_sum;
-               add_float_noatt:
-                       if (ttp->as_int)
-                               sum.as_float += sample;
-                       goto after_sum;
-#endif
                after_sum:
                        srcs[srcidx] += src_steps[srcidx];
                        ttp++;
@@ -321,25 +285,6 @@ static void route_to_channel(snd_pcm_plugin_t *plugin,
                        sample = sum.as_uint64;
                goto after_norm;
 
-#if ROUTE_PLUGIN_USE_FLOAT
-       norm_float_8:
-               sum.as_float *= 1 << 8;
-               goto norm_float;
-       norm_float_16:
-               sum.as_float *= 1 << 16;
-               goto norm_float;
-       norm_float_24:
-               sum.as_float *= 1 << 24;
-               goto norm_float;
-       norm_float_0:
-       norm_float:
-               sum.as_float = floor(sum.as_float + 0.5);
-               if (sum.as_float > (u_int32_t)0xffffffff)
-                       sample = (u_int32_t)0xffffffff;
-               else
-                       sample = sum.as_float;
-               goto after_norm;
-#endif
        after_norm:
                
                /* Put sample */
@@ -353,47 +298,47 @@ static void route_to_channel(snd_pcm_plugin_t *plugin,
        }
 }
 
-int route_src_channels_mask(snd_pcm_plugin_t *plugin,
-                         bitset_t *dst_vmask,
-                         bitset_t **src_vmask)
+static int route_src_channels_mask(struct snd_pcm_plugin *plugin,
+                                  unsigned long *dst_vmask,
+                                  unsigned long **src_vmask)
 {
-       route_t *data = (route_t *)plugin->extra_data;
+       struct route_priv *data = (struct route_priv *)plugin->extra_data;
        int schannels = plugin->src_format.channels;
        int dchannels = plugin->dst_format.channels;
-       bitset_t *vmask = plugin->src_vmask;
+       unsigned long *vmask = plugin->src_vmask;
        int channel;
-       ttable_dst_t *dp = data->ttable;
-       bitset_zero(vmask, schannels);
+       struct ttable_dst *dp = data->ttable;
+       bitmap_zero(vmask, schannels);
        for (channel = 0; channel < dchannels; channel++, dp++) {
                unsigned int src;
-               ttable_src_t *sp;
-               if (!bitset_get(dst_vmask, channel))
+               struct ttable_src *sp;
+               if (!test_bit(channel, dst_vmask))
                        continue;
                sp = dp->srcs;
                for (src = 0; src < dp->nsrcs; src++, sp++)
-                       bitset_set(vmask, sp->channel);
+                       set_bit(sp->channel, vmask);
        }
        *src_vmask = vmask;
        return 0;
 }
 
-int route_dst_channels_mask(snd_pcm_plugin_t *plugin,
-                         bitset_t *src_vmask,
-                         bitset_t **dst_vmask)
+static int route_dst_channels_mask(struct snd_pcm_plugin *plugin,
+                                  unsigned long *src_vmask,
+                                  unsigned long **dst_vmask)
 {
-       route_t *data = (route_t *)plugin->extra_data;
+       struct route_priv *data = (struct route_priv *)plugin->extra_data;
        int dchannels = plugin->dst_format.channels;
-       bitset_t *vmask = plugin->dst_vmask;
+       unsigned long *vmask = plugin->dst_vmask;
        int channel;
-       ttable_dst_t *dp = data->ttable;
-       bitset_zero(vmask, dchannels);
+       struct ttable_dst *dp = data->ttable;
+       bitmap_zero(vmask, dchannels);
        for (channel = 0; channel < dchannels; channel++, dp++) {
                unsigned int src;
-               ttable_src_t *sp;
+               struct ttable_src *sp;
                sp = dp->srcs;
                for (src = 0; src < dp->nsrcs; src++, sp++) {
-                       if (bitset_get(src_vmask, sp->channel)) {
-                               bitset_set(vmask, channel);
+                       if (test_bit(sp->channel, src_vmask)) {
+                               set_bit(channel, vmask);
                                break;
                        }
                }
@@ -402,45 +347,38 @@ int route_dst_channels_mask(snd_pcm_plugin_t *plugin,
        return 0;
 }
 
-static void route_free(snd_pcm_plugin_t *plugin)
+static void route_free(struct snd_pcm_plugin *plugin)
 {
-       route_t *data = (route_t *)plugin->extra_data;
+       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) {
-               if (data->ttable[dst_channel].srcs != NULL)
-                       kfree(data->ttable[dst_channel].srcs);
+               kfree(data->ttable[dst_channel].srcs);
        }
 }
 
-static int route_load_ttable(snd_pcm_plugin_t *plugin, 
-                            const route_ttable_entry_t* src_ttable)
+static int route_load_ttable(struct snd_pcm_plugin *plugin, 
+                            const int *src_ttable)
 {
-       route_t *data;
+       struct route_priv *data;
        unsigned int src_channel, dst_channel;
-       const route_ttable_entry_t *sptr;
-       ttable_dst_t *dptr;
+       const int *sptr;
+       struct ttable_dst *dptr;
        if (src_ttable == NULL)
                return 0;
-       data = (route_t *)plugin->extra_data;
+       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) {
-               route_ttable_entry_t t = 0;
+               int t = 0;
                int att = 0;
                int nsrcs = 0;
-               ttable_src_t srcs[plugin->src_format.channels];
+               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;
-#if ROUTE_PLUGIN_USE_FLOAT
-                               /* Also in user space for non attenuated */
-                               srcs[nsrcs].as_int = (*sptr == FULL ? ROUTE_PLUGIN_RESOLUTION : 0);
-                               srcs[nsrcs].as_float = *sptr;
-#else
                                srcs[nsrcs].as_int = *sptr;
-#endif
                                if (*sptr != FULL)
                                        att = 1;
                                t += *sptr;
@@ -458,31 +396,31 @@ static int route_load_ttable(snd_pcm_plugin_t *plugin,
                        dptr->func = route_to_channel;
                if (nsrcs > 0) {
                         int srcidx;
-                       dptr->srcs = snd_kcalloc(nsrcs * sizeof(*srcs), GFP_KERNEL);
+                       dptr->srcs = kcalloc(nsrcs, sizeof(*srcs), GFP_KERNEL);
                         for(srcidx = 0; srcidx < nsrcs; srcidx++)
                                dptr->srcs[srcidx] = srcs[srcidx];
                } else
-                       dptr->srcs = 0;
+                       dptr->srcs = NULL;
                dptr++;
        }
        return 0;
 }
 
-static snd_pcm_sframes_t route_transfer(snd_pcm_plugin_t *plugin,
-                             const snd_pcm_plugin_channel_t *src_channels,
-                             snd_pcm_plugin_channel_t *dst_channels,
+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)
 {
-       route_t *data;
+       struct route_priv *data;
        int src_nchannels, dst_nchannels;
        int dst_channel;
-       ttable_dst_t *ttp;
-       snd_pcm_plugin_channel_t *dvp;
+       struct ttable_dst *ttp;
+       struct snd_pcm_plugin_channel *dvp;
 
        snd_assert(plugin != NULL && src_channels != NULL && dst_channels != NULL, return -ENXIO);
        if (frames == 0)
                return 0;
-       data = (route_t *)plugin->extra_data;
+       data = (struct route_priv *)plugin->extra_data;
 
        src_nchannels = plugin->src_format.channels;
        dst_nchannels = plugin->dst_format.channels;
@@ -532,14 +470,14 @@ int getput_index(int format)
        return width * 4 + endian * 2 + sign;
 }
 
-int snd_pcm_plugin_build_route(snd_pcm_plug_t *plug,
-                              snd_pcm_plugin_format_t *src_format,
-                              snd_pcm_plugin_format_t *dst_format,
-                              route_ttable_entry_t *ttable,
-                              snd_pcm_plugin_t **r_plugin)
+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)
 {
-       route_t *data;
-       snd_pcm_plugin_t *plugin;
+       struct route_priv *data;
+       struct snd_pcm_plugin *plugin;
        int err;
 
        snd_assert(r_plugin != NULL, return -ENXIO);
@@ -551,25 +489,24 @@ int snd_pcm_plugin_build_route(snd_pcm_plug_t *plug,
 
        err = snd_pcm_plugin_build(plug, "attenuated route conversion",
                                   src_format, dst_format,
-                                  sizeof(route_t) + sizeof(data->ttable[0]) * dst_format->channels,
+                                  sizeof(struct route_priv) +
+                                  sizeof(data->ttable[0]) * dst_format->channels,
                                   &plugin);
        if (err < 0)
                return err;
 
-       data = (route_t *) plugin->extra_data;
+       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 ROUTE_PLUGIN_USE_FLOAT
-       data->sum_type = R_FLOAT;
-#else
        if (snd_pcm_format_width(src_format->format) == 32)
                data->sum_type = R_UINT64;
        else
                data->sum_type = R_UINT32;
-#endif
        data->src_sample_size = snd_pcm_format_width(src_format->format) / 8;
 
        if ((err = route_load_ttable(plugin, ttable)) < 0) {