0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
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 }