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>
24 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
26 #include <linux/time.h>
27 #include <sound/core.h>
28 #include <sound/pcm.h>
29 #include <sound/pcm_params.h>
30 #include "pcm_plugin.h"
32 #define pcm_write(plug,buf,count) snd_pcm_oss_write3(plug,buf,count,1)
33 #define pcm_writev(plug,vec,count) snd_pcm_oss_writev3(plug,vec,count,1)
34 #define pcm_read(plug,buf,count) snd_pcm_oss_read3(plug,buf,count,1)
35 #define pcm_readv(plug,vec,count) snd_pcm_oss_readv3(plug,vec,count,1)
41 static snd_pcm_sframes_t
io_playback_transfer(struct snd_pcm_plugin
*plugin
,
42 const struct snd_pcm_plugin_channel
*src_channels
,
43 struct snd_pcm_plugin_channel
*dst_channels
,
44 snd_pcm_uframes_t frames
)
46 snd_assert(plugin
!= NULL
, return -ENXIO
);
47 snd_assert(src_channels
!= NULL
, return -ENXIO
);
48 if (plugin
->access
== SNDRV_PCM_ACCESS_RW_INTERLEAVED
) {
49 return pcm_write(plugin
->plug
, src_channels
->area
.addr
, frames
);
51 int channel
, channels
= plugin
->dst_format
.channels
;
52 void **bufs
= (void**)plugin
->extra_data
;
53 snd_assert(bufs
!= NULL
, return -ENXIO
);
54 for (channel
= 0; channel
< channels
; channel
++) {
55 if (src_channels
[channel
].enabled
)
56 bufs
[channel
] = src_channels
[channel
].area
.addr
;
60 return pcm_writev(plugin
->plug
, bufs
, frames
);
64 static snd_pcm_sframes_t
io_capture_transfer(struct snd_pcm_plugin
*plugin
,
65 const struct snd_pcm_plugin_channel
*src_channels
,
66 struct snd_pcm_plugin_channel
*dst_channels
,
67 snd_pcm_uframes_t frames
)
69 snd_assert(plugin
!= NULL
, return -ENXIO
);
70 snd_assert(dst_channels
!= NULL
, return -ENXIO
);
71 if (plugin
->access
== SNDRV_PCM_ACCESS_RW_INTERLEAVED
) {
72 return pcm_read(plugin
->plug
, dst_channels
->area
.addr
, frames
);
74 int channel
, channels
= plugin
->dst_format
.channels
;
75 void **bufs
= (void**)plugin
->extra_data
;
76 snd_assert(bufs
!= NULL
, return -ENXIO
);
77 for (channel
= 0; channel
< channels
; channel
++) {
78 if (dst_channels
[channel
].enabled
)
79 bufs
[channel
] = dst_channels
[channel
].area
.addr
;
83 return pcm_readv(plugin
->plug
, bufs
, frames
);
88 static snd_pcm_sframes_t
io_src_channels(struct snd_pcm_plugin
*plugin
,
89 snd_pcm_uframes_t frames
,
90 struct snd_pcm_plugin_channel
**channels
)
94 struct snd_pcm_plugin_channel
*v
;
95 err
= snd_pcm_plugin_client_channels(plugin
, frames
, &v
);
99 if (plugin
->access
== SNDRV_PCM_ACCESS_RW_INTERLEAVED
) {
100 for (channel
= 0; channel
< plugin
->src_format
.channels
; ++channel
, ++v
)
106 int snd_pcm_plugin_build_io(struct snd_pcm_substream
*plug
,
107 struct snd_pcm_hw_params
*params
,
108 struct snd_pcm_plugin
**r_plugin
)
111 struct snd_pcm_plugin_format format
;
112 struct snd_pcm_plugin
*plugin
;
114 snd_assert(r_plugin
!= NULL
, return -ENXIO
);
116 snd_assert(plug
!= NULL
&& params
!= NULL
, return -ENXIO
);
117 format
.format
= params_format(params
);
118 format
.rate
= params_rate(params
);
119 format
.channels
= params_channels(params
);
120 err
= snd_pcm_plugin_build(plug
, "I/O io",
122 sizeof(void *) * format
.channels
,
126 plugin
->access
= params_access(params
);
127 if (snd_pcm_plug_stream(plug
) == SNDRV_PCM_STREAM_PLAYBACK
) {
128 plugin
->transfer
= io_playback_transfer
;
129 if (plugin
->access
== SNDRV_PCM_ACCESS_RW_INTERLEAVED
)
130 plugin
->client_channels
= io_src_channels
;
132 plugin
->transfer
= io_capture_transfer
;