• Home
  • Raw
  • Download

Lines Matching refs:conv

30 typedef size_t (*channel_converter_t)(struct cras_fmt_conv *conv,
127 static size_t mono_to_stereo(struct cras_fmt_conv *conv, const uint8_t *in, in mono_to_stereo() argument
133 static size_t stereo_to_mono(struct cras_fmt_conv *conv, const uint8_t *in, in stereo_to_mono() argument
139 static size_t mono_to_51(struct cras_fmt_conv *conv, const uint8_t *in, in mono_to_51() argument
144 left = conv->out_fmt.channel_layout[CRAS_CH_FL]; in mono_to_51()
145 right = conv->out_fmt.channel_layout[CRAS_CH_FR]; in mono_to_51()
146 center = conv->out_fmt.channel_layout[CRAS_CH_FC]; in mono_to_51()
151 static size_t stereo_to_51(struct cras_fmt_conv *conv, const uint8_t *in, in stereo_to_51() argument
156 left = conv->out_fmt.channel_layout[CRAS_CH_FL]; in stereo_to_51()
157 right = conv->out_fmt.channel_layout[CRAS_CH_FR]; in stereo_to_51()
158 center = conv->out_fmt.channel_layout[CRAS_CH_FC]; in stereo_to_51()
163 static size_t _51_to_stereo(struct cras_fmt_conv *conv, const uint8_t *in, in _51_to_stereo() argument
169 static size_t stereo_to_quad(struct cras_fmt_conv *conv, const uint8_t *in, in stereo_to_quad() argument
174 front_left = conv->out_fmt.channel_layout[CRAS_CH_FL]; in stereo_to_quad()
175 front_right = conv->out_fmt.channel_layout[CRAS_CH_FR]; in stereo_to_quad()
176 rear_left = conv->out_fmt.channel_layout[CRAS_CH_RL]; in stereo_to_quad()
177 rear_right = conv->out_fmt.channel_layout[CRAS_CH_RR]; in stereo_to_quad()
183 static size_t quad_to_stereo(struct cras_fmt_conv *conv, const uint8_t *in, in quad_to_stereo() argument
188 front_left = conv->in_fmt.channel_layout[CRAS_CH_FL]; in quad_to_stereo()
189 front_right = conv->in_fmt.channel_layout[CRAS_CH_FR]; in quad_to_stereo()
190 rear_left = conv->in_fmt.channel_layout[CRAS_CH_RL]; in quad_to_stereo()
191 rear_right = conv->in_fmt.channel_layout[CRAS_CH_RR]; in quad_to_stereo()
197 static size_t default_all_to_all(struct cras_fmt_conv *conv, const uint8_t *in, in default_all_to_all() argument
202 num_in_ch = conv->in_fmt.num_channels; in default_all_to_all()
203 num_out_ch = conv->out_fmt.num_channels; in default_all_to_all()
205 return s16_default_all_to_all(&conv->out_fmt, num_in_ch, num_out_ch, in, in default_all_to_all()
209 static size_t convert_channels(struct cras_fmt_conv *conv, const uint8_t *in, in convert_channels() argument
215 ch_conv_mtx = conv->ch_conv_mtx; in convert_channels()
216 num_in_ch = conv->in_fmt.num_channels; in convert_channels()
217 num_out_ch = conv->out_fmt.num_channels; in convert_channels()
232 struct cras_fmt_conv *conv; in cras_fmt_conv_create() local
236 conv = calloc(1, sizeof(*conv)); in cras_fmt_conv_create()
237 if (conv == NULL) in cras_fmt_conv_create()
239 conv->in_fmt = *in; in cras_fmt_conv_create()
240 conv->out_fmt = *out; in cras_fmt_conv_create()
241 conv->tmp_buf_frames = max_frames; in cras_fmt_conv_create()
242 conv->pre_linear_resample = pre_linear_resample; in cras_fmt_conv_create()
246 cras_fmt_conv_destroy(&conv); in cras_fmt_conv_create()
252 cras_fmt_conv_destroy(&conv); in cras_fmt_conv_create()
260 conv->num_converters++; in cras_fmt_conv_create()
265 conv->in_format_converter = convert_u8_to_s16le; in cras_fmt_conv_create()
268 conv->in_format_converter = convert_s24le_to_s16le; in cras_fmt_conv_create()
271 conv->in_format_converter = convert_s32le_to_s16le; in cras_fmt_conv_create()
274 conv->in_format_converter = convert_s243le_to_s16le; in cras_fmt_conv_create()
282 conv->num_converters++; in cras_fmt_conv_create()
287 conv->out_format_converter = convert_s16le_to_u8; in cras_fmt_conv_create()
290 conv->out_format_converter = convert_s16le_to_s24le; in cras_fmt_conv_create()
293 conv->out_format_converter = convert_s16le_to_s32le; in cras_fmt_conv_create()
296 conv->out_format_converter = convert_s16le_to_s243le; in cras_fmt_conv_create()
306 conv->num_converters++; in cras_fmt_conv_create()
313 conv->channel_converter = mono_to_stereo; in cras_fmt_conv_create()
315 conv->channel_converter = mono_to_51; in cras_fmt_conv_create()
317 conv->channel_converter = stereo_to_mono; in cras_fmt_conv_create()
319 conv->channel_converter = stereo_to_quad; in cras_fmt_conv_create()
321 conv->channel_converter = quad_to_stereo; in cras_fmt_conv_create()
323 conv->channel_converter = stereo_to_51; in cras_fmt_conv_create()
336 conv->ch_conv_mtx = in cras_fmt_conv_create()
340 if (conv->ch_conv_mtx == NULL) { in cras_fmt_conv_create()
341 cras_fmt_conv_destroy(&conv); in cras_fmt_conv_create()
344 conv->channel_converter = convert_channels; in cras_fmt_conv_create()
346 conv->ch_conv_mtx, in cras_fmt_conv_create()
347 conv->in_fmt.channel_layout); in cras_fmt_conv_create()
349 conv->channel_converter = _51_to_stereo; in cras_fmt_conv_create()
355 conv->channel_converter = default_all_to_all; in cras_fmt_conv_create()
358 conv->num_converters++; in cras_fmt_conv_create()
359 conv->ch_conv_mtx = cras_channel_conv_matrix_create(in, out); in cras_fmt_conv_create()
360 if (conv->ch_conv_mtx == NULL) { in cras_fmt_conv_create()
363 cras_fmt_conv_destroy(&conv); in cras_fmt_conv_create()
366 conv->channel_converter = convert_channels; in cras_fmt_conv_create()
370 conv->num_converters++; in cras_fmt_conv_create()
373 conv->speex_state = in cras_fmt_conv_create()
377 if (conv->speex_state == NULL) { in cras_fmt_conv_create()
381 cras_fmt_conv_destroy(&conv); in cras_fmt_conv_create()
394 conv->num_converters++; in cras_fmt_conv_create()
395 conv->resampler = in cras_fmt_conv_create()
399 if (conv->resampler == NULL) { in cras_fmt_conv_create()
401 cras_fmt_conv_destroy(&conv); in cras_fmt_conv_create()
407 for (i = 0; i < conv->num_converters - 1; i++) { in cras_fmt_conv_create()
408 conv->tmp_bufs[i] = malloc( in cras_fmt_conv_create()
411 if (conv->tmp_bufs[i] == NULL) { in cras_fmt_conv_create()
412 cras_fmt_conv_destroy(&conv); in cras_fmt_conv_create()
417 assert(conv->num_converters <= MAX_NUM_CONVERTERS); in cras_fmt_conv_create()
419 return conv; in cras_fmt_conv_create()
425 struct cras_fmt_conv *conv = *convp; in cras_fmt_conv_destroy() local
427 if (conv->ch_conv_mtx) in cras_fmt_conv_destroy()
428 cras_channel_conv_matrix_destroy(conv->ch_conv_mtx, in cras_fmt_conv_destroy()
429 conv->out_fmt.num_channels); in cras_fmt_conv_destroy()
430 if (conv->speex_state) in cras_fmt_conv_destroy()
431 speex_resampler_destroy(conv->speex_state); in cras_fmt_conv_destroy()
432 if (conv->resampler) in cras_fmt_conv_destroy()
433 linear_resampler_destroy(conv->resampler); in cras_fmt_conv_destroy()
435 free(conv->tmp_bufs[i]); in cras_fmt_conv_destroy()
436 free(conv); in cras_fmt_conv_destroy()
443 struct cras_fmt_conv *conv; in cras_channel_remix_conv_create() local
446 conv = calloc(1, sizeof(*conv)); in cras_channel_remix_conv_create()
447 if (conv == NULL) in cras_channel_remix_conv_create()
449 conv->in_fmt.num_channels = num_channels; in cras_channel_remix_conv_create()
450 conv->out_fmt.num_channels = num_channels; in cras_channel_remix_conv_create()
452 conv->ch_conv_mtx = in cras_channel_remix_conv_create()
457 conv->ch_conv_mtx[out_ch][in_ch] = in cras_channel_remix_conv_create()
460 conv->num_converters = 1; in cras_channel_remix_conv_create()
461 conv->tmp_bufs[0] = malloc(4 * /* width in bytes largest format. */ in cras_channel_remix_conv_create()
463 return conv; in cras_channel_remix_conv_create()
466 void cras_channel_remix_convert(struct cras_fmt_conv *conv, in cras_channel_remix_convert() argument
471 int16_t *tmp = (int16_t *)conv->tmp_bufs[0]; in cras_channel_remix_convert()
482 if (fmt->num_channels != conv->in_fmt.num_channels) in cras_channel_remix_convert()
486 for (ch = 0; ch < conv->in_fmt.num_channels; ch++) in cras_channel_remix_convert()
488 conv->ch_conv_mtx[ch], buf, in cras_channel_remix_convert()
489 conv->in_fmt.num_channels); in cras_channel_remix_convert()
490 for (ch = 0; ch < conv->in_fmt.num_channels; ch++) in cras_channel_remix_convert()
492 buf += conv->in_fmt.num_channels; in cras_channel_remix_convert()
497 cras_fmt_conv_in_format(const struct cras_fmt_conv *conv) in cras_fmt_conv_in_format() argument
499 return &conv->in_fmt; in cras_fmt_conv_in_format()
503 cras_fmt_conv_out_format(const struct cras_fmt_conv *conv) in cras_fmt_conv_out_format() argument
505 return &conv->out_fmt; in cras_fmt_conv_out_format()
508 size_t cras_fmt_conv_in_frames_to_out(struct cras_fmt_conv *conv, in cras_fmt_conv_in_frames_to_out() argument
511 if (!conv) in cras_fmt_conv_in_frames_to_out()
514 if (conv->pre_linear_resample) in cras_fmt_conv_in_frames_to_out()
515 in_frames = linear_resampler_in_frames_to_out(conv->resampler, in cras_fmt_conv_in_frames_to_out()
517 in_frames = cras_frames_at_rate(conv->in_fmt.frame_rate, in_frames, in cras_fmt_conv_in_frames_to_out()
518 conv->out_fmt.frame_rate); in cras_fmt_conv_in_frames_to_out()
519 if (!conv->pre_linear_resample) in cras_fmt_conv_in_frames_to_out()
520 in_frames = linear_resampler_in_frames_to_out(conv->resampler, in cras_fmt_conv_in_frames_to_out()
525 size_t cras_fmt_conv_out_frames_to_in(struct cras_fmt_conv *conv, in cras_fmt_conv_out_frames_to_in() argument
528 if (!conv) in cras_fmt_conv_out_frames_to_in()
530 if (!conv->pre_linear_resample) in cras_fmt_conv_out_frames_to_in()
531 out_frames = linear_resampler_out_frames_to_in(conv->resampler, in cras_fmt_conv_out_frames_to_in()
533 out_frames = cras_frames_at_rate(conv->out_fmt.frame_rate, out_frames, in cras_fmt_conv_out_frames_to_in()
534 conv->in_fmt.frame_rate); in cras_fmt_conv_out_frames_to_in()
535 if (conv->pre_linear_resample) in cras_fmt_conv_out_frames_to_in()
536 out_frames = linear_resampler_out_frames_to_in(conv->resampler, in cras_fmt_conv_out_frames_to_in()
541 void cras_fmt_conv_set_linear_resample_rates(struct cras_fmt_conv *conv, in cras_fmt_conv_set_linear_resample_rates() argument
544 linear_resampler_set_rates(conv->resampler, from, to); in cras_fmt_conv_set_linear_resample_rates()
547 size_t cras_fmt_conv_convert_frames(struct cras_fmt_conv *conv, in cras_fmt_conv_convert_frames() argument
555 unsigned int used_converters = conv->num_converters; in cras_fmt_conv_convert_frames()
560 assert(conv); in cras_fmt_conv_convert_frames()
561 assert(*in_frames <= conv->tmp_buf_frames); in cras_fmt_conv_convert_frames()
563 if (linear_resampler_needed(conv->resampler)) { in cras_fmt_conv_convert_frames()
564 post_linear_resample = !conv->pre_linear_resample; in cras_fmt_conv_convert_frames()
565 pre_linear_resample = conv->pre_linear_resample; in cras_fmt_conv_convert_frames()
569 if (conv->speex_state == NULL) { in cras_fmt_conv_convert_frames()
584 if (!linear_resampler_needed(conv->resampler)) in cras_fmt_conv_convert_frames()
587 buffers[4] = (uint8_t *)conv->tmp_bufs[3]; in cras_fmt_conv_convert_frames()
588 buffers[3] = (uint8_t *)conv->tmp_bufs[2]; in cras_fmt_conv_convert_frames()
589 buffers[2] = (uint8_t *)conv->tmp_bufs[1]; in cras_fmt_conv_convert_frames()
590 buffers[1] = (uint8_t *)conv->tmp_bufs[0]; in cras_fmt_conv_convert_frames()
602 if (conv->speex_state != NULL) { in cras_fmt_conv_convert_frames()
604 conv->in_fmt.frame_rate / in cras_fmt_conv_convert_frames()
605 conv->out_fmt.frame_rate; in cras_fmt_conv_convert_frames()
616 resample_limit = MIN(resample_limit, conv->tmp_buf_frames); in cras_fmt_conv_convert_frames()
618 conv->resampler, buffers[buf_idx], &linear_resample_fr, in cras_fmt_conv_convert_frames()
624 if (conv->in_fmt.format != SND_PCM_FORMAT_S16_LE) { in cras_fmt_conv_convert_frames()
625 conv->in_format_converter(buffers[buf_idx], in cras_fmt_conv_convert_frames()
626 fr_in * conv->in_fmt.num_channels, in cras_fmt_conv_convert_frames()
632 if (conv->channel_converter != NULL) { in cras_fmt_conv_convert_frames()
633 conv->channel_converter(conv, buffers[buf_idx], fr_in, in cras_fmt_conv_convert_frames()
639 if (conv->speex_state != NULL) { in cras_fmt_conv_convert_frames()
644 conv->resampler, out_limit); in cras_fmt_conv_convert_frames()
645 fr_out = cras_frames_at_rate(conv->in_fmt.frame_rate, fr_in, in cras_fmt_conv_convert_frames()
646 conv->out_fmt.frame_rate); in cras_fmt_conv_convert_frames()
656 conv->speex_state, (int16_t *)buffers[buf_idx], &fr_in, in cras_fmt_conv_convert_frames()
663 unsigned resample_limit = MIN(conv->tmp_buf_frames, out_frames); in cras_fmt_conv_convert_frames()
665 conv->resampler, buffers[buf_idx], &linear_resample_fr, in cras_fmt_conv_convert_frames()
671 if (conv->out_fmt.format != SND_PCM_FORMAT_S16_LE) { in cras_fmt_conv_convert_frames()
672 conv->out_format_converter(buffers[buf_idx], in cras_fmt_conv_convert_frames()
673 fr_out * conv->out_fmt.num_channels, in cras_fmt_conv_convert_frames()
690 if (conv->speex_state && (fr_in == 0)) in cras_fmt_conv_convert_frames()
698 int cras_fmt_conversion_needed(const struct cras_fmt_conv *conv) in cras_fmt_conversion_needed() argument
700 return linear_resampler_needed(conv->resampler) || in cras_fmt_conversion_needed()
701 (conv->num_converters > 1); in cras_fmt_conversion_needed()
707 int config_format_converter(struct cras_fmt_conv **conv, in config_format_converter() argument
730 *conv = cras_fmt_conv_create(from, &target, frames, in config_format_converter()
732 if (!*conv) { in config_format_converter()