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/] [route.c] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 xianfeng
/*
2
 *  Route 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>
23
#include <linux/slab.h>
24
#include <linux/time.h>
25
#include <sound/core.h>
26
#include <sound/pcm.h>
27
#include "pcm_plugin.h"
28
 
29
static void zero_areas(struct snd_pcm_plugin_channel *dvp, int ndsts,
30
                       snd_pcm_uframes_t frames, int format)
31
{
32
        int dst = 0;
33
        for (; dst < ndsts; ++dst) {
34
                if (dvp->wanted)
35
                        snd_pcm_area_silence(&dvp->area, 0, frames, format);
36
                dvp->enabled = 0;
37
                dvp++;
38
        }
39
}
40
 
41
static inline void copy_area(const struct snd_pcm_plugin_channel *src_channel,
42
                             struct snd_pcm_plugin_channel *dst_channel,
43
                             snd_pcm_uframes_t frames, int format)
44
{
45
        dst_channel->enabled = 1;
46
        snd_pcm_area_copy(&src_channel->area, 0, &dst_channel->area, 0, frames, format);
47
}
48
 
49
static snd_pcm_sframes_t route_transfer(struct snd_pcm_plugin *plugin,
50
                                        const struct snd_pcm_plugin_channel *src_channels,
51
                                        struct snd_pcm_plugin_channel *dst_channels,
52
                                        snd_pcm_uframes_t frames)
53
{
54
        int nsrcs, ndsts, dst;
55
        struct snd_pcm_plugin_channel *dvp;
56
        int format;
57
 
58
        snd_assert(plugin != NULL && src_channels != NULL && dst_channels != NULL, return -ENXIO);
59
        if (frames == 0)
60
                return 0;
61
 
62
        nsrcs = plugin->src_format.channels;
63
        ndsts = plugin->dst_format.channels;
64
 
65
        format = plugin->dst_format.format;
66
        dvp = dst_channels;
67
        if (nsrcs <= 1) {
68
                /* expand to all channels */
69
                for (dst = 0; dst < ndsts; ++dst) {
70
                        copy_area(src_channels, dvp, frames, format);
71
                        dvp++;
72
                }
73
                return frames;
74
        }
75
 
76
        for (dst = 0; dst < ndsts && dst < nsrcs; ++dst) {
77
                copy_area(src_channels, dvp, frames, format);
78
                dvp++;
79
                src_channels++;
80
        }
81
        if (dst < ndsts)
82
                zero_areas(dvp, ndsts - dst, frames, format);
83
        return frames;
84
}
85
 
86
int snd_pcm_plugin_build_route(struct snd_pcm_substream *plug,
87
                               struct snd_pcm_plugin_format *src_format,
88
                               struct snd_pcm_plugin_format *dst_format,
89
                               struct snd_pcm_plugin **r_plugin)
90
{
91
        struct snd_pcm_plugin *plugin;
92
        int err;
93
 
94
        snd_assert(r_plugin != NULL, return -ENXIO);
95
        *r_plugin = NULL;
96
        snd_assert(src_format->rate == dst_format->rate, return -ENXIO);
97
        snd_assert(src_format->format == dst_format->format, return -ENXIO);
98
 
99
        err = snd_pcm_plugin_build(plug, "route conversion",
100
                                   src_format, dst_format, 0, &plugin);
101
        if (err < 0)
102
                return err;
103
 
104
        plugin->transfer = route_transfer;
105
        *r_plugin = plugin;
106
        return 0;
107
}

powered by: WebSVN 2.1.0

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