2 * Copyright 2005 Timo Hirvonen
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 * Functions to convert PCM to 16-bit signed little-endian stereo
27 * Conversion for 8-bit PCM):
33 * Conversion for 16-bit PCM:
41 * There's no reason to split 8-bit conversion to 2 phases because we need to
42 * use separate buffer for 8->16 conversion anyway.
44 * Conversions for 16-bit stereo can be done in place. 16-bit mono needs to be
45 * converted to stereo so it's worthwhile to split the conversion to 2 phases.
48 void convert_u8_1ch_to_s16_2ch(char *dst
, const char *src
, int count
)
50 int16_t *d
= (int16_t *)dst
;
51 const uint8_t *s
= (const uint8_t *)src
;
54 for (i
= 0; i
< count
; i
++) {
55 int16_t sample
= s
[i
] << 8;
62 void convert_s8_1ch_to_s16_2ch(char *dst
, const char *src
, int count
)
64 int16_t *d
= (int16_t *)dst
;
65 const int8_t *s
= (const int8_t *)src
;
68 for (i
= 0; i
< count
; i
++) {
69 int16_t sample
= s
[i
] << 8;
75 void convert_u8_2ch_to_s16_2ch(char *dst
, const char *src
, int count
)
77 int16_t *d
= (int16_t *)dst
;
78 const int8_t *s
= (const int8_t *)src
;
81 for (i
= 0; i
< count
; i
++) {
82 int16_t sample
= s
[i
] << 8;
88 void convert_s8_2ch_to_s16_2ch(char *dst
, const char *src
, int count
)
90 int16_t *d
= (int16_t *)dst
;
91 const int8_t *s
= (const int8_t *)src
;
94 for (i
= 0; i
< count
; i
++) {
95 int16_t sample
= s
[i
] << 8;
100 void convert_u16_le_to_s16_le(char *buf
, int count
)
102 int16_t *b
= (int16_t *)buf
;
105 for (i
= 0; i
< count
; i
++) {
106 int sample
= (uint16_t)b
[i
];
112 void convert_u16_be_to_s16_le(char *buf
, int count
)
114 int16_t *b
= (int16_t *)buf
;
117 for (i
= 0; i
< count
; i
++) {
121 u
= (u
<< 8) | (u
>> 8);
122 sample
= (int)u
- 32768;
127 void convert_s16_be_to_s16_le(char *buf
, int count
)
129 int16_t *b
= (int16_t *)buf
;
132 for (i
= 0; i
< count
; i
++) {
133 uint16_t sample
= b
[i
];
134 b
[i
] = (sample
<< 8) | (sample
>> 8);
138 void convert_16_1ch_to_16_2ch(char *dst
, const char *src
, int count
)
140 int16_t *d
= (int16_t *)dst
;
141 const int16_t *s
= (const int16_t *)src
;
144 for (i
= 0; i
< count
; i
++) {