[PATCH] pci_module_init() conversion for pata_pdc2027x
[deliverable/linux.git] / sound / core / oss / route.c
CommitLineData
1da177e4 1/*
0534ab42 2 * Route Plug-In
1da177e4
LT
3 * Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
4 *
5 *
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Library General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include <sound/driver.h>
21a3479a
JK
23
24#ifdef CONFIG_SND_PCM_OSS_PLUGINS
25
1da177e4
LT
26#include <linux/slab.h>
27#include <linux/time.h>
28#include <sound/core.h>
29#include <sound/pcm.h>
30#include "pcm_plugin.h"
31
0534ab42
TI
32static void zero_areas(struct snd_pcm_plugin_channel *dvp, int ndsts,
33 snd_pcm_uframes_t frames, int format)
1da177e4 34{
0534ab42
TI
35 int dst = 0;
36 for (; dst < ndsts; ++dst) {
37 if (dvp->wanted)
38 snd_pcm_area_silence(&dvp->area, 0, frames, format);
39 dvp->enabled = 0;
40 dvp++;
1da177e4
LT
41 }
42}
43
0534ab42 44static inline void copy_area(const struct snd_pcm_plugin_channel *src_channel,
6ac77bc1 45 struct snd_pcm_plugin_channel *dst_channel,
0534ab42 46 snd_pcm_uframes_t frames, int format)
1da177e4 47{
1da177e4 48 dst_channel->enabled = 1;
0534ab42 49 snd_pcm_area_copy(&src_channel->area, 0, &dst_channel->area, 0, frames, format);
1da177e4
LT
50}
51
6ac77bc1 52static snd_pcm_sframes_t route_transfer(struct snd_pcm_plugin *plugin,
0534ab42
TI
53 const struct snd_pcm_plugin_channel *src_channels,
54 struct snd_pcm_plugin_channel *dst_channels,
55 snd_pcm_uframes_t frames)
1da177e4 56{
0534ab42 57 int nsrcs, ndsts, dst;
6ac77bc1 58 struct snd_pcm_plugin_channel *dvp;
0534ab42 59 int format;
1da177e4
LT
60
61 snd_assert(plugin != NULL && src_channels != NULL && dst_channels != NULL, return -ENXIO);
62 if (frames == 0)
63 return 0;
1da177e4 64
0534ab42
TI
65 nsrcs = plugin->src_format.channels;
66 ndsts = plugin->dst_format.channels;
1da177e4 67
0534ab42
TI
68 format = plugin->dst_format.format;
69 dvp = dst_channels;
70 if (nsrcs <= 1) {
71 /* expand to all channels */
72 for (dst = 0; dst < ndsts; ++dst) {
73 copy_area(src_channels, dvp, frames, format);
74 dvp++;
1da177e4 75 }
0534ab42 76 return frames;
1da177e4 77 }
1da177e4 78
0534ab42
TI
79 for (dst = 0; dst < ndsts && dst < nsrcs; ++dst) {
80 copy_area(src_channels, dvp, frames, format);
1da177e4 81 dvp++;
0534ab42 82 src_channels++;
1da177e4 83 }
0534ab42
TI
84 if (dst < ndsts)
85 zero_areas(dvp, ndsts - dst, frames, format);
1da177e4
LT
86 return frames;
87}
88
6ac77bc1
TI
89int snd_pcm_plugin_build_route(struct snd_pcm_substream *plug,
90 struct snd_pcm_plugin_format *src_format,
91 struct snd_pcm_plugin_format *dst_format,
6ac77bc1 92 struct snd_pcm_plugin **r_plugin)
1da177e4 93{
6ac77bc1 94 struct snd_pcm_plugin *plugin;
1da177e4
LT
95 int err;
96
97 snd_assert(r_plugin != NULL, return -ENXIO);
98 *r_plugin = NULL;
99 snd_assert(src_format->rate == dst_format->rate, return -ENXIO);
0534ab42 100 snd_assert(src_format->format == dst_format->format, return -ENXIO);
1da177e4 101
0534ab42
TI
102 err = snd_pcm_plugin_build(plug, "route conversion",
103 src_format, dst_format, 0, &plugin);
1da177e4
LT
104 if (err < 0)
105 return err;
106
1da177e4 107 plugin->transfer = route_transfer;
1da177e4
LT
108 *r_plugin = plugin;
109 return 0;
110}
21a3479a
JK
111
112#endif
This page took 0.169219 seconds and 5 git commands to generate.