configure.ac: Move OpenAL to Audio Output Plugins (nonstreaming), add header.
[mpd-mk.git] / src / pcm_pack.c
blob9af0ab1edd2e6abf30c7d36128eb06cad739e6f1
1 /*
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.
20 #include "pcm_pack.h"
22 #include <glib.h>
24 static void
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)
30 ++src;
32 *dest++ = *src++;
33 *dest++ = *src++;
34 *dest++ = *src++;
37 void
38 pcm_pack_24(uint8_t *dest, const int32_t *src, unsigned num_samples,
39 bool reverse_endian)
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);
47 dest += 3;
49 } else {
50 while (num_samples-- > 0) {
51 pack_sample(dest, src++, true);
52 dest += 3;
57 static void
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;
66 *dest++ = *src++;
67 *dest++ = *src++;
68 *dest++ = *src;
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;
75 void
76 pcm_unpack_24(int32_t *dest, const uint8_t *src, unsigned num_samples,
77 bool reverse_endian)
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);
85 src += 3;
87 } else {
88 while (num_samples-- > 0) {
89 unpack_sample(dest++, src, true);
90 src += 3;