copy.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Linear conversion 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. #include <sound/driver.h>
  22. #include <linux/time.h>
  23. #include <sound/core.h>
  24. #include <sound/pcm.h>
  25. #include "pcm_plugin.h"
  26. static snd_pcm_sframes_t copy_transfer(snd_pcm_plugin_t *plugin,
  27. const snd_pcm_plugin_channel_t *src_channels,
  28. snd_pcm_plugin_channel_t *dst_channels,
  29. snd_pcm_uframes_t frames)
  30. {
  31. unsigned int channel;
  32. unsigned int nchannels;
  33. snd_assert(plugin != NULL && src_channels != NULL && dst_channels != NULL, return -ENXIO);
  34. if (frames == 0)
  35. return 0;
  36. nchannels = plugin->src_format.channels;
  37. for (channel = 0; channel < nchannels; channel++) {
  38. snd_assert(src_channels->area.first % 8 == 0 &&
  39. src_channels->area.step % 8 == 0,
  40. return -ENXIO);
  41. snd_assert(dst_channels->area.first % 8 == 0 &&
  42. dst_channels->area.step % 8 == 0,
  43. return -ENXIO);
  44. if (!src_channels->enabled) {
  45. if (dst_channels->wanted)
  46. snd_pcm_area_silence(&dst_channels->area, 0, frames, plugin->dst_format.format);
  47. dst_channels->enabled = 0;
  48. continue;
  49. }
  50. dst_channels->enabled = 1;
  51. snd_pcm_area_copy(&src_channels->area, 0, &dst_channels->area, 0, frames, plugin->src_format.format);
  52. src_channels++;
  53. dst_channels++;
  54. }
  55. return frames;
  56. }
  57. int snd_pcm_plugin_build_copy(snd_pcm_plug_t *plug,
  58. snd_pcm_plugin_format_t *src_format,
  59. snd_pcm_plugin_format_t *dst_format,
  60. snd_pcm_plugin_t **r_plugin)
  61. {
  62. int err;
  63. snd_pcm_plugin_t *plugin;
  64. int width;
  65. snd_assert(r_plugin != NULL, return -ENXIO);
  66. *r_plugin = NULL;
  67. snd_assert(src_format->format == dst_format->format, return -ENXIO);
  68. snd_assert(src_format->rate == dst_format->rate, return -ENXIO);
  69. snd_assert(src_format->channels == dst_format->channels, return -ENXIO);
  70. width = snd_pcm_format_physical_width(src_format->format);
  71. snd_assert(width > 0, return -ENXIO);
  72. err = snd_pcm_plugin_build(plug, "copy", src_format, dst_format,
  73. 0, &plugin);
  74. if (err < 0)
  75. return err;
  76. plugin->transfer = copy_transfer;
  77. *r_plugin = plugin;
  78. return 0;
  79. }