Lines Matching +full:8 +full:- +full:channel
2 * Mu-Law conversion Plug-In Interface
4 * Uros Bizjak <uros@kss-loka.si>
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #define SIGN_BIT (0x80) /* Sign bit for a u-law byte. */
31 #define NSEGS (8) /* Number of u-law segments. */
55 * linear2ulaw() - Convert a linear PCM value to u-law
58 * is biased by adding 33 which shifts the encoding range from (0 - 8158) to
59 * (33 - 8191). The result can be seen in the following encoding table:
62 * ------------------------ ---------------
75 * four bits wxyz. * The trailing bits (a - h) are ignored.
81 * John Wiley & Sons, pps 98-111 and 472-476.
83 static unsigned char linear2ulaw(int pcm_val) /* 2's complement (16-bit range) */ in linear2ulaw()
91 pcm_val = BIAS - pcm_val; in linear2ulaw()
112 * ulaw2linear() - Convert a u-law value to 16-bit linear PCM
124 /* Complement to obtain normal u-law value. */ in ulaw2linear()
134 return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS)); in ulaw2linear()
138 * Basic Mu-Law plugin
159 sample ^= data->flip; in cvt_s16_to_native()
160 if (data->cvt_endian) in cvt_s16_to_native()
162 if (data->native_bytes > data->copy_bytes) in cvt_s16_to_native()
163 memset(dst, 0, data->native_bytes); in cvt_s16_to_native()
164 memcpy(dst + data->native_ofs, (char *)&sample + data->copy_ofs, in cvt_s16_to_native()
165 data->copy_bytes); in cvt_s16_to_native()
173 struct mulaw_priv *data = (struct mulaw_priv *)plugin->extra_data; in mulaw_decode()
174 int channel; in mulaw_decode() local
175 int nchannels = plugin->src_format.channels; in mulaw_decode()
176 for (channel = 0; channel < nchannels; ++channel) { in mulaw_decode()
181 if (!src_channels[channel].enabled) { in mulaw_decode()
182 if (dst_channels[channel].wanted) in mulaw_decode()
183 snd_pcm_area_silence(&dst_channels[channel].area, 0, frames, plugin->dst_format.format); in mulaw_decode()
184 dst_channels[channel].enabled = 0; in mulaw_decode()
187 dst_channels[channel].enabled = 1; in mulaw_decode()
188 src = src_channels[channel].area.addr + src_channels[channel].area.first / 8; in mulaw_decode()
189 dst = dst_channels[channel].area.addr + dst_channels[channel].area.first / 8; in mulaw_decode()
190 src_step = src_channels[channel].area.step / 8; in mulaw_decode()
191 dst_step = dst_channels[channel].area.step / 8; in mulaw_decode()
193 while (frames1-- > 0) { in mulaw_decode()
206 memcpy((char *)&sample + data->copy_ofs, src + data->native_ofs, in cvt_native_to_s16()
207 data->copy_bytes); in cvt_native_to_s16()
208 if (data->cvt_endian) in cvt_native_to_s16()
210 sample ^= data->flip; in cvt_native_to_s16()
219 struct mulaw_priv *data = (struct mulaw_priv *)plugin->extra_data; in mulaw_encode()
220 int channel; in mulaw_encode() local
221 int nchannels = plugin->src_format.channels; in mulaw_encode()
222 for (channel = 0; channel < nchannels; ++channel) { in mulaw_encode()
227 if (!src_channels[channel].enabled) { in mulaw_encode()
228 if (dst_channels[channel].wanted) in mulaw_encode()
229 snd_pcm_area_silence(&dst_channels[channel].area, 0, frames, plugin->dst_format.format); in mulaw_encode()
230 dst_channels[channel].enabled = 0; in mulaw_encode()
233 dst_channels[channel].enabled = 1; in mulaw_encode()
234 src = src_channels[channel].area.addr + src_channels[channel].area.first / 8; in mulaw_encode()
235 dst = dst_channels[channel].area.addr + dst_channels[channel].area.first / 8; in mulaw_encode()
236 src_step = src_channels[channel].area.step / 8; in mulaw_encode()
237 dst_step = dst_channels[channel].area.step / 8; in mulaw_encode()
239 while (frames1-- > 0) { in mulaw_encode()
256 return -ENXIO; in mulaw_transfer()
261 unsigned int channel; in mulaw_transfer() local
262 for (channel = 0; channel < plugin->src_format.channels; channel++) { in mulaw_transfer()
263 if (snd_BUG_ON(src_channels[channel].area.first % 8 || in mulaw_transfer()
264 src_channels[channel].area.step % 8)) in mulaw_transfer()
265 return -ENXIO; in mulaw_transfer()
266 if (snd_BUG_ON(dst_channels[channel].area.first % 8 || in mulaw_transfer()
267 dst_channels[channel].area.step % 8)) in mulaw_transfer()
268 return -ENXIO; in mulaw_transfer()
274 data = (struct mulaw_priv *)plugin->extra_data; in mulaw_transfer()
275 data->func(plugin, src_channels, dst_channels, frames); in mulaw_transfer()
282 data->cvt_endian = snd_pcm_format_big_endian(format) > 0; in init_data()
284 data->cvt_endian = snd_pcm_format_little_endian(format) > 0; in init_data()
287 data->flip = 0x8000; in init_data()
288 data->native_bytes = snd_pcm_format_physical_width(format) / 8; in init_data()
289 data->copy_bytes = data->native_bytes < 2 ? 1 : 2; in init_data()
291 data->native_ofs = data->native_bytes - data->copy_bytes; in init_data()
292 data->copy_ofs = 2 - data->copy_bytes; in init_data()
295 data->native_ofs = data->native_bytes - in init_data()
296 snd_pcm_format_width(format) / 8; in init_data()
312 return -ENXIO; in snd_pcm_plugin_build_mulaw()
315 if (snd_BUG_ON(src_format->rate != dst_format->rate)) in snd_pcm_plugin_build_mulaw()
316 return -ENXIO; in snd_pcm_plugin_build_mulaw()
317 if (snd_BUG_ON(src_format->channels != dst_format->channels)) in snd_pcm_plugin_build_mulaw()
318 return -ENXIO; in snd_pcm_plugin_build_mulaw()
320 if (dst_format->format == SNDRV_PCM_FORMAT_MU_LAW) { in snd_pcm_plugin_build_mulaw()
324 else if (src_format->format == SNDRV_PCM_FORMAT_MU_LAW) { in snd_pcm_plugin_build_mulaw()
330 return -EINVAL; in snd_pcm_plugin_build_mulaw()
332 if (!snd_pcm_format_linear(format->format)) in snd_pcm_plugin_build_mulaw()
333 return -EINVAL; in snd_pcm_plugin_build_mulaw()
335 err = snd_pcm_plugin_build(plug, "Mu-Law<->linear conversion", in snd_pcm_plugin_build_mulaw()
340 data = (struct mulaw_priv *)plugin->extra_data; in snd_pcm_plugin_build_mulaw()
341 data->func = func; in snd_pcm_plugin_build_mulaw()
342 init_data(data, format->format); in snd_pcm_plugin_build_mulaw()
343 plugin->transfer = mulaw_transfer; in snd_pcm_plugin_build_mulaw()