[ALSA] Use standard bitmap functions
[linux-2.6.git] / sound / core / oss / pcm_plugin.h
1 #ifndef __PCM_PLUGIN_H
2 #define __PCM_PLUGIN_H
3
4 /*
5  *  Digital Audio (Plugin interface) abstract layer
6  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
7  *
8  *
9  *   This program is free software; you can redistribute it and/or modify
10  *   it under the terms of the GNU General Public License as published by
11  *   the Free Software Foundation; either version 2 of the License, or
12  *   (at your option) any later version.
13  *
14  *   This program is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with this program; if not, write to the Free Software
21  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22  *
23  */
24
25 #include <linux/bitmap.h>
26
27 static inline unsigned long *bitmap_alloc(unsigned int nbits)
28 {
29         return kmalloc(BITS_TO_LONGS(nbits), GFP_KERNEL);
30 }
31
32 #define snd_pcm_plug_t snd_pcm_substream_t
33 #define snd_pcm_plug_stream(plug) ((plug)->stream)
34
35 typedef enum {
36         INIT = 0,
37         PREPARE = 1,
38 } snd_pcm_plugin_action_t;
39
40 typedef struct _snd_pcm_channel_area {
41         void *addr;                     /* base address of channel samples */
42         unsigned int first;             /* offset to first sample in bits */
43         unsigned int step;              /* samples distance in bits */
44 } snd_pcm_channel_area_t;
45
46 typedef struct _snd_pcm_plugin_channel {
47         void *aptr;                     /* pointer to the allocated area */
48         snd_pcm_channel_area_t area;
49         snd_pcm_uframes_t frames;       /* allocated frames */
50         unsigned int enabled:1;         /* channel need to be processed */
51         unsigned int wanted:1;          /* channel is wanted */
52 } snd_pcm_plugin_channel_t;
53
54 typedef struct _snd_pcm_plugin_format {
55         int format;
56         unsigned int rate;
57         unsigned int channels;
58 } snd_pcm_plugin_format_t;
59
60 struct _snd_pcm_plugin {
61         const char *name;               /* plug-in name */
62         int stream;
63         snd_pcm_plugin_format_t src_format;     /* source format */
64         snd_pcm_plugin_format_t dst_format;     /* destination format */
65         int src_width;                  /* sample width in bits */
66         int dst_width;                  /* sample width in bits */
67         int access;
68         snd_pcm_sframes_t (*src_frames)(snd_pcm_plugin_t *plugin, snd_pcm_uframes_t dst_frames);
69         snd_pcm_sframes_t (*dst_frames)(snd_pcm_plugin_t *plugin, snd_pcm_uframes_t src_frames);
70         snd_pcm_sframes_t (*client_channels)(snd_pcm_plugin_t *plugin,
71                                  snd_pcm_uframes_t frames,
72                                  snd_pcm_plugin_channel_t **channels);
73         int (*src_channels_mask)(snd_pcm_plugin_t *plugin,
74                                  unsigned long *dst_vmask,
75                                  unsigned long **src_vmask);
76         int (*dst_channels_mask)(snd_pcm_plugin_t *plugin,
77                                  unsigned long *src_vmask,
78                                  unsigned long **dst_vmask);
79         snd_pcm_sframes_t (*transfer)(snd_pcm_plugin_t *plugin,
80                             const snd_pcm_plugin_channel_t *src_channels,
81                             snd_pcm_plugin_channel_t *dst_channels,
82                             snd_pcm_uframes_t frames);
83         int (*action)(snd_pcm_plugin_t *plugin,
84                       snd_pcm_plugin_action_t action,
85                       unsigned long data);
86         snd_pcm_plugin_t *prev;
87         snd_pcm_plugin_t *next;
88         snd_pcm_plug_t *plug;
89         void *private_data;
90         void (*private_free)(snd_pcm_plugin_t *plugin);
91         char *buf;
92         snd_pcm_uframes_t buf_frames;
93         snd_pcm_plugin_channel_t *buf_channels;
94         unsigned long *src_vmask;
95         unsigned long *dst_vmask;
96         char extra_data[0];
97 };
98
99 int snd_pcm_plugin_build(snd_pcm_plug_t *handle,
100                          const char *name,
101                          snd_pcm_plugin_format_t *src_format,
102                          snd_pcm_plugin_format_t *dst_format,
103                          size_t extra,
104                          snd_pcm_plugin_t **ret);
105 int snd_pcm_plugin_free(snd_pcm_plugin_t *plugin);
106 int snd_pcm_plugin_clear(snd_pcm_plugin_t **first);
107 int snd_pcm_plug_alloc(snd_pcm_plug_t *plug, snd_pcm_uframes_t frames);
108 snd_pcm_sframes_t snd_pcm_plug_client_size(snd_pcm_plug_t *handle, snd_pcm_uframes_t drv_size);
109 snd_pcm_sframes_t snd_pcm_plug_slave_size(snd_pcm_plug_t *handle, snd_pcm_uframes_t clt_size);
110
111 #define FULL ROUTE_PLUGIN_RESOLUTION
112 #define HALF ROUTE_PLUGIN_RESOLUTION / 2
113 typedef int route_ttable_entry_t;
114
115 int snd_pcm_plugin_build_io(snd_pcm_plug_t *handle,
116                             snd_pcm_hw_params_t *params,
117                             snd_pcm_plugin_t **r_plugin);
118 int snd_pcm_plugin_build_linear(snd_pcm_plug_t *handle,
119                                 snd_pcm_plugin_format_t *src_format,
120                                 snd_pcm_plugin_format_t *dst_format,
121                                 snd_pcm_plugin_t **r_plugin);
122 int snd_pcm_plugin_build_mulaw(snd_pcm_plug_t *handle,
123                                snd_pcm_plugin_format_t *src_format,
124                                snd_pcm_plugin_format_t *dst_format,
125                                snd_pcm_plugin_t **r_plugin);
126 int snd_pcm_plugin_build_rate(snd_pcm_plug_t *handle,
127                               snd_pcm_plugin_format_t *src_format,
128                               snd_pcm_plugin_format_t *dst_format,
129                               snd_pcm_plugin_t **r_plugin);
130 int snd_pcm_plugin_build_route(snd_pcm_plug_t *handle,
131                                snd_pcm_plugin_format_t *src_format,
132                                snd_pcm_plugin_format_t *dst_format,
133                                route_ttable_entry_t *ttable,
134                                snd_pcm_plugin_t **r_plugin);
135 int snd_pcm_plugin_build_copy(snd_pcm_plug_t *handle,
136                               snd_pcm_plugin_format_t *src_format,
137                               snd_pcm_plugin_format_t *dst_format,
138                               snd_pcm_plugin_t **r_plugin);
139
140 int snd_pcm_plug_format_plugins(snd_pcm_plug_t *substream,
141                                 snd_pcm_hw_params_t *params,
142                                 snd_pcm_hw_params_t *slave_params);
143
144 int snd_pcm_plug_slave_format(int format, snd_mask_t *format_mask);
145
146 int snd_pcm_plugin_append(snd_pcm_plugin_t *plugin);
147
148 snd_pcm_sframes_t snd_pcm_plug_write_transfer(snd_pcm_plug_t *handle, snd_pcm_plugin_channel_t *src_channels, snd_pcm_uframes_t size);
149 snd_pcm_sframes_t snd_pcm_plug_read_transfer(snd_pcm_plug_t *handle, snd_pcm_plugin_channel_t *dst_channels_final, snd_pcm_uframes_t size);
150
151 snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(snd_pcm_plug_t *handle,
152                                          char *buf, snd_pcm_uframes_t count,
153                                          snd_pcm_plugin_channel_t **channels);
154
155 snd_pcm_sframes_t snd_pcm_plugin_client_channels(snd_pcm_plugin_t *plugin,
156                                        snd_pcm_uframes_t frames,
157                                        snd_pcm_plugin_channel_t **channels);
158
159 int snd_pcm_area_silence(const snd_pcm_channel_area_t *dst_channel, size_t dst_offset,
160                          size_t samples, int format);
161 int snd_pcm_area_copy(const snd_pcm_channel_area_t *src_channel, size_t src_offset,
162                       const snd_pcm_channel_area_t *dst_channel, size_t dst_offset,
163                       size_t samples, int format);
164
165 void *snd_pcm_plug_buf_alloc(snd_pcm_plug_t *plug, snd_pcm_uframes_t size);
166 void snd_pcm_plug_buf_unlock(snd_pcm_plug_t *plug, void *ptr);
167 snd_pcm_sframes_t snd_pcm_oss_write3(snd_pcm_substream_t *substream, const char *ptr, snd_pcm_uframes_t size, int in_kernel);
168 snd_pcm_sframes_t snd_pcm_oss_read3(snd_pcm_substream_t *substream, char *ptr, snd_pcm_uframes_t size, int in_kernel);
169 snd_pcm_sframes_t snd_pcm_oss_writev3(snd_pcm_substream_t *substream, void **bufs, snd_pcm_uframes_t frames, int in_kernel);
170 snd_pcm_sframes_t snd_pcm_oss_readv3(snd_pcm_substream_t *substream, void **bufs, snd_pcm_uframes_t frames, int in_kernel);
171
172
173
174 #define ROUTE_PLUGIN_RESOLUTION 16
175
176 int getput_index(int format);
177 int copy_index(int format);
178 int conv_index(int src_format, int dst_format);
179
180 void zero_channel(snd_pcm_plugin_t *plugin,
181                   const snd_pcm_plugin_channel_t *dst_channel,
182                   size_t samples);
183
184 #ifdef PLUGIN_DEBUG
185 #define pdprintf( fmt, args... ) printk( "plugin: " fmt, ##args)
186 #else
187 #define pdprintf( fmt, args... ) 
188 #endif
189
190 #endif                          /* __PCM_PLUGIN_H */