Lines Matching +full:memcpy +full:- +full:channels
2 * PCM Plug-In shared (kernel/library) code
4 * Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #define snd_pcm_plug_first(plug) ((plug)->runtime->oss.plugin_first)
36 #define snd_pcm_plug_last(plug) ((plug)->runtime->oss.plugin_last)
40 * all "resampling" requests within +-5%
57 if (plugin->stream == SNDRV_PCM_STREAM_PLAYBACK) { in snd_pcm_plugin_alloc()
58 format = &plugin->src_format; in snd_pcm_plugin_alloc()
60 format = &plugin->dst_format; in snd_pcm_plugin_alloc()
62 width = snd_pcm_format_physical_width(format->format); in snd_pcm_plugin_alloc()
65 size = array3_size(frames, format->channels, width); in snd_pcm_plugin_alloc()
68 return -ENOMEM; in snd_pcm_plugin_alloc()
70 return -ENXIO; in snd_pcm_plugin_alloc()
72 if (plugin->buf_frames < frames) { in snd_pcm_plugin_alloc()
73 kvfree(plugin->buf); in snd_pcm_plugin_alloc()
74 plugin->buf = kvzalloc(size, GFP_KERNEL); in snd_pcm_plugin_alloc()
75 plugin->buf_frames = frames; in snd_pcm_plugin_alloc()
77 if (!plugin->buf) { in snd_pcm_plugin_alloc()
78 plugin->buf_frames = 0; in snd_pcm_plugin_alloc()
79 return -ENOMEM; in snd_pcm_plugin_alloc()
81 c = plugin->buf_channels; in snd_pcm_plugin_alloc()
82 if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) { in snd_pcm_plugin_alloc()
83 for (channel = 0; channel < format->channels; channel++, c++) { in snd_pcm_plugin_alloc()
84 c->frames = frames; in snd_pcm_plugin_alloc()
85 c->enabled = 1; in snd_pcm_plugin_alloc()
86 c->wanted = 0; in snd_pcm_plugin_alloc()
87 c->area.addr = plugin->buf; in snd_pcm_plugin_alloc()
88 c->area.first = channel * width; in snd_pcm_plugin_alloc()
89 c->area.step = format->channels * width; in snd_pcm_plugin_alloc()
91 } else if (plugin->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) { in snd_pcm_plugin_alloc()
92 if (snd_BUG_ON(size % format->channels)) in snd_pcm_plugin_alloc()
93 return -EINVAL; in snd_pcm_plugin_alloc()
94 size /= format->channels; in snd_pcm_plugin_alloc()
95 for (channel = 0; channel < format->channels; channel++, c++) { in snd_pcm_plugin_alloc()
96 c->frames = frames; in snd_pcm_plugin_alloc()
97 c->enabled = 1; in snd_pcm_plugin_alloc()
98 c->wanted = 0; in snd_pcm_plugin_alloc()
99 c->area.addr = plugin->buf + (channel * size); in snd_pcm_plugin_alloc()
100 c->area.first = 0; in snd_pcm_plugin_alloc()
101 c->area.step = width; in snd_pcm_plugin_alloc()
104 return -EINVAL; in snd_pcm_plugin_alloc()
112 return -ENXIO; in snd_pcm_plug_alloc()
115 while (plugin->next) { in snd_pcm_plug_alloc()
116 if (plugin->dst_frames) in snd_pcm_plug_alloc()
117 frames = plugin->dst_frames(plugin, frames); in snd_pcm_plug_alloc()
119 return -ENXIO; in snd_pcm_plug_alloc()
120 plugin = plugin->next; in snd_pcm_plug_alloc()
127 while (plugin->prev) { in snd_pcm_plug_alloc()
128 if (plugin->src_frames) in snd_pcm_plug_alloc()
129 frames = plugin->src_frames(plugin, frames); in snd_pcm_plug_alloc()
131 return -ENXIO; in snd_pcm_plug_alloc()
132 plugin = plugin->prev; in snd_pcm_plug_alloc()
144 struct snd_pcm_plugin_channel **channels) in snd_pcm_plugin_client_channels() argument
146 *channels = plugin->buf_channels; in snd_pcm_plugin_client_channels()
158 unsigned int channels; in snd_pcm_plugin_build() local
161 return -ENXIO; in snd_pcm_plugin_build()
163 return -ENXIO; in snd_pcm_plugin_build()
166 return -ENOMEM; in snd_pcm_plugin_build()
167 plugin->name = name; in snd_pcm_plugin_build()
168 plugin->plug = plug; in snd_pcm_plugin_build()
169 plugin->stream = snd_pcm_plug_stream(plug); in snd_pcm_plugin_build()
170 plugin->access = SNDRV_PCM_ACCESS_RW_INTERLEAVED; in snd_pcm_plugin_build()
171 plugin->src_format = *src_format; in snd_pcm_plugin_build()
172 plugin->src_width = snd_pcm_format_physical_width(src_format->format); in snd_pcm_plugin_build()
173 snd_BUG_ON(plugin->src_width <= 0); in snd_pcm_plugin_build()
174 plugin->dst_format = *dst_format; in snd_pcm_plugin_build()
175 plugin->dst_width = snd_pcm_format_physical_width(dst_format->format); in snd_pcm_plugin_build()
176 snd_BUG_ON(plugin->dst_width <= 0); in snd_pcm_plugin_build()
177 if (plugin->stream == SNDRV_PCM_STREAM_PLAYBACK) in snd_pcm_plugin_build()
178 channels = src_format->channels; in snd_pcm_plugin_build()
180 channels = dst_format->channels; in snd_pcm_plugin_build()
181 plugin->buf_channels = kcalloc(channels, sizeof(*plugin->buf_channels), GFP_KERNEL); in snd_pcm_plugin_build()
182 if (plugin->buf_channels == NULL) { in snd_pcm_plugin_build()
184 return -ENOMEM; in snd_pcm_plugin_build()
186 plugin->client_channels = snd_pcm_plugin_client_channels; in snd_pcm_plugin_build()
195 if (plugin->private_free) in snd_pcm_plugin_free()
196 plugin->private_free(plugin); in snd_pcm_plugin_free()
197 kfree(plugin->buf_channels); in snd_pcm_plugin_free()
198 kvfree(plugin->buf); in snd_pcm_plugin_free()
211 plugin_next = plugin->next; in calc_dst_frames()
212 if (check_size && plugin->buf_frames && in calc_dst_frames()
213 frames > plugin->buf_frames) in calc_dst_frames()
214 frames = plugin->buf_frames; in calc_dst_frames()
215 if (plugin->dst_frames) { in calc_dst_frames()
216 frames = plugin->dst_frames(plugin, frames); in calc_dst_frames()
233 plugin_prev = plugin->prev; in calc_src_frames()
234 if (plugin->src_frames) { in calc_src_frames()
235 frames = plugin->src_frames(plugin, frames); in calc_src_frames()
239 if (check_size && plugin->buf_frames && in calc_src_frames()
240 frames > plugin->buf_frames) in calc_src_frames()
241 frames = plugin->buf_frames; in calc_src_frames()
250 return -ENXIO; in snd_pcm_plug_client_size()
258 return -EINVAL; in snd_pcm_plug_client_size()
265 return -ENXIO; in snd_pcm_plug_slave_size()
273 return -EINVAL; in snd_pcm_plug_slave_size()
328 return (__force snd_pcm_format_t)-EINVAL; in snd_pcm_plug_slave_format()
333 unsigned int badness, best = -1; in snd_pcm_plug_slave_format()
334 snd_pcm_format_t best_format = (__force snd_pcm_format_t)-1; in snd_pcm_plug_slave_format()
342 badness = w - width; in snd_pcm_plug_slave_format()
344 badness = width - w + 32; in snd_pcm_plug_slave_format()
355 return (__force snd_pcm_format_t)-EINVAL; in snd_pcm_plug_slave_format()
366 return (__force snd_pcm_format_t)-EINVAL; in snd_pcm_plug_slave_format()
389 dstformat.channels = params_channels(slave_params); in snd_pcm_plug_format_plugins()
392 srcformat.channels = params_channels(params); in snd_pcm_plug_format_plugins()
400 dstformat.channels = params_channels(params); in snd_pcm_plug_format_plugins()
403 srcformat.channels = params_channels(slave_params); in snd_pcm_plug_format_plugins()
410 return -EINVAL; in snd_pcm_plug_format_plugins()
414 pdprintf("srcformat: format=%i, rate=%i, channels=%i\n", in snd_pcm_plug_format_plugins()
417 srcformat.channels); in snd_pcm_plug_format_plugins()
418 pdprintf("dstformat: format=%i, rate=%i, channels=%i\n", in snd_pcm_plug_format_plugins()
421 dstformat.channels); in snd_pcm_plug_format_plugins()
427 return -EINVAL; in snd_pcm_plug_format_plugins()
443 /* channels reduction */ in snd_pcm_plug_format_plugins()
444 if (srcformat.channels > dstformat.channels) { in snd_pcm_plug_format_plugins()
445 tmpformat.channels = dstformat.channels; in snd_pcm_plug_format_plugins()
447 …pdprintf("channels reduction: src=%i, dst=%i returns %i\n", srcformat.channels, tmpformat.channels… in snd_pcm_plug_format_plugins()
509 return -EINVAL; in snd_pcm_plug_format_plugins()
522 /* channels extension */ in snd_pcm_plug_format_plugins()
523 if (srcformat.channels < dstformat.channels) { in snd_pcm_plug_format_plugins()
524 tmpformat.channels = dstformat.channels; in snd_pcm_plug_format_plugins()
526 …pdprintf("channels extension: src=%i, dst=%i returns %i\n", srcformat.channels, tmpformat.channels… in snd_pcm_plug_format_plugins()
538 /* de-interleave */ in snd_pcm_plug_format_plugins()
560 struct snd_pcm_plugin_channel **channels) in snd_pcm_plug_client_channels_buf() argument
569 return -ENXIO; in snd_pcm_plug_client_channels_buf()
572 format = &plugin->src_format; in snd_pcm_plug_client_channels_buf()
575 format = &plugin->dst_format; in snd_pcm_plug_client_channels_buf()
577 v = plugin->buf_channels; in snd_pcm_plug_client_channels_buf()
578 *channels = v; in snd_pcm_plug_client_channels_buf()
579 width = snd_pcm_format_physical_width(format->format); in snd_pcm_plug_client_channels_buf()
582 nchannels = format->channels; in snd_pcm_plug_client_channels_buf()
583 if (snd_BUG_ON(plugin->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED && in snd_pcm_plug_client_channels_buf()
584 format->channels > 1)) in snd_pcm_plug_client_channels_buf()
585 return -ENXIO; in snd_pcm_plug_client_channels_buf()
587 v->frames = count; in snd_pcm_plug_client_channels_buf()
588 v->enabled = 1; in snd_pcm_plug_client_channels_buf()
589 v->wanted = (stream == SNDRV_PCM_STREAM_CAPTURE); in snd_pcm_plug_client_channels_buf()
590 v->area.addr = buf; in snd_pcm_plug_client_channels_buf()
591 v->area.first = channel * width; in snd_pcm_plug_client_channels_buf()
592 v->area.step = nchannels * width; in snd_pcm_plug_client_channels_buf()
608 next = plugin->next; in snd_pcm_plug_write_transfer()
611 if (plugin->dst_frames) { in snd_pcm_plug_write_transfer()
612 frames1 = plugin->dst_frames(plugin, frames); in snd_pcm_plug_write_transfer()
616 err = next->client_channels(next, frames1, &dst_channels); in snd_pcm_plug_write_transfer()
621 if (plugin->src_frames) { in snd_pcm_plug_write_transfer()
622 frames = plugin->src_frames(plugin, frames1); in snd_pcm_plug_write_transfer()
629 pdprintf("write plugin: %s, %li\n", plugin->name, frames); in snd_pcm_plug_write_transfer()
630 frames = plugin->transfer(plugin, src_channels, dst_channels, frames); in snd_pcm_plug_write_transfer()
653 next = plugin->next; in snd_pcm_plug_read_transfer()
655 err = plugin->client_channels(plugin, frames, &dst_channels); in snd_pcm_plug_read_transfer()
662 pdprintf("read plugin: %s, %li\n", plugin->name, frames); in snd_pcm_plug_read_transfer()
663 frames = plugin->transfer(plugin, src_channels, dst_channels, frames); in snd_pcm_plug_read_transfer()
680 if (!dst_area->addr) in snd_pcm_area_silence()
682 dst = dst_area->addr + (dst_area->first + dst_area->step * dst_offset) / 8; in snd_pcm_area_silence()
685 return -EINVAL; in snd_pcm_area_silence()
686 if (dst_area->step == (unsigned int) width && width >= 8) in snd_pcm_area_silence()
690 return -EINVAL; in snd_pcm_area_silence()
691 dst_step = dst_area->step / 8; in snd_pcm_area_silence()
694 int dstbit = dst_area->first % 8; in snd_pcm_area_silence()
695 int dstbit_step = dst_area->step % 8; in snd_pcm_area_silence()
696 while (samples-- > 0) { in snd_pcm_area_silence()
710 while (samples-- > 0) { in snd_pcm_area_silence()
711 memcpy(dst, silence, width); in snd_pcm_area_silence()
726 src = src_area->addr + (src_area->first + src_area->step * src_offset) / 8; in snd_pcm_area_copy()
727 if (!src_area->addr) in snd_pcm_area_copy()
729 dst = dst_area->addr + (dst_area->first + dst_area->step * dst_offset) / 8; in snd_pcm_area_copy()
730 if (!dst_area->addr) in snd_pcm_area_copy()
734 return -EINVAL; in snd_pcm_area_copy()
735 if (src_area->step == (unsigned int) width && in snd_pcm_area_copy()
736 dst_area->step == (unsigned int) width && width >= 8) { in snd_pcm_area_copy()
738 memcpy(dst, src, bytes); in snd_pcm_area_copy()
741 src_step = src_area->step / 8; in snd_pcm_area_copy()
742 dst_step = dst_area->step / 8; in snd_pcm_area_copy()
745 int srcbit = src_area->first % 8; in snd_pcm_area_copy()
746 int srcbit_step = src_area->step % 8; in snd_pcm_area_copy()
747 int dstbit = dst_area->first % 8; in snd_pcm_area_copy()
748 int dstbit_step = dst_area->step % 8; in snd_pcm_area_copy()
749 while (samples-- > 0) { in snd_pcm_area_copy()
774 while (samples-- > 0) { in snd_pcm_area_copy()
775 memcpy(dst, src, width); in snd_pcm_area_copy()