aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2005-11-17 04:18:00 -0500
committerJaroslav Kysela <perex@suse.cz>2006-01-03 06:16:33 -0500
commit47eaebfd31610d2a55fbaccd1e7c37690d42ce30 (patch)
treed86d90a3741e09cf660aef3dda96566ff68778eb /sound/core
parent230b5c1a612ae903c560b55a15df287b0ff437ea (diff)
[ALSA] Use standard bitmap functions
Modules: ALSA<-OSS emulation Use standard bitmap functions instead of in-house ones. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core')
-rw-r--r--sound/core/oss/io.c4
-rw-r--r--sound/core/oss/pcm_plugin.c54
-rw-r--r--sound/core/oss/pcm_plugin.h78
-rw-r--r--sound/core/oss/rate.c2
-rw-r--r--sound/core/oss/route.c28
5 files changed, 53 insertions, 113 deletions
diff --git a/sound/core/oss/io.c b/sound/core/oss/io.c
index bb1c99a5b734..63eca9aec961 100644
--- a/sound/core/oss/io.c
+++ b/sound/core/oss/io.c
@@ -37,7 +37,7 @@
37 37
38static snd_pcm_sframes_t io_playback_transfer(snd_pcm_plugin_t *plugin, 38static snd_pcm_sframes_t io_playback_transfer(snd_pcm_plugin_t *plugin,
39 const snd_pcm_plugin_channel_t *src_channels, 39 const snd_pcm_plugin_channel_t *src_channels,
40 snd_pcm_plugin_channel_t *dst_channels ATTRIBUTE_UNUSED, 40 snd_pcm_plugin_channel_t *dst_channels,
41 snd_pcm_uframes_t frames) 41 snd_pcm_uframes_t frames)
42{ 42{
43 snd_assert(plugin != NULL, return -ENXIO); 43 snd_assert(plugin != NULL, return -ENXIO);
@@ -59,7 +59,7 @@ static snd_pcm_sframes_t io_playback_transfer(snd_pcm_plugin_t *plugin,
59} 59}
60 60
61static snd_pcm_sframes_t io_capture_transfer(snd_pcm_plugin_t *plugin, 61static snd_pcm_sframes_t io_capture_transfer(snd_pcm_plugin_t *plugin,
62 const snd_pcm_plugin_channel_t *src_channels ATTRIBUTE_UNUSED, 62 const snd_pcm_plugin_channel_t *src_channels,
63 snd_pcm_plugin_channel_t *dst_channels, 63 snd_pcm_plugin_channel_t *dst_channels,
64 snd_pcm_uframes_t frames) 64 snd_pcm_uframes_t frames)
65{ 65{
diff --git a/sound/core/oss/pcm_plugin.c b/sound/core/oss/pcm_plugin.c
index fc23373c000d..312ae1f2bfc3 100644
--- a/sound/core/oss/pcm_plugin.c
+++ b/sound/core/oss/pcm_plugin.c
@@ -37,21 +37,21 @@
37#define snd_pcm_plug_last(plug) ((plug)->runtime->oss.plugin_last) 37#define snd_pcm_plug_last(plug) ((plug)->runtime->oss.plugin_last)
38 38
39static int snd_pcm_plugin_src_channels_mask(snd_pcm_plugin_t *plugin, 39static int snd_pcm_plugin_src_channels_mask(snd_pcm_plugin_t *plugin,
40 bitset_t *dst_vmask, 40 unsigned long *dst_vmask,
41 bitset_t **src_vmask) 41 unsigned long **src_vmask)
42{ 42{
43 bitset_t *vmask = plugin->src_vmask; 43 unsigned long *vmask = plugin->src_vmask;
44 bitset_copy(vmask, dst_vmask, plugin->src_format.channels); 44 bitmap_copy(vmask, dst_vmask, plugin->src_format.channels);
45 *src_vmask = vmask; 45 *src_vmask = vmask;
46 return 0; 46 return 0;
47} 47}
48 48
49static int snd_pcm_plugin_dst_channels_mask(snd_pcm_plugin_t *plugin, 49static int snd_pcm_plugin_dst_channels_mask(snd_pcm_plugin_t *plugin,
50 bitset_t *src_vmask, 50 unsigned long *src_vmask,
51 bitset_t **dst_vmask) 51 unsigned long **dst_vmask)
52{ 52{
53 bitset_t *vmask = plugin->dst_vmask; 53 unsigned long *vmask = plugin->dst_vmask;
54 bitset_copy(vmask, src_vmask, plugin->dst_format.channels); 54 bitmap_copy(vmask, src_vmask, plugin->dst_format.channels);
55 *dst_vmask = vmask; 55 *dst_vmask = vmask;
56 return 0; 56 return 0;
57} 57}
@@ -193,12 +193,12 @@ int snd_pcm_plugin_build(snd_pcm_plug_t *plug,
193 snd_pcm_plugin_free(plugin); 193 snd_pcm_plugin_free(plugin);
194 return -ENOMEM; 194 return -ENOMEM;
195 } 195 }
196 plugin->src_vmask = bitset_alloc(src_format->channels); 196 plugin->src_vmask = bitmap_alloc(src_format->channels);
197 if (plugin->src_vmask == NULL) { 197 if (plugin->src_vmask == NULL) {
198 snd_pcm_plugin_free(plugin); 198 snd_pcm_plugin_free(plugin);
199 return -ENOMEM; 199 return -ENOMEM;
200 } 200 }
201 plugin->dst_vmask = bitset_alloc(dst_format->channels); 201 plugin->dst_vmask = bitmap_alloc(dst_format->channels);
202 if (plugin->dst_vmask == NULL) { 202 if (plugin->dst_vmask == NULL) {
203 snd_pcm_plugin_free(plugin); 203 snd_pcm_plugin_free(plugin);
204 return -ENOMEM; 204 return -ENOMEM;
@@ -651,18 +651,18 @@ snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(snd_pcm_plug_t *plug,
651} 651}
652 652
653static int snd_pcm_plug_playback_channels_mask(snd_pcm_plug_t *plug, 653static int snd_pcm_plug_playback_channels_mask(snd_pcm_plug_t *plug,
654 bitset_t *client_vmask) 654 unsigned long *client_vmask)
655{ 655{
656 snd_pcm_plugin_t *plugin = snd_pcm_plug_last(plug); 656 snd_pcm_plugin_t *plugin = snd_pcm_plug_last(plug);
657 if (plugin == NULL) { 657 if (plugin == NULL) {
658 return 0; 658 return 0;
659 } else { 659 } else {
660 int schannels = plugin->dst_format.channels; 660 int schannels = plugin->dst_format.channels;
661 bitset_t bs[bitset_size(schannels)]; 661 DECLARE_BITMAP(bs, schannels);
662 bitset_t *srcmask; 662 unsigned long *srcmask;
663 bitset_t *dstmask = bs; 663 unsigned long *dstmask = bs;
664 int err; 664 int err;
665 bitset_one(dstmask, schannels); 665 bitmap_fill(dstmask, schannels);
666 666
667 while (1) { 667 while (1) {
668 err = plugin->src_channels_mask(plugin, dstmask, &srcmask); 668 err = plugin->src_channels_mask(plugin, dstmask, &srcmask);
@@ -673,7 +673,7 @@ static int snd_pcm_plug_playback_channels_mask(snd_pcm_plug_t *plug,
673 break; 673 break;
674 plugin = plugin->prev; 674 plugin = plugin->prev;
675 } 675 }
676 bitset_and(client_vmask, dstmask, plugin->src_format.channels); 676 bitmap_and(client_vmask, client_vmask, dstmask, plugin->src_format.channels);
677 return 0; 677 return 0;
678 } 678 }
679} 679}
@@ -683,21 +683,21 @@ static int snd_pcm_plug_playback_disable_useless_channels(snd_pcm_plug_t *plug,
683{ 683{
684 snd_pcm_plugin_t *plugin = snd_pcm_plug_first(plug); 684 snd_pcm_plugin_t *plugin = snd_pcm_plug_first(plug);
685 unsigned int nchannels = plugin->src_format.channels; 685 unsigned int nchannels = plugin->src_format.channels;
686 bitset_t bs[bitset_size(nchannels)]; 686 DECLARE_BITMAP(bs, nchannels);
687 bitset_t *srcmask = bs; 687 unsigned long *srcmask = bs;
688 int err; 688 int err;
689 unsigned int channel; 689 unsigned int channel;
690 for (channel = 0; channel < nchannels; channel++) { 690 for (channel = 0; channel < nchannels; channel++) {
691 if (src_channels[channel].enabled) 691 if (src_channels[channel].enabled)
692 bitset_set(srcmask, channel); 692 set_bit(channel, srcmask);
693 else 693 else
694 bitset_reset(srcmask, channel); 694 clear_bit(channel, srcmask);
695 } 695 }
696 err = snd_pcm_plug_playback_channels_mask(plug, srcmask); 696 err = snd_pcm_plug_playback_channels_mask(plug, srcmask);
697 if (err < 0) 697 if (err < 0)
698 return err; 698 return err;
699 for (channel = 0; channel < nchannels; channel++) { 699 for (channel = 0; channel < nchannels; channel++) {
700 if (!bitset_get(srcmask, channel)) 700 if (!test_bit(channel, srcmask))
701 src_channels[channel].enabled = 0; 701 src_channels[channel].enabled = 0;
702 } 702 }
703 return 0; 703 return 0;
@@ -709,16 +709,16 @@ static int snd_pcm_plug_capture_disable_useless_channels(snd_pcm_plug_t *plug,
709{ 709{
710 snd_pcm_plugin_t *plugin = snd_pcm_plug_last(plug); 710 snd_pcm_plugin_t *plugin = snd_pcm_plug_last(plug);
711 unsigned int nchannels = plugin->dst_format.channels; 711 unsigned int nchannels = plugin->dst_format.channels;
712 bitset_t bs[bitset_size(nchannels)]; 712 DECLARE_BITMAP(bs, nchannels);
713 bitset_t *dstmask = bs; 713 unsigned long *dstmask = bs;
714 bitset_t *srcmask; 714 unsigned long *srcmask;
715 int err; 715 int err;
716 unsigned int channel; 716 unsigned int channel;
717 for (channel = 0; channel < nchannels; channel++) { 717 for (channel = 0; channel < nchannels; channel++) {
718 if (client_channels[channel].enabled) 718 if (client_channels[channel].enabled)
719 bitset_set(dstmask, channel); 719 set_bit(channel, dstmask);
720 else 720 else
721 bitset_reset(dstmask, channel); 721 clear_bit(channel, dstmask);
722 } 722 }
723 while (plugin) { 723 while (plugin) {
724 err = plugin->src_channels_mask(plugin, dstmask, &srcmask); 724 err = plugin->src_channels_mask(plugin, dstmask, &srcmask);
@@ -730,7 +730,7 @@ static int snd_pcm_plug_capture_disable_useless_channels(snd_pcm_plug_t *plug,
730 plugin = snd_pcm_plug_first(plug); 730 plugin = snd_pcm_plug_first(plug);
731 nchannels = plugin->src_format.channels; 731 nchannels = plugin->src_format.channels;
732 for (channel = 0; channel < nchannels; channel++) { 732 for (channel = 0; channel < nchannels; channel++) {
733 if (!bitset_get(dstmask, channel)) 733 if (!test_bit(channel, dstmask))
734 src_channels[channel].enabled = 0; 734 src_channels[channel].enabled = 0;
735 } 735 }
736 return 0; 736 return 0;
diff --git a/sound/core/oss/pcm_plugin.h b/sound/core/oss/pcm_plugin.h
index 0f86ce477490..69a43172142c 100644
--- a/sound/core/oss/pcm_plugin.h
+++ b/sound/core/oss/pcm_plugin.h
@@ -22,71 +22,11 @@
22 * 22 *
23 */ 23 */
24 24
25#ifndef ATTRIBUTE_UNUSED 25#include <linux/bitmap.h>
26#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
27#endif
28
29typedef unsigned int bitset_t;
30
31static inline size_t bitset_size(int nbits)
32{
33 return (nbits + sizeof(bitset_t) * 8 - 1) / (sizeof(bitset_t) * 8);
34}
35
36static inline bitset_t *bitset_alloc(int nbits)
37{
38 return kcalloc(bitset_size(nbits), sizeof(bitset_t), GFP_KERNEL);
39}
40
41static inline void bitset_set(bitset_t *bitmap, unsigned int pos)
42{
43 size_t bits = sizeof(*bitmap) * 8;
44 bitmap[pos / bits] |= 1 << (pos % bits);
45}
46
47static inline void bitset_reset(bitset_t *bitmap, unsigned int pos)
48{
49 size_t bits = sizeof(*bitmap) * 8;
50 bitmap[pos / bits] &= ~(1 << (pos % bits));
51}
52
53static inline int bitset_get(bitset_t *bitmap, unsigned int pos)
54{
55 size_t bits = sizeof(*bitmap) * 8;
56 return !!(bitmap[pos / bits] & (1 << (pos % bits)));
57}
58
59static inline void bitset_copy(bitset_t *dst, bitset_t *src, unsigned int nbits)
60{
61 memcpy(dst, src, bitset_size(nbits) * sizeof(bitset_t));
62}
63
64static inline void bitset_and(bitset_t *dst, bitset_t *bs, unsigned int nbits)
65{
66 bitset_t *end = dst + bitset_size(nbits);
67 while (dst < end)
68 *dst++ &= *bs++;
69}
70
71static inline void bitset_or(bitset_t *dst, bitset_t *bs, unsigned int nbits)
72{
73 bitset_t *end = dst + bitset_size(nbits);
74 while (dst < end)
75 *dst++ |= *bs++;
76}
77
78static inline void bitset_zero(bitset_t *dst, unsigned int nbits)
79{
80 bitset_t *end = dst + bitset_size(nbits);
81 while (dst < end)
82 *dst++ = 0;
83}
84 26
85static inline void bitset_one(bitset_t *dst, unsigned int nbits) 27static inline unsigned long *bitmap_alloc(unsigned int nbits)
86{ 28{
87 bitset_t *end = dst + bitset_size(nbits); 29 return kmalloc(BITS_TO_LONGS(nbits), GFP_KERNEL);
88 while (dst < end)
89 *dst++ = ~(bitset_t)0;
90} 30}
91 31
92#define snd_pcm_plug_t snd_pcm_substream_t 32#define snd_pcm_plug_t snd_pcm_substream_t
@@ -131,11 +71,11 @@ struct _snd_pcm_plugin {
131 snd_pcm_uframes_t frames, 71 snd_pcm_uframes_t frames,
132 snd_pcm_plugin_channel_t **channels); 72 snd_pcm_plugin_channel_t **channels);
133 int (*src_channels_mask)(snd_pcm_plugin_t *plugin, 73 int (*src_channels_mask)(snd_pcm_plugin_t *plugin,
134 bitset_t *dst_vmask, 74 unsigned long *dst_vmask,
135 bitset_t **src_vmask); 75 unsigned long **src_vmask);
136 int (*dst_channels_mask)(snd_pcm_plugin_t *plugin, 76 int (*dst_channels_mask)(snd_pcm_plugin_t *plugin,
137 bitset_t *src_vmask, 77 unsigned long *src_vmask,
138 bitset_t **dst_vmask); 78 unsigned long **dst_vmask);
139 snd_pcm_sframes_t (*transfer)(snd_pcm_plugin_t *plugin, 79 snd_pcm_sframes_t (*transfer)(snd_pcm_plugin_t *plugin,
140 const snd_pcm_plugin_channel_t *src_channels, 80 const snd_pcm_plugin_channel_t *src_channels,
141 snd_pcm_plugin_channel_t *dst_channels, 81 snd_pcm_plugin_channel_t *dst_channels,
@@ -151,8 +91,8 @@ struct _snd_pcm_plugin {
151 char *buf; 91 char *buf;
152 snd_pcm_uframes_t buf_frames; 92 snd_pcm_uframes_t buf_frames;
153 snd_pcm_plugin_channel_t *buf_channels; 93 snd_pcm_plugin_channel_t *buf_channels;
154 bitset_t *src_vmask; 94 unsigned long *src_vmask;
155 bitset_t *dst_vmask; 95 unsigned long *dst_vmask;
156 char extra_data[0]; 96 char extra_data[0];
157}; 97};
158 98
diff --git a/sound/core/oss/rate.c b/sound/core/oss/rate.c
index 1096ec186714..7e325ca58706 100644
--- a/sound/core/oss/rate.c
+++ b/sound/core/oss/rate.c
@@ -315,7 +315,7 @@ static snd_pcm_sframes_t rate_transfer(snd_pcm_plugin_t *plugin,
315 315
316static int rate_action(snd_pcm_plugin_t *plugin, 316static int rate_action(snd_pcm_plugin_t *plugin,
317 snd_pcm_plugin_action_t action, 317 snd_pcm_plugin_action_t action,
318 unsigned long udata ATTRIBUTE_UNUSED) 318 unsigned long udata)
319{ 319{
320 snd_assert(plugin != NULL, return -ENXIO); 320 snd_assert(plugin != NULL, return -ENXIO);
321 switch (action) { 321 switch (action) {
diff --git a/sound/core/oss/route.c b/sound/core/oss/route.c
index c955b7dfdb30..7519aed757cd 100644
--- a/sound/core/oss/route.c
+++ b/sound/core/oss/route.c
@@ -70,9 +70,9 @@ typedef union {
70 70
71 71
72static void route_to_channel_from_zero(snd_pcm_plugin_t *plugin, 72static void route_to_channel_from_zero(snd_pcm_plugin_t *plugin,
73 const snd_pcm_plugin_channel_t *src_channels ATTRIBUTE_UNUSED, 73 const snd_pcm_plugin_channel_t *src_channels,
74 snd_pcm_plugin_channel_t *dst_channel, 74 snd_pcm_plugin_channel_t *dst_channel,
75 ttable_dst_t* ttable ATTRIBUTE_UNUSED, snd_pcm_uframes_t frames) 75 ttable_dst_t* ttable, snd_pcm_uframes_t frames)
76{ 76{
77 if (dst_channel->wanted) 77 if (dst_channel->wanted)
78 snd_pcm_area_silence(&dst_channel->area, 0, frames, plugin->dst_format.format); 78 snd_pcm_area_silence(&dst_channel->area, 0, frames, plugin->dst_format.format);
@@ -298,46 +298,46 @@ static void route_to_channel(snd_pcm_plugin_t *plugin,
298} 298}
299 299
300static int route_src_channels_mask(snd_pcm_plugin_t *plugin, 300static int route_src_channels_mask(snd_pcm_plugin_t *plugin,
301 bitset_t *dst_vmask, 301 unsigned long *dst_vmask,
302 bitset_t **src_vmask) 302 unsigned long **src_vmask)
303{ 303{
304 route_t *data = (route_t *)plugin->extra_data; 304 route_t *data = (route_t *)plugin->extra_data;
305 int schannels = plugin->src_format.channels; 305 int schannels = plugin->src_format.channels;
306 int dchannels = plugin->dst_format.channels; 306 int dchannels = plugin->dst_format.channels;
307 bitset_t *vmask = plugin->src_vmask; 307 unsigned long *vmask = plugin->src_vmask;
308 int channel; 308 int channel;
309 ttable_dst_t *dp = data->ttable; 309 ttable_dst_t *dp = data->ttable;
310 bitset_zero(vmask, schannels); 310 bitmap_zero(vmask, schannels);
311 for (channel = 0; channel < dchannels; channel++, dp++) { 311 for (channel = 0; channel < dchannels; channel++, dp++) {
312 unsigned int src; 312 unsigned int src;
313 ttable_src_t *sp; 313 ttable_src_t *sp;
314 if (!bitset_get(dst_vmask, channel)) 314 if (!test_bit(channel, dst_vmask))
315 continue; 315 continue;
316 sp = dp->srcs; 316 sp = dp->srcs;
317 for (src = 0; src < dp->nsrcs; src++, sp++) 317 for (src = 0; src < dp->nsrcs; src++, sp++)
318 bitset_set(vmask, sp->channel); 318 set_bit(sp->channel, vmask);
319 } 319 }
320 *src_vmask = vmask; 320 *src_vmask = vmask;
321 return 0; 321 return 0;
322} 322}
323 323
324static int route_dst_channels_mask(snd_pcm_plugin_t *plugin, 324static int route_dst_channels_mask(snd_pcm_plugin_t *plugin,
325 bitset_t *src_vmask, 325 unsigned long *src_vmask,
326 bitset_t **dst_vmask) 326 unsigned long **dst_vmask)
327{ 327{
328 route_t *data = (route_t *)plugin->extra_data; 328 route_t *data = (route_t *)plugin->extra_data;
329 int dchannels = plugin->dst_format.channels; 329 int dchannels = plugin->dst_format.channels;
330 bitset_t *vmask = plugin->dst_vmask; 330 unsigned long *vmask = plugin->dst_vmask;
331 int channel; 331 int channel;
332 ttable_dst_t *dp = data->ttable; 332 ttable_dst_t *dp = data->ttable;
333 bitset_zero(vmask, dchannels); 333 bitmap_zero(vmask, dchannels);
334 for (channel = 0; channel < dchannels; channel++, dp++) { 334 for (channel = 0; channel < dchannels; channel++, dp++) {
335 unsigned int src; 335 unsigned int src;
336 ttable_src_t *sp; 336 ttable_src_t *sp;
337 sp = dp->srcs; 337 sp = dp->srcs;
338 for (src = 0; src < dp->nsrcs; src++, sp++) { 338 for (src = 0; src < dp->nsrcs; src++, sp++) {
339 if (bitset_get(src_vmask, sp->channel)) { 339 if (test_bit(sp->channel, src_vmask)) {
340 bitset_set(vmask, channel); 340 set_bit(channel, vmask);
341 break; 341 break;
342 } 342 }
343 } 343 }