7 * Functions to convert PCM to 16-bit signed little-endian stereo
9 * Conversion for 8-bit PCM):
15 * Conversion for 16-bit PCM:
23 * There's no reason to split 8-bit conversion to 2 phases because we need to
24 * use separate buffer for 8->16 conversion anyway.
26 * Conversions for 16-bit stereo can be done in place. 16-bit mono needs to be
27 * converted to stereo so it's worthwhile to split the conversion to 2 phases.
30 static void convert_u8_1ch_to_s16_2ch(char *dst
, const char *src
, int count
)
32 int16_t *d
= (int16_t *)dst
;
33 const uint8_t *s
= (const uint8_t *)src
;
36 for (i
= 0; i
< count
; i
++) {
37 int16_t sample
= s
[i
] << 8;
44 static void convert_s8_1ch_to_s16_2ch(char *dst
, const char *src
, int count
)
46 int16_t *d
= (int16_t *)dst
;
47 const int8_t *s
= (const int8_t *)src
;
50 for (i
= 0; i
< count
; i
++) {
51 int16_t sample
= s
[i
] << 8;
57 static void convert_u8_2ch_to_s16_2ch(char *dst
, const char *src
, int count
)
59 int16_t *d
= (int16_t *)dst
;
60 const int8_t *s
= (const int8_t *)src
;
63 for (i
= 0; i
< count
; i
++) {
64 int16_t sample
= s
[i
] << 8;
70 static void convert_s8_2ch_to_s16_2ch(char *dst
, const char *src
, int count
)
72 int16_t *d
= (int16_t *)dst
;
73 const int8_t *s
= (const int8_t *)src
;
76 for (i
= 0; i
< count
; i
++) {
77 int16_t sample
= s
[i
] << 8;
82 static void convert_u16_le_to_s16_le(char *buf
, int count
)
84 int16_t *b
= (int16_t *)buf
;
87 for (i
= 0; i
< count
; i
++) {
88 int sample
= (uint16_t)b
[i
];
94 static void convert_u16_be_to_s16_le(char *buf
, int count
)
96 int16_t *b
= (int16_t *)buf
;
99 for (i
= 0; i
< count
; i
++) {
103 u
= (u
<< 8) | (u
>> 8);
104 sample
= (int)u
- 32768;
109 static void convert_s16_be_to_s16_le(char *buf
, int count
)
111 int16_t *b
= (int16_t *)buf
;
114 for (i
= 0; i
< count
; i
++) {
115 uint16_t sample
= b
[i
];
116 b
[i
] = (sample
<< 8) | (sample
>> 8);
120 static void convert_16_1ch_to_16_2ch(char *dst
, const char *src
, int count
)
122 int16_t *d
= (int16_t *)dst
;
123 const int16_t *s
= (const int16_t *)src
;
126 for (i
= 0; i
< count
; i
++) {
132 /* index is ((bits >> 2) & 1) | (is_signed << 1) | (channels - 1) */
133 pcm_conv_func pcm_conv
[8] = {
134 convert_u8_1ch_to_s16_2ch
,
135 convert_u8_2ch_to_s16_2ch
,
136 convert_s8_1ch_to_s16_2ch
,
137 convert_s8_2ch_to_s16_2ch
,
139 convert_16_1ch_to_16_2ch
,
141 convert_16_1ch_to_16_2ch
,
145 /* index is ((bits >> 2) & 1) | (is_signed << 1) | bigendian */
146 pcm_conv_in_place_func pcm_conv_in_place
[8] = {
152 convert_u16_le_to_s16_le
,
153 convert_u16_be_to_s16_le
,
155 convert_s16_be_to_s16_le