Merge with /pub/scm/linux/kernel/git/sfrench/cifs-2.6.git/
[linux-2.6] / sound / core / oss / copy.c
1 /*
2  *  Linear conversion Plug-In
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>
23 #include <linux/time.h>
24 #include <sound/core.h>
25 #include <sound/pcm.h>
26 #include "pcm_plugin.h"
27
28 static snd_pcm_sframes_t copy_transfer(snd_pcm_plugin_t *plugin,
29                              const snd_pcm_plugin_channel_t *src_channels,
30                              snd_pcm_plugin_channel_t *dst_channels,
31                              snd_pcm_uframes_t frames)
32 {
33         unsigned int channel;
34         unsigned int nchannels;
35
36         snd_assert(plugin != NULL && src_channels != NULL && dst_channels != NULL, return -ENXIO);
37         if (frames == 0)
38                 return 0;
39         nchannels = plugin->src_format.channels;
40         for (channel = 0; channel < nchannels; channel++) {
41                 snd_assert(src_channels->area.first % 8 == 0 &&
42                            src_channels->area.step % 8 == 0,
43                            return -ENXIO);
44                 snd_assert(dst_channels->area.first % 8 == 0 &&
45                            dst_channels->area.step % 8 == 0,
46                            return -ENXIO);
47                 if (!src_channels->enabled) {
48                         if (dst_channels->wanted)
49                                 snd_pcm_area_silence(&dst_channels->area, 0, frames, plugin->dst_format.format);
50                         dst_channels->enabled = 0;
51                         continue;
52                 }
53                 dst_channels->enabled = 1;
54                 snd_pcm_area_copy(&src_channels->area, 0, &dst_channels->area, 0, frames, plugin->src_format.format);
55                 src_channels++;
56                 dst_channels++;
57         }
58         return frames;
59 }
60
61 int snd_pcm_plugin_build_copy(snd_pcm_plug_t *plug,
62                               snd_pcm_plugin_format_t *src_format,
63                               snd_pcm_plugin_format_t *dst_format,
64                               snd_pcm_plugin_t **r_plugin)
65 {
66         int err;
67         snd_pcm_plugin_t *plugin;
68         int width;
69
70         snd_assert(r_plugin != NULL, return -ENXIO);
71         *r_plugin = NULL;
72
73         snd_assert(src_format->format == dst_format->format, return -ENXIO);
74         snd_assert(src_format->rate == dst_format->rate, return -ENXIO);
75         snd_assert(src_format->channels == dst_format->channels, return -ENXIO);
76
77         width = snd_pcm_format_physical_width(src_format->format);
78         snd_assert(width > 0, return -ENXIO);
79
80         err = snd_pcm_plugin_build(plug, "copy", src_format, dst_format,
81                                    0, &plugin);
82         if (err < 0)
83                 return err;
84         plugin->transfer = copy_transfer;
85         *r_plugin = plugin;
86         return 0;
87 }