annotate libaudacious/xconvert.c @ 1756:dd78822cd1d8 trunk

[svn] Do not try write NULL into a gconf key, convert it to "" first.
author chainsaw
date Sat, 23 Sep 2006 13:50:17 -0700
parents 0a73d1faeb4e
children 6f1346ce2764
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * Copyright (C) 2001-2003 Haavard Kvaalen <havardk@xmms.org>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 * Licensed under GNU LGPL version 2.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 #include "config.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 #include <stdlib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 #include <audacious/plugin.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 #include "xconvert.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 #define IS_BIG_ENDIAN (G_BYTE_ORDER==G_BIG_ENDIAN)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 struct buffer {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 void *buffer;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 int size;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 struct xmms_convert_buffers {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 struct buffer format_buffer, stereo_buffer, freq_buffer;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 struct xmms_convert_buffers *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 xmms_convert_buffers_new(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 return g_malloc0(sizeof(struct xmms_convert_buffers));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 static void *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 convert_get_buffer(struct buffer *buffer, size_t size)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 {
625
0a73d1faeb4e [svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents: 0
diff changeset
32 if (size > 0 && size <= (size_t)buffer->size)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 return buffer->buffer;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 buffer->size = size;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 buffer->buffer = g_realloc(buffer->buffer, size);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 return buffer->buffer;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 xmms_convert_buffers_free(struct xmms_convert_buffers *buf)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 convert_get_buffer(&buf->format_buffer, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 convert_get_buffer(&buf->stereo_buffer, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 convert_get_buffer(&buf->freq_buffer, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 xmms_convert_buffers_destroy(struct xmms_convert_buffers *buf)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 if (!buf)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 xmms_convert_buffers_free(buf);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 g_free(buf);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 convert_swap_endian(struct xmms_convert_buffers *buf, void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 guint16 *ptr = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 for (i = 0; i < length; i += 2, ptr++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 *ptr = GUINT16_SWAP_LE_BE(*ptr);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 return i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 convert_swap_sign_and_endian_to_native(struct
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 xmms_convert_buffers
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 *buf, void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 guint16 *ptr = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 for (i = 0; i < length; i += 2, ptr++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 *ptr = GUINT16_SWAP_LE_BE(*ptr) ^ 1 << 15;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 return i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 convert_swap_sign_and_endian_to_alien(struct
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 guint16 *ptr = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 for (i = 0; i < length; i += 2, ptr++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 *ptr = GUINT16_SWAP_LE_BE(*ptr ^ 1 << 15);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 return i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 convert_swap_sign16(struct xmms_convert_buffers *buf, void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 gint16 *ptr = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 for (i = 0; i < length; i += 2, ptr++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 *ptr ^= 1 << 15;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 return i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 convert_swap_sign8(struct xmms_convert_buffers *buf, void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 gint8 *ptr = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 for (i = 0; i < length; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 *ptr++ ^= 1 << 7;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 return i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 convert_to_8_native_endian(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 gint8 *output = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 gint16 *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 for (i = 0; i < length / 2; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 *output++ = *input++ >> 8;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 return i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 convert_to_8_native_endian_swap_sign(struct xmms_convert_buffers
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 *buf, void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 gint8 *output = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 gint16 *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 for (i = 0; i < length / 2; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 *output++ = (*input++ >> 8) ^ (1 << 7);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 return i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 convert_to_8_alien_endian(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 gint8 *output = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 gint16 *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 for (i = 0; i < length / 2; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 *output++ = *input++ & 0xff;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 return i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 convert_to_8_alien_endian_swap_sign(struct xmms_convert_buffers
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 *buf, void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 gint8 *output = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 gint16 *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 for (i = 0; i < length / 2; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 *output++ = (*input++ & 0xff) ^ (1 << 7);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 return i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 convert_to_16_native_endian(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 guint8 *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 guint16 *output;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 *data = convert_get_buffer(&buf->format_buffer, length * 2);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 output = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 for (i = 0; i < length; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 *output++ = *input++ << 8;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 return i * 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 convert_to_16_native_endian_swap_sign(struct
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 guint8 *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 guint16 *output;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 *data = convert_get_buffer(&buf->format_buffer, length * 2);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 output = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 for (i = 0; i < length; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 *output++ = (*input++ << 8) ^ (1 << 15);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 return i * 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 convert_to_16_alien_endian(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 guint8 *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206 guint16 *output;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 *data = convert_get_buffer(&buf->format_buffer, length * 2);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209 output = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 for (i = 0; i < length; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211 *output++ = *input++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213 return i * 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 convert_to_16_alien_endian_swap_sign(struct xmms_convert_buffers
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218 *buf, void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 guint8 *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 guint16 *output;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 *data = convert_get_buffer(&buf->format_buffer, length * 2);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224 output = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 for (i = 0; i < length; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226 *output++ = *input++ ^ (1 << 7);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228 return i * 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 static AFormat
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 unnativize(AFormat fmt)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234 if (fmt == FMT_S16_NE) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 if (IS_BIG_ENDIAN)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 return FMT_S16_BE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238 return FMT_S16_LE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240 if (fmt == FMT_U16_NE) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 if (IS_BIG_ENDIAN)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 return FMT_U16_BE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 return FMT_U16_LE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246 return fmt;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 convert_func_t
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 xmms_convert_get_func(AFormat output, AFormat input)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252 output = unnativize(output);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 input = unnativize(input);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255 if (output == input)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 if ((output == FMT_U16_BE && input == FMT_U16_LE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 (output == FMT_U16_LE && input == FMT_U16_BE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 (output == FMT_S16_BE && input == FMT_S16_LE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 (output == FMT_S16_LE && input == FMT_S16_BE))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 return convert_swap_endian;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 if ((output == FMT_U16_BE && input == FMT_S16_BE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 (output == FMT_U16_LE && input == FMT_S16_LE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266 (output == FMT_S16_BE && input == FMT_U16_BE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267 (output == FMT_S16_LE && input == FMT_U16_LE))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 return convert_swap_sign16;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 if ((IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271 ((output == FMT_U16_BE && input == FMT_S16_LE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 (output == FMT_S16_BE && input == FMT_U16_LE))) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273 (!IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274 ((output == FMT_U16_LE && input == FMT_S16_BE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275 (output == FMT_S16_LE && input == FMT_U16_BE))))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 return convert_swap_sign_and_endian_to_native;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 if ((!IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279 ((output == FMT_U16_BE && input == FMT_S16_LE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280 (output == FMT_S16_BE && input == FMT_U16_LE))) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 (IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 ((output == FMT_U16_LE && input == FMT_S16_BE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283 (output == FMT_S16_LE && input == FMT_U16_BE))))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284 return convert_swap_sign_and_endian_to_alien;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286 if ((IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 ((output == FMT_U8 && input == FMT_U16_BE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 (output == FMT_S8 && input == FMT_S16_BE))) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 (!IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 ((output == FMT_U8 && input == FMT_U16_LE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 (output == FMT_S8 && input == FMT_S16_LE))))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 return convert_to_8_native_endian;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 if ((IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295 ((output == FMT_U8 && input == FMT_S16_BE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 (output == FMT_S8 && input == FMT_U16_BE))) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 (!IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 ((output == FMT_U8 && input == FMT_S16_LE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 (output == FMT_S8 && input == FMT_U16_LE))))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 return convert_to_8_native_endian_swap_sign;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 if ((!IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 ((output == FMT_U8 && input == FMT_U16_BE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 (output == FMT_S8 && input == FMT_S16_BE))) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 (IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 ((output == FMT_U8 && input == FMT_U16_LE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 (output == FMT_S8 && input == FMT_S16_LE))))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308 return convert_to_8_alien_endian;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 if ((!IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 ((output == FMT_U8 && input == FMT_S16_BE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 (output == FMT_S8 && input == FMT_U16_BE))) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313 (IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 ((output == FMT_U8 && input == FMT_S16_LE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315 (output == FMT_S8 && input == FMT_U16_LE))))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 return convert_to_8_alien_endian_swap_sign;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318 if ((output == FMT_U8 && input == FMT_S8) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319 (output == FMT_S8 && input == FMT_U8))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 return convert_swap_sign8;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322 if ((IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 ((output == FMT_U16_BE && input == FMT_U8) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 (output == FMT_S16_BE && input == FMT_S8))) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 (!IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 ((output == FMT_U16_LE && input == FMT_U8) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327 (output == FMT_S16_LE && input == FMT_S8))))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 return convert_to_16_native_endian;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 if ((IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 ((output == FMT_U16_BE && input == FMT_S8) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 (output == FMT_S16_BE && input == FMT_U8))) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333 (!IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 ((output == FMT_U16_LE && input == FMT_S8) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335 (output == FMT_S16_LE && input == FMT_U8))))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336 return convert_to_16_native_endian_swap_sign;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 if ((!IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339 ((output == FMT_U16_BE && input == FMT_U8) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340 (output == FMT_S16_BE && input == FMT_S8))) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341 (IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342 ((output == FMT_U16_LE && input == FMT_U8) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343 (output == FMT_S16_LE && input == FMT_S8))))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 return convert_to_16_alien_endian;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346 if ((!IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347 ((output == FMT_U16_BE && input == FMT_S8) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348 (output == FMT_S16_BE && input == FMT_U8))) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349 (IS_BIG_ENDIAN &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 ((output == FMT_U16_LE && input == FMT_S8) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351 (output == FMT_S16_LE && input == FMT_U8))))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 return convert_to_16_alien_endian_swap_sign;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354 g_warning("Translation needed, but not available.\n"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355 "Input: %d; Output %d.", input, output);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 convert_mono_to_stereo(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361 void **data, int length, int b16)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364 void *outbuf = convert_get_buffer(&buf->stereo_buffer, length * 2);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366 if (b16) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 guint16 *output = outbuf, *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368 for (i = 0; i < length / 2; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369 *output++ = *input;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370 *output++ = *input;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371 input++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
374 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
375 guint8 *output = outbuf, *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
376 for (i = 0; i < length; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
377 *output++ = *input;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
378 *output++ = *input;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
379 input++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
380 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
381 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
382 *data = outbuf;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
383
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
384 return length * 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
385 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
386
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
387 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
388 convert_mono_to_stereo_8(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
389 void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
390 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
391 return convert_mono_to_stereo(buf, data, length, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
392 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
393
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
394 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
395 convert_mono_to_stereo_16(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
396 void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
397 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
398 return convert_mono_to_stereo(buf, data, length, TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
399 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
400
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
401 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
402 convert_stereo_to_mono_u8(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
403 void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
404 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
405 guint8 *output = *data, *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
406 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
407 for (i = 0; i < length / 2; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
408 guint16 tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
409 tmp = *input++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
410 tmp += *input++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
411 *output++ = tmp / 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
412 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
413 return length / 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
414 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
415 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
416 convert_stereo_to_mono_s8(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
417 void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
418 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
419 gint8 *output = *data, *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
420 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
421 for (i = 0; i < length / 2; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
422 gint16 tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
423 tmp = *input++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
424 tmp += *input++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
425 *output++ = tmp / 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
426 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
427 return length / 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
428 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
429 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
430 convert_stereo_to_mono_u16le(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
431 void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
432 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
433 guint16 *output = *data, *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
434 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
435 for (i = 0; i < length / 4; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
436 guint32 tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
437 guint16 stmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
438 tmp = GUINT16_FROM_LE(*input);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
439 input++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
440 tmp += GUINT16_FROM_LE(*input);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
441 input++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
442 stmp = tmp / 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
443 *output++ = GUINT16_TO_LE(stmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
444 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
445 return length / 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
446 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
447
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
448 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
449 convert_stereo_to_mono_u16be(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
450 void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
451 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
452 guint16 *output = *data, *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
453 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
454 for (i = 0; i < length / 4; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
455 guint32 tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
456 guint16 stmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
457 tmp = GUINT16_FROM_BE(*input);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
458 input++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
459 tmp += GUINT16_FROM_BE(*input);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
460 input++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
461 stmp = tmp / 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
462 *output++ = GUINT16_TO_BE(stmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
463 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
464 return length / 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
465 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
466
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
467 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
468 convert_stereo_to_mono_s16le(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
469 void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
470 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
471 gint16 *output = *data, *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
472 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
473 for (i = 0; i < length / 4; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
474 gint32 tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
475 gint16 stmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
476 tmp = GINT16_FROM_LE(*input);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
477 input++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
478 tmp += GINT16_FROM_LE(*input);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
479 input++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
480 stmp = tmp / 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
481 *output++ = GINT16_TO_LE(stmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
482 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
483 return length / 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
484 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
485
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
486 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
487 convert_stereo_to_mono_s16be(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
488 void **data, int length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
489 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
490 gint16 *output = *data, *input = *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
491 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
492 for (i = 0; i < length / 4; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
493 gint32 tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
494 gint16 stmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
495 tmp = GINT16_FROM_BE(*input);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
496 input++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
497 tmp += GINT16_FROM_BE(*input);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
498 input++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
499 stmp = tmp / 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
500 *output++ = GINT16_TO_BE(stmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
501 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
502 return length / 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
503 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
504
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
505 convert_channel_func_t
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
506 xmms_convert_get_channel_func(AFormat fmt, int output, int input)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
507 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
508 fmt = unnativize(fmt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
509
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
510 if (output == input)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
511 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
512
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
513 if (input == 1 && output == 2)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
514 switch (fmt) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
515 case FMT_U8:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
516 case FMT_S8:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
517 return convert_mono_to_stereo_8;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
518 case FMT_U16_LE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
519 case FMT_U16_BE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
520 case FMT_S16_LE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
521 case FMT_S16_BE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
522 return convert_mono_to_stereo_16;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
523 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
524 g_warning("Unknown format: %d" "No conversion available.", fmt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
525 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
526 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
527 if (input == 2 && output == 1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
528 switch (fmt) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
529 case FMT_U8:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
530 return convert_stereo_to_mono_u8;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
531 case FMT_S8:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
532 return convert_stereo_to_mono_s8;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
533 case FMT_U16_LE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
534 return convert_stereo_to_mono_u16le;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
535 case FMT_U16_BE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
536 return convert_stereo_to_mono_u16be;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
537 case FMT_S16_LE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
538 return convert_stereo_to_mono_s16le;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
539 case FMT_S16_BE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
540 return convert_stereo_to_mono_s16be;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
541 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
542 g_warning("Unknown format: %d. "
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
543 "No conversion available.", fmt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
544 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
545
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
546 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
547
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
548 g_warning("Input has %d channels, soundcard uses %d channels\n"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
549 "No conversion is available", input, output);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
550 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
551 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
552
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
553
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
554 #define RESAMPLE_STEREO(sample_type, bswap) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
555 const int shift = sizeof (sample_type); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
556 int i, in_samples, out_samples, x, delta; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
557 sample_type *inptr = *data, *outptr; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
558 guint nlen = (((length >> shift) * ofreq) / ifreq); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
559 void *nbuf; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
560 if (nlen == 0) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
561 return 0; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
562 nlen <<= shift; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
563 if (bswap) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
564 convert_swap_endian(NULL, data, length); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
565 nbuf = convert_get_buffer(&buf->freq_buffer, nlen); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
566 outptr = nbuf; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
567 in_samples = length >> shift; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
568 out_samples = nlen >> shift; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
569 delta = (in_samples << 12) / out_samples; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
570 for (x = 0, i = 0; i < out_samples; i++) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
571 { \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
572 int x1, frac; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
573 x1 = (x >> 12) << 12; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
574 frac = x - x1; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
575 *outptr++ = \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
576 ((inptr[(x1 >> 12) << 1] * \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
577 ((1<<12) - frac) + \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
578 inptr[((x1 >> 12) + 1) << 1] * \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
579 frac) >> 12); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
580 *outptr++ = \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
581 ((inptr[((x1 >> 12) << 1) + 1] * \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
582 ((1<<12) - frac) + \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
583 inptr[(((x1 >> 12) + 1) << 1) + 1] * \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
584 frac) >> 12); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
585 x += delta; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
586 } \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
587 if (bswap) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
588 convert_swap_endian(NULL, &nbuf, nlen); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
589 *data = nbuf; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
590 return nlen; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
591
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
592
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
593 #define RESAMPLE_MONO(sample_type, bswap) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
594 const int shift = sizeof (sample_type) - 1; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
595 int i, x, delta, in_samples, out_samples; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
596 sample_type *inptr = *data, *outptr; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
597 guint nlen = (((length >> shift) * ofreq) / ifreq); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
598 void *nbuf; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
599 if (nlen == 0) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
600 return 0; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
601 nlen <<= shift; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
602 if (bswap) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
603 convert_swap_endian(NULL, data, length); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
604 nbuf = convert_get_buffer(&buf->freq_buffer, nlen); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
605 outptr = nbuf; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
606 in_samples = length >> shift; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
607 out_samples = nlen >> shift; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
608 delta = ((length >> shift) << 12) / out_samples; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
609 for (x = 0, i = 0; i < out_samples; i++) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
610 { \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
611 int x1, frac; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
612 x1 = (x >> 12) << 12; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
613 frac = x - x1; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
614 *outptr++ = \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
615 ((inptr[x1 >> 12] * ((1<<12) - frac) + \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
616 inptr[(x1 >> 12) + 1] * frac) >> 12); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
617 x += delta; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
618 } \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
619 if (bswap) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
620 convert_swap_endian(NULL, &nbuf, nlen); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
621 *data = nbuf; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
622 return nlen; \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
623
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
624 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
625 convert_resample_stereo_s16ne(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
626 void **data, int length, int ifreq, int ofreq)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
627 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
628 RESAMPLE_STEREO(gint16, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
629 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
630
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
631 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
632 convert_resample_stereo_s16ae(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
633 void **data, int length, int ifreq, int ofreq)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
634 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
635 RESAMPLE_STEREO(gint16, TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
636 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
637
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
638 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
639 convert_resample_stereo_u16ne(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
640 void **data, int length, int ifreq, int ofreq)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
641 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
642 RESAMPLE_STEREO(guint16, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
643 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
644
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
645 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
646 convert_resample_stereo_u16ae(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
647 void **data, int length, int ifreq, int ofreq)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
648 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
649 RESAMPLE_STEREO(guint16, TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
650 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
651
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
652 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
653 convert_resample_mono_s16ne(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
654 void **data, int length, int ifreq, int ofreq)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
655 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
656 RESAMPLE_MONO(gint16, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
657 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
658
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
659 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
660 convert_resample_mono_s16ae(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
661 void **data, int length, int ifreq, int ofreq)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
662 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
663 RESAMPLE_MONO(gint16, TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
664 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
665
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
666 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
667 convert_resample_mono_u16ne(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
668 void **data, int length, int ifreq, int ofreq)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
669 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
670 RESAMPLE_MONO(guint16, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
671 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
672
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
673 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
674 convert_resample_mono_u16ae(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
675 void **data, int length, int ifreq, int ofreq)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
676 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
677 RESAMPLE_MONO(guint16, TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
678 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
679
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
680 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
681 convert_resample_stereo_u8(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
682 void **data, int length, int ifreq, int ofreq)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
683 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
684 RESAMPLE_STEREO(guint8, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
685 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
686
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
687 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
688 convert_resample_mono_u8(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
689 void **data, int length, int ifreq, int ofreq)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
690 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
691 RESAMPLE_MONO(guint8, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
692 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
693
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
694 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
695 convert_resample_stereo_s8(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
696 void **data, int length, int ifreq, int ofreq)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
697 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
698 RESAMPLE_STEREO(gint8, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
699 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
700
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
701 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
702 convert_resample_mono_s8(struct xmms_convert_buffers *buf,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
703 void **data, int length, int ifreq, int ofreq)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
704 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
705 RESAMPLE_MONO(gint8, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
706 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
707
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
708
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
709 convert_freq_func_t
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
710 xmms_convert_get_frequency_func(AFormat fmt, int channels)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
711 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
712 fmt = unnativize(fmt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
713 g_message("fmt %d, channels: %d", fmt, channels);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
714
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
715 if (channels < 1 || channels > 2) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
716 g_warning("Unsupported number of channels: %d. "
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
717 "Resample function not available", channels);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
718 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
719 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
720 if ((IS_BIG_ENDIAN && fmt == FMT_U16_BE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
721 (!IS_BIG_ENDIAN && fmt == FMT_U16_LE)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
722 if (channels == 1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
723 return convert_resample_mono_u16ne;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
724 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
725 return convert_resample_stereo_u16ne;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
726 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
727 if ((IS_BIG_ENDIAN && fmt == FMT_S16_BE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
728 (!IS_BIG_ENDIAN && fmt == FMT_S16_LE)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
729 if (channels == 1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
730 return convert_resample_mono_s16ne;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
731 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
732 return convert_resample_stereo_s16ne;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
733 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
734 if ((!IS_BIG_ENDIAN && fmt == FMT_U16_BE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
735 (IS_BIG_ENDIAN && fmt == FMT_U16_LE)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
736 if (channels == 1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
737 return convert_resample_mono_u16ae;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
738 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
739 return convert_resample_stereo_u16ae;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
740 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
741 if ((!IS_BIG_ENDIAN && fmt == FMT_S16_BE) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
742 (IS_BIG_ENDIAN && fmt == FMT_S16_LE)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
743 if (channels == 1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
744 return convert_resample_mono_s16ae;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
745 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
746 return convert_resample_stereo_s16ae;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
747 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
748 if (fmt == FMT_U8) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
749 if (channels == 1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
750 return convert_resample_mono_u8;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
751 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
752 return convert_resample_stereo_u8;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
753 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
754 if (fmt == FMT_S8) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
755 if (channels == 1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
756 return convert_resample_mono_s8;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
757 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
758 return convert_resample_stereo_s8;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
759 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
760 g_warning("Resample function not available" "Format %d.", fmt);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
761 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
762 }