Linux Audio

Check our new training course

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