annotate Plugins/Output/arts/convert.c @ 1457:bbd5869239e5 trunk

[svn] RockLight visualization plugin ported from XMMS.
author chainsaw
date Wed, 02 Aug 2006 14:26:56 -0700
parents e9509e909193
children f12d7e208b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
810
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
1 /*
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
2 * Copyright (C) 2001-2003 Haavard Kvaalen
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
3 *
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
7 * (at your option) any later version.
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
8 *
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
12 * GNU General Public License for more details.
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
13 *
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
15 * along with this program; if not, write to the Free Software
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
17 */
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
18
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
19 #if defined(HAVE_CONFIG_H)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
20 #include "config.h"
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
21 #endif
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
22
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
23 #include "audacious/plugin.h"
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
24 #include <glib.h>
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
25
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
26 #ifdef WORDS_BIGENDIAN
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
27 # define IS_BIG_ENDIAN TRUE
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
28 #else
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
29 # define IS_BIG_ENDIAN FALSE
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
30 #endif
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
31
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
32
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
33
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
34 static int convert_swap_endian(void **data, int length)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
35 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
36 guint16 *ptr = *data;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
37 int i;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
38 for (i = 0; i < length; i += 2, ptr++)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
39 *ptr = GUINT16_SWAP_LE_BE(*ptr);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
40
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
41 return i;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
42 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
43
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
44 static int convert_swap_sign_and_endian_to_native(void **data, int length)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
45 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
46 guint16 *ptr = *data;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
47 int i;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
48 for (i = 0; i < length; i += 2, ptr++)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
49 *ptr = GUINT16_SWAP_LE_BE(*ptr) ^ 1 << 15;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
50
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
51 return i;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
52 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
53
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
54 static int convert_swap_sign_and_endian_to_alien(void **data, int length)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
55 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
56 guint16 *ptr = *data;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
57 int i;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
58 for (i = 0; i < length; i += 2, ptr++)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
59 *ptr = GUINT16_SWAP_LE_BE(*ptr ^ 1 << 15);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
60
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
61 return i;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
62 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
63
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
64 static int convert_swap_sign16(void **data, int length)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
65 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
66 gint16 *ptr = *data;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
67 int i;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
68 for (i = 0; i < length; i += 2, ptr++)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
69 *ptr ^= 1 << 15;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
70
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
71 return i;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
72 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
73
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
74 static int convert_swap_sign8(void **data, int length)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
75 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
76 gint8 *ptr = *data;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
77 int i;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
78 for (i = 0; i < length; i++)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
79 *ptr++ ^= 1 << 7;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
80
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
81 return i;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
82 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
83
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
84 int (*arts_get_convert_func(int input))(void **, int)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
85 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
86 if (input == FMT_S16_NE)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
87 input = IS_BIG_ENDIAN ? FMT_S16_BE : FMT_S16_LE;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
88 else if (input == FMT_U16_NE)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
89 input = IS_BIG_ENDIAN ? FMT_U16_BE : FMT_U16_LE;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
90
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
91 if (input == FMT_S16_LE || input == FMT_U8)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
92 return NULL;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
93
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
94 if (input == FMT_S16_BE)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
95 return convert_swap_endian;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
96
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
97 if (input == FMT_U16_LE)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
98 return convert_swap_sign16;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
99
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
100 if (!IS_BIG_ENDIAN && input == FMT_U16_BE)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
101 return convert_swap_sign_and_endian_to_native;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
102
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
103 if (IS_BIG_ENDIAN && input == FMT_U16_BE)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
104 return convert_swap_sign_and_endian_to_alien;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
105
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
106 if (input == FMT_S8)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
107 return convert_swap_sign8;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
108
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
109 g_warning("Translation needed, but not available.\n"
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
110 "Input: %d.", input);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
111 return NULL;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
112 }