• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  PCM - Common plugin code
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 Lesser General Public License as
8  *   published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
15  *
16  *   You should have received a copy of the GNU Lesser General Public
17  *   License along with this library; if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21 
22 #include "pcm_generic.h"
23 
24 typedef snd_pcm_uframes_t (*snd_pcm_slave_xfer_areas_func_t)
25      (snd_pcm_t *pcm,
26       const snd_pcm_channel_area_t *areas,
27       snd_pcm_uframes_t offset,
28       snd_pcm_uframes_t size,
29       const snd_pcm_channel_area_t *slave_areas,
30       snd_pcm_uframes_t slave_offset,
31       snd_pcm_uframes_t *slave_sizep);
32 
33 typedef snd_pcm_sframes_t (*snd_pcm_slave_xfer_areas_undo_func_t)
34      (snd_pcm_t *pcm,
35       const snd_pcm_channel_area_t *res_areas,	/* result areas */
36       snd_pcm_uframes_t res_offset,		/* offset of result areas */
37       snd_pcm_uframes_t res_size,		/* size of result areas */
38       snd_pcm_uframes_t slave_undo_size);
39 
40 typedef struct {
41 	snd_pcm_generic_t gen;
42 	snd_pcm_slave_xfer_areas_func_t read;
43 	snd_pcm_slave_xfer_areas_func_t write;
44 	snd_pcm_slave_xfer_areas_undo_func_t undo_read;
45 	snd_pcm_slave_xfer_areas_undo_func_t undo_write;
46 	int (*init)(snd_pcm_t *pcm);
47 	snd_pcm_uframes_t appl_ptr, hw_ptr;
48 } snd_pcm_plugin_t;
49 
50 /* make local functions really local */
51 #define snd_pcm_plugin_init \
52 	snd1_pcm_plugin_init
53 #define snd_pcm_plugin_may_wait_for_avail_min_conv \
54 	snd1_pcm_plugin_may_wait_for_avail_min_conv
55 #define snd_pcm_plugin_may_wait_for_avail_min \
56 	snd1_pcm_plugin_may_wait_for_avail_min
57 #define snd_pcm_plugin_fast_ops \
58 	snd1_pcm_plugin_fast_ops
59 #define snd_pcm_plugin_undo_read_generic \
60 	snd1_pcm_plugin_undo_read_generic
61 #define snd_pcm_plugin_undo_write_generic \
62 	snd1_pcm_plugin_undo_write_generic
63 #define snd_pcm_plugin_rewind \
64 	snd1_pcm_plugin_rewind
65 #define snd_pcm_plugin_forward \
66 	snd1_pcm_plugin_forward
67 
68 void snd_pcm_plugin_init(snd_pcm_plugin_t *plugin);
69 snd_pcm_sframes_t snd_pcm_plugin_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
70 snd_pcm_sframes_t snd_pcm_plugin_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
71 int snd_pcm_plugin_may_wait_for_avail_min_conv(snd_pcm_t *pcm, snd_pcm_uframes_t avail,
72 					       snd_pcm_uframes_t (*conv)(snd_pcm_t *, snd_pcm_uframes_t));
73 int snd_pcm_plugin_may_wait_for_avail_min(snd_pcm_t *pcm, snd_pcm_uframes_t avail);
74 
75 extern const snd_pcm_fast_ops_t snd_pcm_plugin_fast_ops;
76 
77 snd_pcm_sframes_t snd_pcm_plugin_undo_read_generic
78      (snd_pcm_t *pcm,
79       const snd_pcm_channel_area_t *res_areas,	/* result areas */
80       snd_pcm_uframes_t res_offset,		/* offset of result areas */
81       snd_pcm_uframes_t res_size,		/* size of result areas */
82       snd_pcm_uframes_t slave_undo_size);
83 
84 snd_pcm_sframes_t snd_pcm_plugin_undo_write_generic
85      (snd_pcm_t *pcm,
86       const snd_pcm_channel_area_t *res_areas,	/* result areas */
87       snd_pcm_uframes_t res_offset,		/* offset of result areas */
88       snd_pcm_uframes_t res_size,		/* size of result areas */
89       snd_pcm_uframes_t slave_undo_size);
90 
91 /* make local functions really local */
92 #define snd_pcm_linear_get_index	snd1_pcm_linear_get_index
93 #define snd_pcm_linear_put_index	snd1_pcm_linear_put_index
94 #define snd_pcm_linear_convert_index	snd1_pcm_linear_convert_index
95 #define snd_pcm_linear_convert	snd1_pcm_linear_convert
96 #define snd_pcm_linear_getput	snd1_pcm_linear_getput
97 #define snd_pcm_alaw_decode	snd1_pcm_alaw_decode
98 #define snd_pcm_alaw_encode	snd1_pcm_alaw_encode
99 #define snd_pcm_mulaw_decode	snd1_pcm_mulaw_decode
100 #define snd_pcm_mulaw_encode	snd1_pcm_mulaw_encode
101 #define snd_pcm_adpcm_decode	snd1_pcm_adpcm_decode
102 #define snd_pcm_adpcm_encode	snd1_pcm_adpcm_encode
103 
104 int snd_pcm_linear_get_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
105 int snd_pcm_linear_put_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
106 int snd_pcm_linear_convert_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
107 
108 void snd_pcm_linear_convert(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
109 			    const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset,
110 			    unsigned int channels, snd_pcm_uframes_t frames,
111 			    unsigned int convidx);
112 void snd_pcm_linear_getput(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
113 			   const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset,
114 			   unsigned int channels, snd_pcm_uframes_t frames,
115 			   unsigned int get_idx, unsigned int put_idx);
116 void snd_pcm_alaw_decode(const snd_pcm_channel_area_t *dst_areas,
117 			 snd_pcm_uframes_t dst_offset,
118 			 const snd_pcm_channel_area_t *src_areas,
119 			 snd_pcm_uframes_t src_offset,
120 			 unsigned int channels, snd_pcm_uframes_t frames,
121 			 unsigned int putidx);
122 void snd_pcm_alaw_encode(const snd_pcm_channel_area_t *dst_areas,
123 			 snd_pcm_uframes_t dst_offset,
124 			 const snd_pcm_channel_area_t *src_areas,
125 			 snd_pcm_uframes_t src_offset,
126 			 unsigned int channels, snd_pcm_uframes_t frames,
127 			 unsigned int getidx);
128 void snd_pcm_mulaw_decode(const snd_pcm_channel_area_t *dst_areas,
129 			  snd_pcm_uframes_t dst_offset,
130 			  const snd_pcm_channel_area_t *src_areas,
131 			  snd_pcm_uframes_t src_offset,
132 			  unsigned int channels, snd_pcm_uframes_t frames,
133 			  unsigned int putidx);
134 void snd_pcm_mulaw_encode(const snd_pcm_channel_area_t *dst_areas,
135 			  snd_pcm_uframes_t dst_offset,
136 			  const snd_pcm_channel_area_t *src_areas,
137 			  snd_pcm_uframes_t src_offset,
138 			  unsigned int channels, snd_pcm_uframes_t frames,
139 			  unsigned int getidx);
140 
141 typedef struct _snd_pcm_adpcm_state {
142 	int pred_val;		/* Calculated predicted value */
143 	int step_idx;		/* Previous StepSize lookup index */
144 } snd_pcm_adpcm_state_t;
145 
146 void snd_pcm_adpcm_decode(const snd_pcm_channel_area_t *dst_areas,
147 			  snd_pcm_uframes_t dst_offset,
148 			  const snd_pcm_channel_area_t *src_areas,
149 			  snd_pcm_uframes_t src_offset,
150 			  unsigned int channels, snd_pcm_uframes_t frames,
151 			  unsigned int putidx,
152 			  snd_pcm_adpcm_state_t *states);
153 void snd_pcm_adpcm_encode(const snd_pcm_channel_area_t *dst_areas,
154 			  snd_pcm_uframes_t dst_offset,
155 			  const snd_pcm_channel_area_t *src_areas,
156 			  snd_pcm_uframes_t src_offset,
157 			  unsigned int channels, snd_pcm_uframes_t frames,
158 			  unsigned int getidx,
159 			  snd_pcm_adpcm_state_t *states);
160