Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  *  Linear conversion Plug-In
0003  *  Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
0004  *
0005  *
0006  *   This library is free software; you can redistribute it and/or modify
0007  *   it under the terms of the GNU Library General Public License as
0008  *   published by the Free Software Foundation; either version 2 of
0009  *   the License, or (at your option) any later version.
0010  *
0011  *   This program is distributed in the hope that it will be useful,
0012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  *   GNU Library General Public License for more details.
0015  *
0016  *   You should have received a copy of the GNU Library General Public
0017  *   License along with this library; if not, write to the Free Software
0018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
0019  *
0020  */
0021 
0022 #include <linux/time.h>
0023 #include <sound/core.h>
0024 #include <sound/pcm.h>
0025 #include "pcm_plugin.h"
0026 
0027 static snd_pcm_sframes_t copy_transfer(struct snd_pcm_plugin *plugin,
0028                  const struct snd_pcm_plugin_channel *src_channels,
0029                  struct snd_pcm_plugin_channel *dst_channels,
0030                  snd_pcm_uframes_t frames)
0031 {
0032     unsigned int channel;
0033     unsigned int nchannels;
0034 
0035     if (snd_BUG_ON(!plugin || !src_channels || !dst_channels))
0036         return -ENXIO;
0037     if (frames == 0)
0038         return 0;
0039     nchannels = plugin->src_format.channels;
0040     for (channel = 0; channel < nchannels; channel++) {
0041         if (snd_BUG_ON(src_channels->area.first % 8 ||
0042                    src_channels->area.step % 8))
0043             return -ENXIO;
0044         if (snd_BUG_ON(dst_channels->area.first % 8 ||
0045                    dst_channels->area.step % 8))
0046             return -ENXIO;
0047         if (!src_channels->enabled) {
0048             if (dst_channels->wanted)
0049                 snd_pcm_area_silence(&dst_channels->area, 0, frames, plugin->dst_format.format);
0050             dst_channels->enabled = 0;
0051             continue;
0052         }
0053         dst_channels->enabled = 1;
0054         snd_pcm_area_copy(&src_channels->area, 0, &dst_channels->area, 0, frames, plugin->src_format.format);
0055         src_channels++;
0056         dst_channels++;
0057     }
0058     return frames;
0059 }
0060 
0061 int snd_pcm_plugin_build_copy(struct snd_pcm_substream *plug,
0062                   struct snd_pcm_plugin_format *src_format,
0063                   struct snd_pcm_plugin_format *dst_format,
0064                   struct snd_pcm_plugin **r_plugin)
0065 {
0066     int err;
0067     struct snd_pcm_plugin *plugin;
0068     int width;
0069 
0070     if (snd_BUG_ON(!r_plugin))
0071         return -ENXIO;
0072     *r_plugin = NULL;
0073 
0074     if (snd_BUG_ON(src_format->format != dst_format->format))
0075         return -ENXIO;
0076     if (snd_BUG_ON(src_format->rate != dst_format->rate))
0077         return -ENXIO;
0078     if (snd_BUG_ON(src_format->channels != dst_format->channels))
0079         return -ENXIO;
0080 
0081     width = snd_pcm_format_physical_width(src_format->format);
0082     if (snd_BUG_ON(width <= 0))
0083         return -ENXIO;
0084 
0085     err = snd_pcm_plugin_build(plug, "copy", src_format, dst_format,
0086                    0, &plugin);
0087     if (err < 0)
0088         return err;
0089     plugin->transfer = copy_transfer;
0090     *r_plugin = plugin;
0091     return 0;
0092 }