2 * PCM I/O Plug-In Interface
3 * Copyright (c) 1999 by Jaroslav Kysela <perex@suse.cz>
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 <sound/driver.h>
23 #include <linux/time.h>
24 #include <sound/core.h>
25 #include <sound/pcm.h>
26 #include <sound/pcm_params.h>
27 #include "pcm_plugin.h"
29 #define pcm_write(plug,buf,count) snd_pcm_oss_write3(plug,buf,count,1)
30 #define pcm_writev(plug,vec,count) snd_pcm_oss_writev3(plug,vec,count,1)
31 #define pcm_read(plug,buf,count) snd_pcm_oss_read3(plug,buf,count,1)
32 #define pcm_readv(plug,vec,count) snd_pcm_oss_readv3(plug,vec,count,1)
38 static snd_pcm_sframes_t io_playback_transfer(struct snd_pcm_plugin *plugin,
39 const struct snd_pcm_plugin_channel *src_channels,
40 struct snd_pcm_plugin_channel *dst_channels,
41 snd_pcm_uframes_t frames)
43 snd_assert(plugin != NULL, return -ENXIO);
44 snd_assert(src_channels != NULL, return -ENXIO);
45 if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) {
46 return pcm_write(plugin->plug, src_channels->area.addr, frames);
48 int channel, channels = plugin->dst_format.channels;
49 void **bufs = (void**)plugin->extra_data;
50 snd_assert(bufs != NULL, return -ENXIO);
51 for (channel = 0; channel < channels; channel++) {
52 if (src_channels[channel].enabled)
53 bufs[channel] = src_channels[channel].area.addr;
57 return pcm_writev(plugin->plug, bufs, frames);
61 static snd_pcm_sframes_t io_capture_transfer(struct snd_pcm_plugin *plugin,
62 const struct snd_pcm_plugin_channel *src_channels,
63 struct snd_pcm_plugin_channel *dst_channels,
64 snd_pcm_uframes_t frames)
66 snd_assert(plugin != NULL, return -ENXIO);
67 snd_assert(dst_channels != NULL, return -ENXIO);
68 if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) {
69 return pcm_read(plugin->plug, dst_channels->area.addr, frames);
71 int channel, channels = plugin->dst_format.channels;
72 void **bufs = (void**)plugin->extra_data;
73 snd_assert(bufs != NULL, return -ENXIO);
74 for (channel = 0; channel < channels; channel++) {
75 if (dst_channels[channel].enabled)
76 bufs[channel] = dst_channels[channel].area.addr;
80 return pcm_readv(plugin->plug, bufs, frames);
85 static snd_pcm_sframes_t io_src_channels(struct snd_pcm_plugin *plugin,
86 snd_pcm_uframes_t frames,
87 struct snd_pcm_plugin_channel **channels)
91 struct snd_pcm_plugin_channel *v;
92 err = snd_pcm_plugin_client_channels(plugin, frames, &v);
96 if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) {
97 for (channel = 0; channel < plugin->src_format.channels; ++channel, ++v)
103 int snd_pcm_plugin_build_io(struct snd_pcm_substream *plug,
104 struct snd_pcm_hw_params *params,
105 struct snd_pcm_plugin **r_plugin)
108 struct snd_pcm_plugin_format format;
109 struct snd_pcm_plugin *plugin;
111 snd_assert(r_plugin != NULL, return -ENXIO);
113 snd_assert(plug != NULL && params != NULL, return -ENXIO);
114 format.format = params_format(params);
115 format.rate = params_rate(params);
116 format.channels = params_channels(params);
117 err = snd_pcm_plugin_build(plug, "I/O io",
119 sizeof(void *) * format.channels,
123 plugin->access = params_access(params);
124 if (snd_pcm_plug_stream(plug) == SNDRV_PCM_STREAM_PLAYBACK) {
125 plugin->transfer = io_playback_transfer;
126 if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED)
127 plugin->client_channels = io_src_channels;
129 plugin->transfer = io_capture_transfer;