xref: /third_party/alsa-lib/include/pcm_rate.h (revision d5ac70f0)
1/**
2 * \file include/pcm_rate.h
3 * \brief External Rate-Converter-Plugin SDK
4 * \author Takashi Iwai <tiwai@suse.de>
5 * \date 2006
6 *
7 * External Rate-Converter-Plugin SDK
8 */
9
10/*
11 * ALSA external PCM rate-converter plugin SDK (draft version)
12 *
13 * Copyright (c) 2006 Takashi Iwai <tiwai@suse.de>
14 *
15 *   This library is free software; you can redistribute it and/or modify
16 *   it under the terms of the GNU Lesser General Public License as
17 *   published by the Free Software Foundation; either version 2.1 of
18 *   the License, or (at your option) any later version.
19 *
20 *   This program is distributed in the hope that it will be useful,
21 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
22 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 *   GNU Lesser General Public License for more details.
24 *
25 *   You should have received a copy of the GNU Lesser General Public
26 *   License along with this library; if not, write to the Free Software
27 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
28 *
29 */
30
31#ifndef __ALSA_PCM_RATE_H
32#define __ALSA_PCM_RATE_H
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/**
39 * Protocol version
40 */
41#define SND_PCM_RATE_PLUGIN_VERSION	0x010003
42
43/** hw_params information for a single side */
44typedef struct snd_pcm_rate_side_info {
45	snd_pcm_format_t format;
46	unsigned int rate;
47	snd_pcm_uframes_t buffer_size;
48	snd_pcm_uframes_t period_size;
49} snd_pcm_rate_side_info_t;
50
51/** hw_params information */
52typedef struct snd_pcm_rate_info {
53	struct snd_pcm_rate_side_info in;
54	struct snd_pcm_rate_side_info out;
55	unsigned int channels;
56} snd_pcm_rate_info_t;
57
58enum {
59	SND_PCM_RATE_FLAG_INTERLEAVED = (1U << 0),	/** only interleaved format */
60	SND_PCM_RATE_FLAG_SYNC_FORMATS = (1U << 1),	/** both input and output formats have to be identical */
61};
62
63/** Callback table of rate-converter */
64typedef struct snd_pcm_rate_ops {
65	/**
66	 * close the converter; optional
67	 */
68	void (*close)(void *obj);
69	/**
70	 * initialize the converter, called at hw_params
71	 */
72	int (*init)(void *obj, snd_pcm_rate_info_t *info);
73	/**
74	 * free the converter; optional
75	 */
76	void (*free)(void *obj);
77	/**
78	 * reset the converter, called at prepare; optional
79	 */
80	void (*reset)(void *obj);
81	/**
82	 * adjust the pitch, called at sw_params; optional
83	 */
84	int (*adjust_pitch)(void *obj, snd_pcm_rate_info_t *info);
85	/**
86	 * convert the data
87	 */
88	void (*convert)(void *obj,
89			const snd_pcm_channel_area_t *dst_areas,
90			snd_pcm_uframes_t dst_offset, unsigned int dst_frames,
91			const snd_pcm_channel_area_t *src_areas,
92			snd_pcm_uframes_t src_offset, unsigned int src_frames);
93	/**
94	 * convert an s16 interleaved-data array; exclusive with convert
95	 */
96	void (*convert_s16)(void *obj, int16_t *dst, unsigned int dst_frames,
97			    const int16_t *src, unsigned int src_frames);
98	/**
99	 * compute the frame size for input
100	 */
101	snd_pcm_uframes_t (*input_frames)(void *obj, snd_pcm_uframes_t frames);
102	/**
103	 * compute the frame size for output
104	 */
105	snd_pcm_uframes_t (*output_frames)(void *obj, snd_pcm_uframes_t frames);
106	/**
107	 * the protocol version the plugin supports;
108	 * new field since version 0x010002
109	 */
110	unsigned int version;
111	/**
112	 * return the supported min / max sample rates;
113	 * new ops since version 0x010002
114	 */
115	int (*get_supported_rates)(void *obj, unsigned int *rate_min,
116				   unsigned int *rate_max);
117	/**
118	 * show some status messages for verbose mode;
119	 * new ops since version 0x010002
120	 */
121	void (*dump)(void *obj, snd_output_t *out);
122	/**
123	 * get the supported input and output formats (optional);
124	 * new ops since version 0x010003
125	 */
126	int (*get_supported_formats)(void *obj, uint64_t *in_formats,
127				     uint64_t *out_formats,
128				     unsigned int *flags);
129} snd_pcm_rate_ops_t;
130
131/** open function type */
132typedef int (*snd_pcm_rate_open_func_t)(unsigned int version, void **objp,
133					snd_pcm_rate_ops_t *opsp);
134
135typedef int (*snd_pcm_rate_open_conf_func_t)(unsigned int version, void **objp,
136					snd_pcm_rate_ops_t *opsp, const snd_config_t *conf);
137
138/**
139 * Define the object entry for external PCM rate-converter plugins
140 */
141#define SND_PCM_RATE_PLUGIN_ENTRY(name) _snd_pcm_rate_##name##_open
142#define SND_PCM_RATE_PLUGIN_CONF_ENTRY(name) _snd_pcm_rate_##name##_open_conf
143
144#ifndef DOC_HIDDEN
145/* old rate_ops for protocol version 0x010001 */
146typedef struct snd_pcm_rate_old_ops {
147	void (*close)(void *obj);
148	int (*init)(void *obj, snd_pcm_rate_info_t *info);
149	void (*free)(void *obj);
150	void (*reset)(void *obj);
151	int (*adjust_pitch)(void *obj, snd_pcm_rate_info_t *info);
152	void (*convert)(void *obj,
153			const snd_pcm_channel_area_t *dst_areas,
154			snd_pcm_uframes_t dst_offset, unsigned int dst_frames,
155			const snd_pcm_channel_area_t *src_areas,
156			snd_pcm_uframes_t src_offset, unsigned int src_frames);
157	void (*convert_s16)(void *obj, int16_t *dst, unsigned int dst_frames,
158			    const int16_t *src, unsigned int src_frames);
159	snd_pcm_uframes_t (*input_frames)(void *obj, snd_pcm_uframes_t frames);
160	snd_pcm_uframes_t (*output_frames)(void *obj, snd_pcm_uframes_t frames);
161} snd_pcm_rate_old_ops_t;
162
163/* old rate_ops for protocol version 0x010002 */
164typedef struct snd_pcm_rate_v2_ops {
165	void (*close)(void *obj);
166	int (*init)(void *obj, snd_pcm_rate_info_t *info);
167	void (*free)(void *obj);
168	void (*reset)(void *obj);
169	int (*adjust_pitch)(void *obj, snd_pcm_rate_info_t *info);
170	void (*convert)(void *obj,
171			const snd_pcm_channel_area_t *dst_areas,
172			snd_pcm_uframes_t dst_offset, unsigned int dst_frames,
173			const snd_pcm_channel_area_t *src_areas,
174			snd_pcm_uframes_t src_offset, unsigned int src_frames);
175	void (*convert_s16)(void *obj, int16_t *dst, unsigned int dst_frames,
176			    const int16_t *src, unsigned int src_frames);
177	snd_pcm_uframes_t (*input_frames)(void *obj, snd_pcm_uframes_t frames);
178	snd_pcm_uframes_t (*output_frames)(void *obj, snd_pcm_uframes_t frames);
179	unsigned int version;
180	int (*get_supported_rates)(void *obj, unsigned int *rate_min,
181				   unsigned int *rate_max);
182	void (*dump)(void *obj, snd_output_t *out);
183} snd_pcm_rate_v2_ops_t;
184#endif
185
186#ifdef __cplusplus
187}
188#endif
189
190#endif /* __ALSA_PCM_RATE_H */
191