• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #ifndef CRAS_FMT_CONV_OPS_H_
7 #define CRAS_FMT_CONV_OPS_H_
8 
9 #include <sys/types.h>
10 #include "cras_audio_format.h"
11 
12 /*
13  * Format converter.
14  */
15 void convert_u8_to_s16le(const uint8_t *in, size_t in_samples, uint8_t *out);
16 void convert_s243le_to_s16le(const uint8_t *in, size_t in_samples,
17 			     uint8_t *out);
18 void convert_s24le_to_s16le(const uint8_t *in, size_t in_samples, uint8_t *out);
19 void convert_s32le_to_s16le(const uint8_t *in, size_t in_samples, uint8_t *out);
20 void convert_s16le_to_u8(const uint8_t *in, size_t in_samples, uint8_t *out);
21 void convert_s16le_to_s243le(const uint8_t *in, size_t in_samples,
22 			     uint8_t *out);
23 void convert_s16le_to_s24le(const uint8_t *in, size_t in_samples, uint8_t *out);
24 void convert_s16le_to_s32le(const uint8_t *in, size_t in_samples, uint8_t *out);
25 
26 /*
27  * Channel converter: mono to stereo.
28  */
29 size_t s16_mono_to_stereo(const uint8_t *in, size_t in_frames, uint8_t *out);
30 
31 /*
32  * Channel converter: stereo to mono.
33  */
34 size_t s16_stereo_to_mono(const uint8_t *in, size_t in_frames, uint8_t *out);
35 
36 /*
37  * Channel converter: mono to 5.1 surround.
38  */
39 size_t s16_mono_to_51(size_t left, size_t right, size_t center,
40 		      const uint8_t *in, size_t in_frames, uint8_t *out);
41 
42 /*
43  * Channel converter: stereo to 5.1 surround.
44  */
45 size_t s16_stereo_to_51(size_t left, size_t right, size_t center,
46 			const uint8_t *in, size_t in_frames, uint8_t *out);
47 
48 /*
49  * Channel converter: quad to 5.1 surround.
50  */
51 size_t s16_quad_to_51(size_t font_left, size_t front_right, size_t rear_left,
52 		      size_t rear_right, const uint8_t *in, size_t in_frames,
53 		      uint8_t *out);
54 
55 /*
56  * Channel converter: 5.1 surround to stereo.
57  */
58 size_t s16_51_to_stereo(const uint8_t *in, size_t in_frames, uint8_t *out);
59 
60 /*
61  * Channel converter: 5.1 surround to quad.
62  */
63 size_t s16_51_to_quad(const uint8_t *in, size_t in_frames, uint8_t *out);
64 
65 /*
66  * Channel converter: stereo to quad (front L/R, rear L/R).
67  */
68 size_t s16_stereo_to_quad(size_t front_left, size_t front_right,
69 			  size_t rear_left, size_t rear_right,
70 			  const uint8_t *in, size_t in_frames, uint8_t *out);
71 
72 /*
73  * Channel converter: quad (front L/R, rear L/R) to stereo.
74  */
75 size_t s16_quad_to_stereo(size_t front_left, size_t front_right,
76 			  size_t rear_left, size_t rear_right,
77 			  const uint8_t *in, size_t in_frames, uint8_t *out);
78 
79 /*
80  * Channel converter: N channels to M channels.
81  */
82 size_t s16_default_all_to_all(struct cras_audio_format *out_fmt,
83 			      size_t num_in_ch, size_t num_out_ch,
84 			      const uint8_t *in, size_t in_frames,
85 			      uint8_t *out);
86 
87 /*
88  * Channel converter: N channels to M channels filling min(N,M) channels by
89  * directly copying to the destination.
90  */
91 size_t s16_some_to_some(const struct cras_audio_format *out_fmt,
92 			const size_t num_in_ch, const size_t num_out_ch,
93 			const uint8_t *_in, const size_t frame_count,
94 			uint8_t *_out);
95 
96 /*
97  * Multiplies buffer vector with coefficient vector.
98  */
99 int16_t s16_multiply_buf_with_coef(float *coef, const int16_t *buf,
100 				   size_t size);
101 
102 /*
103  * Channel layout converter.
104  */
105 size_t s16_convert_channels(float **ch_conv_mtx, size_t num_in_ch,
106 			    size_t num_out_ch, const uint8_t *in,
107 			    size_t in_frames, uint8_t *out);
108 
109 #endif /* CRAS_FMT_CONV_OPS_H_ */
110