OpenCores
URL https://opencores.org/ocsvn/or1k_soc_on_altera_embedded_dev_kit/or1k_soc_on_altera_embedded_dev_kit/trunk

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [linux-2.6/] [linux-2.6.24/] [sound/] [core/] [oss/] [io.c] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 xianfeng
/*
2
 *  PCM I/O Plug-In Interface
3
 *  Copyright (c) 1999 by Jaroslav Kysela <perex@perex.cz>
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 <sound/pcm_params.h>
27
#include "pcm_plugin.h"
28
 
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)
33
 
34
/*
35
 *  Basic io plugin
36
 */
37
 
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)
42
{
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);
47
        } else {
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;
54
                        else
55
                                bufs[channel] = NULL;
56
                }
57
                return pcm_writev(plugin->plug, bufs, frames);
58
        }
59
}
60
 
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)
65
{
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);
70
        } else {
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;
77
                        else
78
                                bufs[channel] = NULL;
79
                }
80
                return pcm_readv(plugin->plug, bufs, frames);
81
        }
82
        return 0;
83
}
84
 
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)
88
{
89
        int err;
90
        unsigned int channel;
91
        struct snd_pcm_plugin_channel *v;
92
        err = snd_pcm_plugin_client_channels(plugin, frames, &v);
93
        if (err < 0)
94
                return err;
95
        *channels = v;
96
        if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) {
97
                for (channel = 0; channel < plugin->src_format.channels; ++channel, ++v)
98
                        v->wanted = 1;
99
        }
100
        return frames;
101
}
102
 
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)
106
{
107
        int err;
108
        struct snd_pcm_plugin_format format;
109
        struct snd_pcm_plugin *plugin;
110
 
111
        snd_assert(r_plugin != NULL, return -ENXIO);
112
        *r_plugin = NULL;
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",
118
                                   &format, &format,
119
                                   sizeof(void *) * format.channels,
120
                                   &plugin);
121
        if (err < 0)
122
                return err;
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;
128
        } else {
129
                plugin->transfer = io_capture_transfer;
130
        }
131
 
132
        *r_plugin = plugin;
133
        return 0;
134
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.