Committer: Michael Beasley <mike@snafu.setup>
[mikesnafu-overlay.git] / sound / core / oss / copy.c
blob9ded30d0e97da413c1ec244ec8aa205d0b010254
1 /*
2 * Linear conversion Plug-In
3 * Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
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.
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.
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
22 #include <linux/time.h>
23 #include <sound/core.h>
24 #include <sound/pcm.h>
25 #include "pcm_plugin.h"
27 static snd_pcm_sframes_t copy_transfer(struct snd_pcm_plugin *plugin,
28 const struct snd_pcm_plugin_channel *src_channels,
29 struct snd_pcm_plugin_channel *dst_channels,
30 snd_pcm_uframes_t frames)
32 unsigned int channel;
33 unsigned int nchannels;
35 snd_assert(plugin != NULL && src_channels != NULL && dst_channels != NULL, return -ENXIO);
36 if (frames == 0)
37 return 0;
38 nchannels = plugin->src_format.channels;
39 for (channel = 0; channel < nchannels; channel++) {
40 snd_assert(src_channels->area.first % 8 == 0 &&
41 src_channels->area.step % 8 == 0,
42 return -ENXIO);
43 snd_assert(dst_channels->area.first % 8 == 0 &&
44 dst_channels->area.step % 8 == 0,
45 return -ENXIO);
46 if (!src_channels->enabled) {
47 if (dst_channels->wanted)
48 snd_pcm_area_silence(&dst_channels->area, 0, frames, plugin->dst_format.format);
49 dst_channels->enabled = 0;
50 continue;
52 dst_channels->enabled = 1;
53 snd_pcm_area_copy(&src_channels->area, 0, &dst_channels->area, 0, frames, plugin->src_format.format);
54 src_channels++;
55 dst_channels++;
57 return frames;
60 int snd_pcm_plugin_build_copy(struct snd_pcm_substream *plug,
61 struct snd_pcm_plugin_format *src_format,
62 struct snd_pcm_plugin_format *dst_format,
63 struct snd_pcm_plugin **r_plugin)
65 int err;
66 struct snd_pcm_plugin *plugin;
67 int width;
69 snd_assert(r_plugin != NULL, return -ENXIO);
70 *r_plugin = NULL;
72 snd_assert(src_format->format == dst_format->format, return -ENXIO);
73 snd_assert(src_format->rate == dst_format->rate, return -ENXIO);
74 snd_assert(src_format->channels == dst_format->channels, return -ENXIO);
76 width = snd_pcm_format_physical_width(src_format->format);
77 snd_assert(width > 0, return -ENXIO);
79 err = snd_pcm_plugin_build(plug, "copy", src_format, dst_format,
80 0, &plugin);
81 if (err < 0)
82 return err;
83 plugin->transfer = copy_transfer;
84 *r_plugin = plugin;
85 return 0;