2 * Linear conversion Plug-In
3 * Copyright (c) 1999 by Jaroslav Kysela <perex@suse.cz>,
4 * Abramo Bagnara <abramo@alsa-project.org>
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Library General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <sound/driver.h>
24 #include <linux/time.h>
25 #include <sound/core.h>
26 #include <sound/pcm.h>
27 #include "pcm_plugin.h"
30 * Basic linear conversion plugin
33 typedef struct linear_private_data {
37 static void convert(snd_pcm_plugin_t *plugin,
38 const snd_pcm_plugin_channel_t *src_channels,
39 snd_pcm_plugin_channel_t *dst_channels,
40 snd_pcm_uframes_t frames)
43 #include "plugin_ops.h"
45 linear_t *data = (linear_t *)plugin->extra_data;
46 void *conv = conv_labels[data->conv];
48 int nchannels = plugin->src_format.channels;
49 for (channel = 0; channel < nchannels; ++channel) {
52 int src_step, dst_step;
53 snd_pcm_uframes_t frames1;
54 if (!src_channels[channel].enabled) {
55 if (dst_channels[channel].wanted)
56 snd_pcm_area_silence(&dst_channels[channel].area, 0, frames, plugin->dst_format.format);
57 dst_channels[channel].enabled = 0;
60 dst_channels[channel].enabled = 1;
61 src = src_channels[channel].area.addr + src_channels[channel].area.first / 8;
62 dst = dst_channels[channel].area.addr + dst_channels[channel].area.first / 8;
63 src_step = src_channels[channel].area.step / 8;
64 dst_step = dst_channels[channel].area.step / 8;
66 while (frames1-- > 0) {
68 #define CONV_END after
69 #include "plugin_ops.h"
78 static snd_pcm_sframes_t linear_transfer(snd_pcm_plugin_t *plugin,
79 const snd_pcm_plugin_channel_t *src_channels,
80 snd_pcm_plugin_channel_t *dst_channels,
81 snd_pcm_uframes_t frames)
85 snd_assert(plugin != NULL && src_channels != NULL && dst_channels != NULL, return -ENXIO);
86 data = (linear_t *)plugin->extra_data;
89 #ifdef CONFIG_SND_DEBUG
92 for (channel = 0; channel < plugin->src_format.channels; channel++) {
93 snd_assert(src_channels[channel].area.first % 8 == 0 &&
94 src_channels[channel].area.step % 8 == 0,
96 snd_assert(dst_channels[channel].area.first % 8 == 0 &&
97 dst_channels[channel].area.step % 8 == 0,
102 convert(plugin, src_channels, dst_channels, frames);
106 int conv_index(int src_format, int dst_format)
108 int src_endian, dst_endian, sign, src_width, dst_width;
110 sign = (snd_pcm_format_signed(src_format) !=
111 snd_pcm_format_signed(dst_format));
112 #ifdef SNDRV_LITTLE_ENDIAN
113 src_endian = snd_pcm_format_big_endian(src_format);
114 dst_endian = snd_pcm_format_big_endian(dst_format);
116 src_endian = snd_pcm_format_little_endian(src_format);
117 dst_endian = snd_pcm_format_little_endian(dst_format);
125 src_width = snd_pcm_format_width(src_format) / 8 - 1;
126 dst_width = snd_pcm_format_width(dst_format) / 8 - 1;
128 return src_width * 32 + src_endian * 16 + sign * 8 + dst_width * 2 + dst_endian;
131 int snd_pcm_plugin_build_linear(snd_pcm_plug_t *plug,
132 snd_pcm_plugin_format_t *src_format,
133 snd_pcm_plugin_format_t *dst_format,
134 snd_pcm_plugin_t **r_plugin)
137 struct linear_private_data *data;
138 snd_pcm_plugin_t *plugin;
140 snd_assert(r_plugin != NULL, return -ENXIO);
143 snd_assert(src_format->rate == dst_format->rate, return -ENXIO);
144 snd_assert(src_format->channels == dst_format->channels, return -ENXIO);
145 snd_assert(snd_pcm_format_linear(src_format->format) &&
146 snd_pcm_format_linear(dst_format->format), return -ENXIO);
148 err = snd_pcm_plugin_build(plug, "linear format conversion",
149 src_format, dst_format,
150 sizeof(linear_t), &plugin);
153 data = (linear_t *)plugin->extra_data;
154 data->conv = conv_index(src_format->format, dst_format->format);
155 plugin->transfer = linear_transfer;