18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Linear conversion Plug-In 38c2ecf20Sopenharmony_ci * Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org> 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This library is free software; you can redistribute it and/or modify 78c2ecf20Sopenharmony_ci * it under the terms of the GNU Library General Public License as 88c2ecf20Sopenharmony_ci * published by the Free Software Foundation; either version 2 of 98c2ecf20Sopenharmony_ci * the License, or (at your option) any later version. 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful, 128c2ecf20Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 138c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 148c2ecf20Sopenharmony_ci * GNU Library General Public License for more details. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * You should have received a copy of the GNU Library General Public 178c2ecf20Sopenharmony_ci * License along with this library; if not, write to the Free Software 188c2ecf20Sopenharmony_ci * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci */ 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#include <linux/time.h> 238c2ecf20Sopenharmony_ci#include <sound/core.h> 248c2ecf20Sopenharmony_ci#include <sound/pcm.h> 258c2ecf20Sopenharmony_ci#include "pcm_plugin.h" 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistatic snd_pcm_sframes_t copy_transfer(struct snd_pcm_plugin *plugin, 288c2ecf20Sopenharmony_ci const struct snd_pcm_plugin_channel *src_channels, 298c2ecf20Sopenharmony_ci struct snd_pcm_plugin_channel *dst_channels, 308c2ecf20Sopenharmony_ci snd_pcm_uframes_t frames) 318c2ecf20Sopenharmony_ci{ 328c2ecf20Sopenharmony_ci unsigned int channel; 338c2ecf20Sopenharmony_ci unsigned int nchannels; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci if (snd_BUG_ON(!plugin || !src_channels || !dst_channels)) 368c2ecf20Sopenharmony_ci return -ENXIO; 378c2ecf20Sopenharmony_ci if (frames == 0) 388c2ecf20Sopenharmony_ci return 0; 398c2ecf20Sopenharmony_ci nchannels = plugin->src_format.channels; 408c2ecf20Sopenharmony_ci for (channel = 0; channel < nchannels; channel++) { 418c2ecf20Sopenharmony_ci if (snd_BUG_ON(src_channels->area.first % 8 || 428c2ecf20Sopenharmony_ci src_channels->area.step % 8)) 438c2ecf20Sopenharmony_ci return -ENXIO; 448c2ecf20Sopenharmony_ci if (snd_BUG_ON(dst_channels->area.first % 8 || 458c2ecf20Sopenharmony_ci dst_channels->area.step % 8)) 468c2ecf20Sopenharmony_ci return -ENXIO; 478c2ecf20Sopenharmony_ci if (!src_channels->enabled) { 488c2ecf20Sopenharmony_ci if (dst_channels->wanted) 498c2ecf20Sopenharmony_ci snd_pcm_area_silence(&dst_channels->area, 0, frames, plugin->dst_format.format); 508c2ecf20Sopenharmony_ci dst_channels->enabled = 0; 518c2ecf20Sopenharmony_ci continue; 528c2ecf20Sopenharmony_ci } 538c2ecf20Sopenharmony_ci dst_channels->enabled = 1; 548c2ecf20Sopenharmony_ci snd_pcm_area_copy(&src_channels->area, 0, &dst_channels->area, 0, frames, plugin->src_format.format); 558c2ecf20Sopenharmony_ci src_channels++; 568c2ecf20Sopenharmony_ci dst_channels++; 578c2ecf20Sopenharmony_ci } 588c2ecf20Sopenharmony_ci return frames; 598c2ecf20Sopenharmony_ci} 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ciint snd_pcm_plugin_build_copy(struct snd_pcm_substream *plug, 628c2ecf20Sopenharmony_ci struct snd_pcm_plugin_format *src_format, 638c2ecf20Sopenharmony_ci struct snd_pcm_plugin_format *dst_format, 648c2ecf20Sopenharmony_ci struct snd_pcm_plugin **r_plugin) 658c2ecf20Sopenharmony_ci{ 668c2ecf20Sopenharmony_ci int err; 678c2ecf20Sopenharmony_ci struct snd_pcm_plugin *plugin; 688c2ecf20Sopenharmony_ci int width; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci if (snd_BUG_ON(!r_plugin)) 718c2ecf20Sopenharmony_ci return -ENXIO; 728c2ecf20Sopenharmony_ci *r_plugin = NULL; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci if (snd_BUG_ON(src_format->format != dst_format->format)) 758c2ecf20Sopenharmony_ci return -ENXIO; 768c2ecf20Sopenharmony_ci if (snd_BUG_ON(src_format->rate != dst_format->rate)) 778c2ecf20Sopenharmony_ci return -ENXIO; 788c2ecf20Sopenharmony_ci if (snd_BUG_ON(src_format->channels != dst_format->channels)) 798c2ecf20Sopenharmony_ci return -ENXIO; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci width = snd_pcm_format_physical_width(src_format->format); 828c2ecf20Sopenharmony_ci if (snd_BUG_ON(width <= 0)) 838c2ecf20Sopenharmony_ci return -ENXIO; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci err = snd_pcm_plugin_build(plug, "copy", src_format, dst_format, 868c2ecf20Sopenharmony_ci 0, &plugin); 878c2ecf20Sopenharmony_ci if (err < 0) 888c2ecf20Sopenharmony_ci return err; 898c2ecf20Sopenharmony_ci plugin->transfer = copy_transfer; 908c2ecf20Sopenharmony_ci *r_plugin = plugin; 918c2ecf20Sopenharmony_ci return 0; 928c2ecf20Sopenharmony_ci} 93