2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 pack_sample(uint8_t *dest
, const int32_t *src0
, bool reverse_endian
)
27 const uint8_t *src
= (const uint8_t *)src0
;
29 if ((G_BYTE_ORDER
== G_BIG_ENDIAN
) != reverse_endian
)
38 pcm_pack_24(uint8_t *dest
, const int32_t *src
, unsigned num_samples
,
41 /* duplicate loop to help the compiler's optimizer (constant
42 parameter to the pack_sample() inline function) */
44 if (G_LIKELY(!reverse_endian
)) {
45 while (num_samples
-- > 0) {
46 pack_sample(dest
, src
++, false);
50 while (num_samples
-- > 0) {
51 pack_sample(dest
, src
++, true);
58 unpack_sample(int32_t *dest0
, const uint8_t *src
, bool reverse_endian
)
60 uint8_t *dest
= (uint8_t *)dest0
;
62 if ((G_BYTE_ORDER
== G_BIG_ENDIAN
) != reverse_endian
)
63 /* extend the sign bit to the most fourth byte */
64 *dest
++ = *src
& 0x80 ? 0xff : 0x00;
70 if ((G_BYTE_ORDER
== G_LITTLE_ENDIAN
) != reverse_endian
)
71 /* extend the sign bit to the most fourth byte */
72 *dest
++ = *src
& 0x80 ? 0xff : 0x00;
76 pcm_unpack_24(int32_t *dest
, const uint8_t *src
, unsigned num_samples
,
79 /* duplicate loop to help the compiler's optimizer (constant
80 parameter to the unpack_sample() inline function) */
82 if (G_LIKELY(!reverse_endian
)) {
83 while (num_samples
-- > 0) {
84 unpack_sample(dest
++, src
, false);
88 while (num_samples
-- > 0) {
89 unpack_sample(dest
++, src
, true);