pcm_plugin.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #ifndef __PCM_PLUGIN_H
  2. #define __PCM_PLUGIN_H
  3. /*
  4. * Digital Audio (Plugin interface) abstract layer
  5. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <linux/bitmap.h>
  24. static inline unsigned long *bitmap_alloc(unsigned int nbits)
  25. {
  26. return kmalloc(BITS_TO_LONGS(nbits), GFP_KERNEL);
  27. }
  28. #define snd_pcm_plug_stream(plug) ((plug)->stream)
  29. enum snd_pcm_plugin_action {
  30. INIT = 0,
  31. PREPARE = 1,
  32. };
  33. struct snd_pcm_channel_area {
  34. void *addr; /* base address of channel samples */
  35. unsigned int first; /* offset to first sample in bits */
  36. unsigned int step; /* samples distance in bits */
  37. };
  38. struct snd_pcm_plugin_channel {
  39. void *aptr; /* pointer to the allocated area */
  40. struct snd_pcm_channel_area area;
  41. snd_pcm_uframes_t frames; /* allocated frames */
  42. unsigned int enabled:1; /* channel need to be processed */
  43. unsigned int wanted:1; /* channel is wanted */
  44. };
  45. struct snd_pcm_plugin_format {
  46. int format;
  47. unsigned int rate;
  48. unsigned int channels;
  49. };
  50. struct snd_pcm_plugin {
  51. const char *name; /* plug-in name */
  52. int stream;
  53. struct snd_pcm_plugin_format src_format; /* source format */
  54. struct snd_pcm_plugin_format dst_format; /* destination format */
  55. int src_width; /* sample width in bits */
  56. int dst_width; /* sample width in bits */
  57. int access;
  58. snd_pcm_sframes_t (*src_frames)(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t dst_frames);
  59. snd_pcm_sframes_t (*dst_frames)(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t src_frames);
  60. snd_pcm_sframes_t (*client_channels)(struct snd_pcm_plugin *plugin,
  61. snd_pcm_uframes_t frames,
  62. struct snd_pcm_plugin_channel **channels);
  63. int (*src_channels_mask)(struct snd_pcm_plugin *plugin,
  64. unsigned long *dst_vmask,
  65. unsigned long **src_vmask);
  66. int (*dst_channels_mask)(struct snd_pcm_plugin *plugin,
  67. unsigned long *src_vmask,
  68. unsigned long **dst_vmask);
  69. snd_pcm_sframes_t (*transfer)(struct snd_pcm_plugin *plugin,
  70. const struct snd_pcm_plugin_channel *src_channels,
  71. struct snd_pcm_plugin_channel *dst_channels,
  72. snd_pcm_uframes_t frames);
  73. int (*action)(struct snd_pcm_plugin *plugin,
  74. enum snd_pcm_plugin_action action,
  75. unsigned long data);
  76. struct snd_pcm_plugin *prev;
  77. struct snd_pcm_plugin *next;
  78. struct snd_pcm_substream *plug;
  79. void *private_data;
  80. void (*private_free)(struct snd_pcm_plugin *plugin);
  81. char *buf;
  82. snd_pcm_uframes_t buf_frames;
  83. struct snd_pcm_plugin_channel *buf_channels;
  84. unsigned long *src_vmask;
  85. unsigned long *dst_vmask;
  86. char extra_data[0];
  87. };
  88. int snd_pcm_plugin_build(struct snd_pcm_substream *handle,
  89. const char *name,
  90. struct snd_pcm_plugin_format *src_format,
  91. struct snd_pcm_plugin_format *dst_format,
  92. size_t extra,
  93. struct snd_pcm_plugin **ret);
  94. int snd_pcm_plugin_free(struct snd_pcm_plugin *plugin);
  95. int snd_pcm_plugin_clear(struct snd_pcm_plugin **first);
  96. int snd_pcm_plug_alloc(struct snd_pcm_substream *plug, snd_pcm_uframes_t frames);
  97. snd_pcm_sframes_t snd_pcm_plug_client_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t drv_size);
  98. snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t clt_size);
  99. #define FULL ROUTE_PLUGIN_RESOLUTION
  100. #define HALF ROUTE_PLUGIN_RESOLUTION / 2
  101. int snd_pcm_plugin_build_io(struct snd_pcm_substream *handle,
  102. struct snd_pcm_hw_params *params,
  103. struct snd_pcm_plugin **r_plugin);
  104. int snd_pcm_plugin_build_linear(struct snd_pcm_substream *handle,
  105. struct snd_pcm_plugin_format *src_format,
  106. struct snd_pcm_plugin_format *dst_format,
  107. struct snd_pcm_plugin **r_plugin);
  108. int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *handle,
  109. struct snd_pcm_plugin_format *src_format,
  110. struct snd_pcm_plugin_format *dst_format,
  111. struct snd_pcm_plugin **r_plugin);
  112. int snd_pcm_plugin_build_rate(struct snd_pcm_substream *handle,
  113. struct snd_pcm_plugin_format *src_format,
  114. struct snd_pcm_plugin_format *dst_format,
  115. struct snd_pcm_plugin **r_plugin);
  116. int snd_pcm_plugin_build_route(struct snd_pcm_substream *handle,
  117. struct snd_pcm_plugin_format *src_format,
  118. struct snd_pcm_plugin_format *dst_format,
  119. int *ttable,
  120. struct snd_pcm_plugin **r_plugin);
  121. int snd_pcm_plugin_build_copy(struct snd_pcm_substream *handle,
  122. struct snd_pcm_plugin_format *src_format,
  123. struct snd_pcm_plugin_format *dst_format,
  124. struct snd_pcm_plugin **r_plugin);
  125. int snd_pcm_plug_format_plugins(struct snd_pcm_substream *substream,
  126. struct snd_pcm_hw_params *params,
  127. struct snd_pcm_hw_params *slave_params);
  128. int snd_pcm_plug_slave_format(int format, struct snd_mask *format_mask);
  129. int snd_pcm_plugin_append(struct snd_pcm_plugin *plugin);
  130. snd_pcm_sframes_t snd_pcm_plug_write_transfer(struct snd_pcm_substream *handle,
  131. struct snd_pcm_plugin_channel *src_channels,
  132. snd_pcm_uframes_t size);
  133. snd_pcm_sframes_t snd_pcm_plug_read_transfer(struct snd_pcm_substream *handle,
  134. struct snd_pcm_plugin_channel *dst_channels_final,
  135. snd_pcm_uframes_t size);
  136. snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(struct snd_pcm_substream *handle,
  137. char *buf, snd_pcm_uframes_t count,
  138. struct snd_pcm_plugin_channel **channels);
  139. snd_pcm_sframes_t snd_pcm_plugin_client_channels(struct snd_pcm_plugin *plugin,
  140. snd_pcm_uframes_t frames,
  141. struct snd_pcm_plugin_channel **channels);
  142. int snd_pcm_area_silence(const struct snd_pcm_channel_area *dst_channel,
  143. size_t dst_offset,
  144. size_t samples, int format);
  145. int snd_pcm_area_copy(const struct snd_pcm_channel_area *src_channel,
  146. size_t src_offset,
  147. const struct snd_pcm_channel_area *dst_channel,
  148. size_t dst_offset,
  149. size_t samples, int format);
  150. void *snd_pcm_plug_buf_alloc(struct snd_pcm_substream *plug, snd_pcm_uframes_t size);
  151. void snd_pcm_plug_buf_unlock(struct snd_pcm_substream *plug, void *ptr);
  152. snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream,
  153. const char *ptr, snd_pcm_uframes_t size,
  154. int in_kernel);
  155. snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream,
  156. char *ptr, snd_pcm_uframes_t size, int in_kernel);
  157. snd_pcm_sframes_t snd_pcm_oss_writev3(struct snd_pcm_substream *substream,
  158. void **bufs, snd_pcm_uframes_t frames,
  159. int in_kernel);
  160. snd_pcm_sframes_t snd_pcm_oss_readv3(struct snd_pcm_substream *substream,
  161. void **bufs, snd_pcm_uframes_t frames,
  162. int in_kernel);
  163. #define ROUTE_PLUGIN_RESOLUTION 16
  164. int getput_index(int format);
  165. int copy_index(int format);
  166. int conv_index(int src_format, int dst_format);
  167. void zero_channel(struct snd_pcm_plugin *plugin,
  168. const struct snd_pcm_plugin_channel *dst_channel,
  169. size_t samples);
  170. #ifdef PLUGIN_DEBUG
  171. #define pdprintf( fmt, args... ) printk( "plugin: " fmt, ##args)
  172. #else
  173. #define pdprintf( fmt, args... )
  174. #endif
  175. #endif /* __PCM_PLUGIN_H */