[ALSA] PCM midlevel & PCM OSS - make procfs & OSS plugin code optional
[deliverable/linux.git] / sound / core / oss / copy.c
CommitLineData
1da177e4
LT
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>
21a3479a
JK
23
24#ifdef SND_PCM_OSS_PLUGINS
25
1da177e4
LT
26#include <linux/time.h>
27#include <sound/core.h>
28#include <sound/pcm.h>
29#include "pcm_plugin.h"
30
6ac77bc1
TI
31static snd_pcm_sframes_t copy_transfer(struct snd_pcm_plugin *plugin,
32 const struct snd_pcm_plugin_channel *src_channels,
33 struct snd_pcm_plugin_channel *dst_channels,
1da177e4
LT
34 snd_pcm_uframes_t frames)
35{
36 unsigned int channel;
37 unsigned int nchannels;
38
39 snd_assert(plugin != NULL && src_channels != NULL && dst_channels != NULL, return -ENXIO);
40 if (frames == 0)
41 return 0;
42 nchannels = plugin->src_format.channels;
43 for (channel = 0; channel < nchannels; channel++) {
44 snd_assert(src_channels->area.first % 8 == 0 &&
45 src_channels->area.step % 8 == 0,
46 return -ENXIO);
47 snd_assert(dst_channels->area.first % 8 == 0 &&
48 dst_channels->area.step % 8 == 0,
49 return -ENXIO);
50 if (!src_channels->enabled) {
51 if (dst_channels->wanted)
52 snd_pcm_area_silence(&dst_channels->area, 0, frames, plugin->dst_format.format);
53 dst_channels->enabled = 0;
54 continue;
55 }
56 dst_channels->enabled = 1;
57 snd_pcm_area_copy(&src_channels->area, 0, &dst_channels->area, 0, frames, plugin->src_format.format);
58 src_channels++;
59 dst_channels++;
60 }
61 return frames;
62}
63
6ac77bc1
TI
64int snd_pcm_plugin_build_copy(struct snd_pcm_substream *plug,
65 struct snd_pcm_plugin_format *src_format,
66 struct snd_pcm_plugin_format *dst_format,
67 struct snd_pcm_plugin **r_plugin)
1da177e4
LT
68{
69 int err;
6ac77bc1 70 struct snd_pcm_plugin *plugin;
1da177e4
LT
71 int width;
72
73 snd_assert(r_plugin != NULL, return -ENXIO);
74 *r_plugin = NULL;
75
76 snd_assert(src_format->format == dst_format->format, return -ENXIO);
77 snd_assert(src_format->rate == dst_format->rate, return -ENXIO);
78 snd_assert(src_format->channels == dst_format->channels, return -ENXIO);
79
80 width = snd_pcm_format_physical_width(src_format->format);
81 snd_assert(width > 0, return -ENXIO);
82
83 err = snd_pcm_plugin_build(plug, "copy", src_format, dst_format,
84 0, &plugin);
85 if (err < 0)
86 return err;
87 plugin->transfer = copy_transfer;
88 *r_plugin = plugin;
89 return 0;
90}
21a3479a
JK
91
92#endif
This page took 0.100049 seconds and 5 git commands to generate.