Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / core / oss / pcm_plugin.h
blob0f86ce47749019922b0b6bfdacb518083645efa8
1 #ifndef __PCM_PLUGIN_H
2 #define __PCM_PLUGIN_H
4 /*
5 * Digital Audio (Plugin interface) abstract layer
6 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
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.
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.
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
25 #ifndef ATTRIBUTE_UNUSED
26 #define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
27 #endif
29 typedef unsigned int bitset_t;
31 static inline size_t bitset_size(int nbits)
33 return (nbits + sizeof(bitset_t) * 8 - 1) / (sizeof(bitset_t) * 8);
36 static inline bitset_t *bitset_alloc(int nbits)
38 return kcalloc(bitset_size(nbits), sizeof(bitset_t), GFP_KERNEL);
41 static inline void bitset_set(bitset_t *bitmap, unsigned int pos)
43 size_t bits = sizeof(*bitmap) * 8;
44 bitmap[pos / bits] |= 1 << (pos % bits);
47 static inline void bitset_reset(bitset_t *bitmap, unsigned int pos)
49 size_t bits = sizeof(*bitmap) * 8;
50 bitmap[pos / bits] &= ~(1 << (pos % bits));
53 static inline int bitset_get(bitset_t *bitmap, unsigned int pos)
55 size_t bits = sizeof(*bitmap) * 8;
56 return !!(bitmap[pos / bits] & (1 << (pos % bits)));
59 static inline void bitset_copy(bitset_t *dst, bitset_t *src, unsigned int nbits)
61 memcpy(dst, src, bitset_size(nbits) * sizeof(bitset_t));
64 static inline void bitset_and(bitset_t *dst, bitset_t *bs, unsigned int nbits)
66 bitset_t *end = dst + bitset_size(nbits);
67 while (dst < end)
68 *dst++ &= *bs++;
71 static inline void bitset_or(bitset_t *dst, bitset_t *bs, unsigned int nbits)
73 bitset_t *end = dst + bitset_size(nbits);
74 while (dst < end)
75 *dst++ |= *bs++;
78 static inline void bitset_zero(bitset_t *dst, unsigned int nbits)
80 bitset_t *end = dst + bitset_size(nbits);
81 while (dst < end)
82 *dst++ = 0;
85 static inline void bitset_one(bitset_t *dst, unsigned int nbits)
87 bitset_t *end = dst + bitset_size(nbits);
88 while (dst < end)
89 *dst++ = ~(bitset_t)0;
92 #define snd_pcm_plug_t snd_pcm_substream_t
93 #define snd_pcm_plug_stream(plug) ((plug)->stream)
95 typedef enum {
96 INIT = 0,
97 PREPARE = 1,
98 } snd_pcm_plugin_action_t;
100 typedef struct _snd_pcm_channel_area {
101 void *addr; /* base address of channel samples */
102 unsigned int first; /* offset to first sample in bits */
103 unsigned int step; /* samples distance in bits */
104 } snd_pcm_channel_area_t;
106 typedef struct _snd_pcm_plugin_channel {
107 void *aptr; /* pointer to the allocated area */
108 snd_pcm_channel_area_t area;
109 snd_pcm_uframes_t frames; /* allocated frames */
110 unsigned int enabled:1; /* channel need to be processed */
111 unsigned int wanted:1; /* channel is wanted */
112 } snd_pcm_plugin_channel_t;
114 typedef struct _snd_pcm_plugin_format {
115 int format;
116 unsigned int rate;
117 unsigned int channels;
118 } snd_pcm_plugin_format_t;
120 struct _snd_pcm_plugin {
121 const char *name; /* plug-in name */
122 int stream;
123 snd_pcm_plugin_format_t src_format; /* source format */
124 snd_pcm_plugin_format_t dst_format; /* destination format */
125 int src_width; /* sample width in bits */
126 int dst_width; /* sample width in bits */
127 int access;
128 snd_pcm_sframes_t (*src_frames)(snd_pcm_plugin_t *plugin, snd_pcm_uframes_t dst_frames);
129 snd_pcm_sframes_t (*dst_frames)(snd_pcm_plugin_t *plugin, snd_pcm_uframes_t src_frames);
130 snd_pcm_sframes_t (*client_channels)(snd_pcm_plugin_t *plugin,
131 snd_pcm_uframes_t frames,
132 snd_pcm_plugin_channel_t **channels);
133 int (*src_channels_mask)(snd_pcm_plugin_t *plugin,
134 bitset_t *dst_vmask,
135 bitset_t **src_vmask);
136 int (*dst_channels_mask)(snd_pcm_plugin_t *plugin,
137 bitset_t *src_vmask,
138 bitset_t **dst_vmask);
139 snd_pcm_sframes_t (*transfer)(snd_pcm_plugin_t *plugin,
140 const snd_pcm_plugin_channel_t *src_channels,
141 snd_pcm_plugin_channel_t *dst_channels,
142 snd_pcm_uframes_t frames);
143 int (*action)(snd_pcm_plugin_t *plugin,
144 snd_pcm_plugin_action_t action,
145 unsigned long data);
146 snd_pcm_plugin_t *prev;
147 snd_pcm_plugin_t *next;
148 snd_pcm_plug_t *plug;
149 void *private_data;
150 void (*private_free)(snd_pcm_plugin_t *plugin);
151 char *buf;
152 snd_pcm_uframes_t buf_frames;
153 snd_pcm_plugin_channel_t *buf_channels;
154 bitset_t *src_vmask;
155 bitset_t *dst_vmask;
156 char extra_data[0];
159 int snd_pcm_plugin_build(snd_pcm_plug_t *handle,
160 const char *name,
161 snd_pcm_plugin_format_t *src_format,
162 snd_pcm_plugin_format_t *dst_format,
163 size_t extra,
164 snd_pcm_plugin_t **ret);
165 int snd_pcm_plugin_free(snd_pcm_plugin_t *plugin);
166 int snd_pcm_plugin_clear(snd_pcm_plugin_t **first);
167 int snd_pcm_plug_alloc(snd_pcm_plug_t *plug, snd_pcm_uframes_t frames);
168 snd_pcm_sframes_t snd_pcm_plug_client_size(snd_pcm_plug_t *handle, snd_pcm_uframes_t drv_size);
169 snd_pcm_sframes_t snd_pcm_plug_slave_size(snd_pcm_plug_t *handle, snd_pcm_uframes_t clt_size);
171 #define FULL ROUTE_PLUGIN_RESOLUTION
172 #define HALF ROUTE_PLUGIN_RESOLUTION / 2
173 typedef int route_ttable_entry_t;
175 int snd_pcm_plugin_build_io(snd_pcm_plug_t *handle,
176 snd_pcm_hw_params_t *params,
177 snd_pcm_plugin_t **r_plugin);
178 int snd_pcm_plugin_build_linear(snd_pcm_plug_t *handle,
179 snd_pcm_plugin_format_t *src_format,
180 snd_pcm_plugin_format_t *dst_format,
181 snd_pcm_plugin_t **r_plugin);
182 int snd_pcm_plugin_build_mulaw(snd_pcm_plug_t *handle,
183 snd_pcm_plugin_format_t *src_format,
184 snd_pcm_plugin_format_t *dst_format,
185 snd_pcm_plugin_t **r_plugin);
186 int snd_pcm_plugin_build_rate(snd_pcm_plug_t *handle,
187 snd_pcm_plugin_format_t *src_format,
188 snd_pcm_plugin_format_t *dst_format,
189 snd_pcm_plugin_t **r_plugin);
190 int snd_pcm_plugin_build_route(snd_pcm_plug_t *handle,
191 snd_pcm_plugin_format_t *src_format,
192 snd_pcm_plugin_format_t *dst_format,
193 route_ttable_entry_t *ttable,
194 snd_pcm_plugin_t **r_plugin);
195 int snd_pcm_plugin_build_copy(snd_pcm_plug_t *handle,
196 snd_pcm_plugin_format_t *src_format,
197 snd_pcm_plugin_format_t *dst_format,
198 snd_pcm_plugin_t **r_plugin);
200 int snd_pcm_plug_format_plugins(snd_pcm_plug_t *substream,
201 snd_pcm_hw_params_t *params,
202 snd_pcm_hw_params_t *slave_params);
204 int snd_pcm_plug_slave_format(int format, snd_mask_t *format_mask);
206 int snd_pcm_plugin_append(snd_pcm_plugin_t *plugin);
208 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);
209 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);
211 snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(snd_pcm_plug_t *handle,
212 char *buf, snd_pcm_uframes_t count,
213 snd_pcm_plugin_channel_t **channels);
215 snd_pcm_sframes_t snd_pcm_plugin_client_channels(snd_pcm_plugin_t *plugin,
216 snd_pcm_uframes_t frames,
217 snd_pcm_plugin_channel_t **channels);
219 int snd_pcm_area_silence(const snd_pcm_channel_area_t *dst_channel, size_t dst_offset,
220 size_t samples, int format);
221 int snd_pcm_area_copy(const snd_pcm_channel_area_t *src_channel, size_t src_offset,
222 const snd_pcm_channel_area_t *dst_channel, size_t dst_offset,
223 size_t samples, int format);
225 void *snd_pcm_plug_buf_alloc(snd_pcm_plug_t *plug, snd_pcm_uframes_t size);
226 void snd_pcm_plug_buf_unlock(snd_pcm_plug_t *plug, void *ptr);
227 snd_pcm_sframes_t snd_pcm_oss_write3(snd_pcm_substream_t *substream, const char *ptr, snd_pcm_uframes_t size, int in_kernel);
228 snd_pcm_sframes_t snd_pcm_oss_read3(snd_pcm_substream_t *substream, char *ptr, snd_pcm_uframes_t size, int in_kernel);
229 snd_pcm_sframes_t snd_pcm_oss_writev3(snd_pcm_substream_t *substream, void **bufs, snd_pcm_uframes_t frames, int in_kernel);
230 snd_pcm_sframes_t snd_pcm_oss_readv3(snd_pcm_substream_t *substream, void **bufs, snd_pcm_uframes_t frames, int in_kernel);
234 #define ROUTE_PLUGIN_RESOLUTION 16
236 int getput_index(int format);
237 int copy_index(int format);
238 int conv_index(int src_format, int dst_format);
240 void zero_channel(snd_pcm_plugin_t *plugin,
241 const snd_pcm_plugin_channel_t *dst_channel,
242 size_t samples);
244 #ifdef PLUGIN_DEBUG
245 #define pdprintf( fmt, args... ) printk( "plugin: " fmt, ##args)
246 #else
247 #define pdprintf( fmt, args... )
248 #endif
250 #endif /* __PCM_PLUGIN_H */