Skip to content

Latest commit

 

History

History
1592 lines (1445 loc) · 58.8 KB

effect_position.c

File metadata and controls

1592 lines (1445 loc) · 58.8 KB
 
Dec 14, 2001
Dec 14, 2001
2
SDL_mixer: An audio mixer library based on the SDL library
Dec 8, 2008
Dec 8, 2008
3
Copyright (C) 1997-2009 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Jan 15, 2007
Jan 15, 2007
19
This file by Ryan C. Gordon (icculus@icculus.org)
20
21
22
23
24
25
26
27
28
These are some internally supported special effects that use SDL_mixer's
effect callback API. They are meant for speed over quality. :)
*/
/* $Id$ */
#include <stdio.h>
#include <stdlib.h>
Sep 11, 2001
Sep 11, 2001
29
30
#include <string.h>
31
32
#include "SDL.h"
#include "SDL_mixer.h"
Feb 7, 2002
Feb 7, 2002
33
#include "SDL_endian.h"
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#define __MIX_INTERNAL_EFFECT__
#include "effects_internal.h"
/* profile code:
#include <sys/time.h>
#include <unistd.h>
struct timeval tv1;
struct timeval tv2;
gettimeofday(&tv1, NULL);
... do your thing here ...
gettimeofday(&tv2, NULL);
printf("%ld\n", tv2.tv_usec - tv1.tv_usec);
*/
/*
* Positional effects...panning, distance attenuation, etc.
*/
typedef struct _Eff_positionargs
{
volatile float left_f;
volatile float right_f;
volatile Uint8 left_u8;
volatile Uint8 right_u8;
Aug 21, 2004
Aug 21, 2004
63
64
65
66
67
68
69
70
volatile float left_rear_f;
volatile float right_rear_f;
volatile float center_f;
volatile float lfe_f;
volatile Uint8 left_rear_u8;
volatile Uint8 right_rear_u8;
volatile Uint8 center_u8;
volatile Uint8 lfe_u8;
71
72
volatile float distance_f;
volatile Uint8 distance_u8;
Aug 21, 2004
Aug 21, 2004
73
volatile Sint16 room_angle;
74
75
76
77
78
79
80
81
volatile int in_use;
volatile int channels;
} position_args;
static position_args **pos_args_array = NULL;
static position_args *pos_args_global = NULL;
static int position_channels = 0;
Jul 15, 2007
Jul 15, 2007
82
83
84
85
86
87
88
void _Eff_PositionDeinit(void)
{
int i;
for (i = 0; i < position_channels; i++) {
free(pos_args_array[i]);
}
Feb 4, 2008
Feb 4, 2008
89
90
position_channels = 0;
Jul 15, 2007
Jul 15, 2007
91
92
93
94
95
96
97
free(pos_args_global);
pos_args_global = NULL;
free(pos_args_array);
pos_args_array = NULL;
}
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* This just frees up the callback-specific data. */
static void _Eff_PositionDone(int channel, void *udata)
{
if (channel < 0) {
if (pos_args_global != NULL) {
free(pos_args_global);
pos_args_global = NULL;
}
}
else if (pos_args_array[channel] != NULL) {
free(pos_args_array[channel]);
pos_args_array[channel] = NULL;
}
}
static void _Eff_position_u8(int chan, void *stream, int len, void *udata)
{
volatile position_args *args = (volatile position_args *) udata;
Uint8 *ptr = (Uint8 *) stream;
int i;
/*
* if there's only a mono channnel (the only way we wouldn't have
* a len divisible by 2 here), then left_f and right_f are always
* 1.0, and are therefore throwaways.
*/
if (len % sizeof (Uint16) != 0) {
Feb 21, 2003
Feb 21, 2003
127
128
*ptr = (Uint8) (((float) *ptr) * args->distance_f);
ptr++;
129
130
131
len--;
}
Aug 21, 2004
Aug 21, 2004
132
if (args->room_angle == 0)
133
for (i = 0; i < len; i += sizeof (Uint8) * 2) {
Aug 21, 2004
Aug 21, 2004
134
135
136
137
138
139
140
141
142
/* must adjust the sample so that 0 is the center */
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_f) * args->distance_f) + 128);
ptr++;
}
else for (i = 0; i < len; i += sizeof (Uint8) * 2) {
Dec 27, 2002
Dec 27, 2002
143
/* must adjust the sample so that 0 is the center */
Feb 21, 2003
Feb 21, 2003
144
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
Dec 27, 2002
Dec 27, 2002
145
* args->left_f) * args->distance_f) + 128);
Feb 21, 2003
Feb 21, 2003
146
147
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
Dec 27, 2002
Dec 27, 2002
148
* args->right_f) * args->distance_f) + 128);
Feb 21, 2003
Feb 21, 2003
149
ptr++;
150
151
}
}
Aug 21, 2004
Aug 21, 2004
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
static void _Eff_position_u8_c4(int chan, void *stream, int len, void *udata)
{
volatile position_args *args = (volatile position_args *) udata;
Uint8 *ptr = (Uint8 *) stream;
int i;
/*
* if there's only a mono channnel (the only way we wouldn't have
* a len divisible by 2 here), then left_f and right_f are always
* 1.0, and are therefore throwaways.
*/
if (len % sizeof (Uint16) != 0) {
*ptr = (Uint8) (((float) *ptr) * args->distance_f);
ptr++;
len--;
}
if (args->room_angle == 0)
for (i = 0; i < len; i += sizeof (Uint8) * 6) {
/* must adjust the sample so that 0 is the center */
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_rear_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_rear_f) * args->distance_f) + 128);
ptr++;
}
else if (args->room_angle == 90)
for (i = 0; i < len; i += sizeof (Uint8) * 6) {
/* must adjust the sample so that 0 is the center */
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_rear_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_rear_f) * args->distance_f) + 128);
ptr++;
}
else if (args->room_angle == 180)
for (i = 0; i < len; i += sizeof (Uint8) * 6) {
/* must adjust the sample so that 0 is the center */
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_rear_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_rear_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_f) * args->distance_f) + 128);
ptr++;
}
else if (args->room_angle == 270)
for (i = 0; i < len; i += sizeof (Uint8) * 6) {
/* must adjust the sample so that 0 is the center */
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_rear_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_rear_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_f) * args->distance_f) + 128);
ptr++;
}
}
static void _Eff_position_u8_c6(int chan, void *stream, int len, void *udata)
{
volatile position_args *args = (volatile position_args *) udata;
Uint8 *ptr = (Uint8 *) stream;
int i;
/*
* if there's only a mono channnel (the only way we wouldn't have
* a len divisible by 2 here), then left_f and right_f are always
* 1.0, and are therefore throwaways.
*/
if (len % sizeof (Uint16) != 0) {
*ptr = (Uint8) (((float) *ptr) * args->distance_f);
ptr++;
len--;
}
if (args->room_angle == 0)
for (i = 0; i < len; i += sizeof (Uint8) * 6) {
/* must adjust the sample so that 0 is the center */
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_rear_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_rear_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->center_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->lfe_f) * args->distance_f) + 128);
ptr++;
}
else if (args->room_angle == 90)
for (i = 0; i < len; i += sizeof (Uint8) * 6) {
/* must adjust the sample so that 0 is the center */
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_rear_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_rear_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_rear_f) * args->distance_f/2) + 128)
+ (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_f) * args->distance_f/2) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->lfe_f) * args->distance_f) + 128);
ptr++;
}
else if (args->room_angle == 180)
for (i = 0; i < len; i += sizeof (Uint8) * 6) {
/* must adjust the sample so that 0 is the center */
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_rear_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_rear_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_rear_f) * args->distance_f/2) + 128)
+ (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_rear_f) * args->distance_f/2) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->lfe_f) * args->distance_f) + 128);
ptr++;
}
else if (args->room_angle == 270)
for (i = 0; i < len; i += sizeof (Uint8) * 6) {
/* must adjust the sample so that 0 is the center */
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_rear_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_rear_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->right_f) * args->distance_f) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_f) * args->distance_f/2) + 128)
+ (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->left_rear_f) * args->distance_f/2) + 128);
ptr++;
*ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128))
* args->lfe_f) * args->distance_f) + 128);
ptr++;
}
}
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*
* This one runs about 10.1 times faster than the non-table version, with
* no loss in quality. It does, however, require 64k of memory for the
* lookup table. Also, this will only update position information once per
* call; the non-table version always checks the arguments for each sample,
* in case the user has called Mix_SetPanning() or whatnot again while this
* callback is running.
*/
static void _Eff_position_table_u8(int chan, void *stream, int len, void *udata)
{
volatile position_args *args = (volatile position_args *) udata;
Uint8 *ptr = (Uint8 *) stream;
Uint32 *p;
int i;
Uint8 *l = ((Uint8 *) _Eff_volume_table) + (256 * args->left_u8);
Uint8 *r = ((Uint8 *) _Eff_volume_table) + (256 * args->right_u8);
Uint8 *d = ((Uint8 *) _Eff_volume_table) + (256 * args->distance_u8);
Aug 21, 2004
Aug 21, 2004
368
369
370
371
372
if (args->room_angle == 180) {
Uint8 *temp = l;
l = r;
r = temp;
}
373
374
375
376
377
378
/*
* if there's only a mono channnel, then l[] and r[] are always
* volume 255, and are therefore throwaways. Still, we have to
* be sure not to overrun the audio buffer...
*/
while (len % sizeof (Uint32) != 0) {
Feb 21, 2003
Feb 21, 2003
379
380
381
382
383
384
*ptr = d[l[*ptr]];
ptr++;
if (args->channels > 1) {
*ptr = d[r[*ptr]];
ptr++;
}
385
386
387
388
389
390
len -= args->channels;
}
p = (Uint32 *) ptr;
for (i = 0; i < len; i += sizeof (Uint32)) {
Feb 7, 2002
Feb 7, 2002
391
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
Jul 21, 2007
Jul 21, 2007
392
393
394
395
*p = (d[l[(*p & 0xFF000000) >> 24]] << 24) |
(d[r[(*p & 0x00FF0000) >> 16]] << 16) |
(d[l[(*p & 0x0000FF00) >> 8]] << 8) |
(d[r[(*p & 0x000000FF) ]] ) ;
396
#else
Jul 21, 2007
Jul 21, 2007
397
398
399
400
*p = (d[r[(*p & 0xFF000000) >> 24]] << 24) |
(d[l[(*p & 0x00FF0000) >> 16]] << 16) |
(d[r[(*p & 0x0000FF00) >> 8]] << 8) |
(d[l[(*p & 0x000000FF) ]] ) ;
401
#endif
Jul 21, 2007
Jul 21, 2007
402
++p;
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
}
}
static void _Eff_position_s8(int chan, void *stream, int len, void *udata)
{
volatile position_args *args = (volatile position_args *) udata;
Sint8 *ptr = (Sint8 *) stream;
int i;
/*
* if there's only a mono channnel (the only way we wouldn't have
* a len divisible by 2 here), then left_f and right_f are always
* 1.0, and are therefore throwaways.
*/
if (len % sizeof (Sint16) != 0) {
Feb 21, 2003
Feb 21, 2003
419
420
*ptr = (Sint8) (((float) *ptr) * args->distance_f);
ptr++;
421
422
423
len--;
}
Aug 21, 2004
Aug 21, 2004
424
425
426
427
428
429
430
431
if (args->room_angle == 180)
for (i = 0; i < len; i += sizeof (Sint8) * 2) {
*ptr = (Sint8)((((float) *ptr) * args->right_f) * args->distance_f);
ptr++;
*ptr = (Sint8)((((float) *ptr) * args->left_f) * args->distance_f);
ptr++;
}
else
432
for (i = 0; i < len; i += sizeof (Sint8) * 2) {
Feb 21, 2003
Feb 21, 2003
433
434
435
436
*ptr = (Sint8)((((float) *ptr) * args->left_f) * args->distance_f);
ptr++;
*ptr = (Sint8)((((float) *ptr) * args->right_f) * args->distance_f);
ptr++;
437
438
}
}
Aug 21, 2004
Aug 21, 2004
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
static void _Eff_position_s8_c4(int chan, void *stream, int len, void *udata)
{
volatile position_args *args = (volatile position_args *) udata;
Sint8 *ptr = (Sint8 *) stream;
int i;
/*
* if there's only a mono channnel (the only way we wouldn't have
* a len divisible by 2 here), then left_f and right_f are always
* 1.0, and are therefore throwaways.
*/
if (len % sizeof (Sint16) != 0) {
*ptr = (Sint8) (((float) *ptr) * args->distance_f);
ptr++;
len--;
}
for (i = 0; i < len; i += sizeof (Sint8) * 4) {
switch (args->room_angle) {
case 0:
*ptr = (Sint8)((((float) *ptr) * args->left_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->right_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->left_rear_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->right_rear_f) * args->distance_f); ptr++;
break;
case 90:
*ptr = (Sint8)((((float) *ptr) * args->right_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->right_rear_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->left_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->left_rear_f) * args->distance_f); ptr++;
break;
case 180:
*ptr = (Sint8)((((float) *ptr) * args->right_rear_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->left_rear_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->right_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->left_f) * args->distance_f); ptr++;
break;
case 270:
*ptr = (Sint8)((((float) *ptr) * args->left_rear_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->left_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->right_rear_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->right_f) * args->distance_f); ptr++;
break;
}
}
}
static void _Eff_position_s8_c6(int chan, void *stream, int len, void *udata)
{
volatile position_args *args = (volatile position_args *) udata;
Sint8 *ptr = (Sint8 *) stream;
int i;
/*
* if there's only a mono channnel (the only way we wouldn't have
* a len divisible by 2 here), then left_f and right_f are always
* 1.0, and are therefore throwaways.
*/
if (len % sizeof (Sint16) != 0) {
*ptr = (Sint8) (((float) *ptr) * args->distance_f);
ptr++;
len--;
}
for (i = 0; i < len; i += sizeof (Sint8) * 6) {
switch (args->room_angle) {
case 0:
*ptr = (Sint8)((((float) *ptr) * args->left_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->right_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->left_rear_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->right_rear_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->center_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->lfe_f) * args->distance_f); ptr++;
break;
case 90:
*ptr = (Sint8)((((float) *ptr) * args->right_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->right_rear_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->left_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->left_rear_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->right_rear_f) * args->distance_f / 2)
+ (Sint8)((((float) *ptr) * args->right_f) * args->distance_f / 2); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->lfe_f) * args->distance_f); ptr++;
break;
case 180:
*ptr = (Sint8)((((float) *ptr) * args->right_rear_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->left_rear_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->right_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->left_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->right_rear_f) * args->distance_f / 2)
+ (Sint8)((((float) *ptr) * args->left_rear_f) * args->distance_f / 2); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->lfe_f) * args->distance_f); ptr++;
break;
case 270:
*ptr = (Sint8)((((float) *ptr) * args->left_rear_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->left_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->right_rear_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->right_f) * args->distance_f); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->left_f) * args->distance_f / 2)
+ (Sint8)((((float) *ptr) * args->left_rear_f) * args->distance_f / 2); ptr++;
*ptr = (Sint8)((((float) *ptr) * args->lfe_f) * args->distance_f); ptr++;
break;
}
}
}
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
/*
* This one runs about 10.1 times faster than the non-table version, with
* no loss in quality. It does, however, require 64k of memory for the
* lookup table. Also, this will only update position information once per
* call; the non-table version always checks the arguments for each sample,
* in case the user has called Mix_SetPanning() or whatnot again while this
* callback is running.
*/
static void _Eff_position_table_s8(int chan, void *stream, int len, void *udata)
{
volatile position_args *args = (volatile position_args *) udata;
Sint8 *ptr = (Sint8 *) stream;
Uint32 *p;
int i;
Nov 30, 2001
Nov 30, 2001
558
559
Sint8 *l = ((Sint8 *) _Eff_volume_table) + (256 * args->left_u8);
Sint8 *r = ((Sint8 *) _Eff_volume_table) + (256 * args->right_u8);
560
561
Sint8 *d = ((Sint8 *) _Eff_volume_table) + (256 * args->distance_u8);
Aug 21, 2004
Aug 21, 2004
562
563
564
565
566
567
if (args->room_angle == 180) {
Sint8 *temp = l;
l = r;
r = temp;
}
568
569
while (len % sizeof (Uint32) != 0) {
Feb 21, 2003
Feb 21, 2003
570
571
572
573
574
575
*ptr = d[l[*ptr]];
ptr++;
if (args->channels > 1) {
*ptr = d[r[*ptr]];
ptr++;
}
576
577
578
579
580
581
len -= args->channels;
}
p = (Uint32 *) ptr;
for (i = 0; i < len; i += sizeof (Uint32)) {
Feb 7, 2002
Feb 7, 2002
582
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
Jul 21, 2007
Jul 21, 2007
583
584
585
586
*p = (d[l[((Sint16)(Sint8)((*p & 0xFF000000) >> 24))+128]] << 24) |
(d[r[((Sint16)(Sint8)((*p & 0x00FF0000) >> 16))+128]] << 16) |
(d[l[((Sint16)(Sint8)((*p & 0x0000FF00) >> 8))+128]] << 8) |
(d[r[((Sint16)(Sint8)((*p & 0x000000FF) ))+128]] ) ;
587
#else
Jul 21, 2007
Jul 21, 2007
588
589
590
591
*p = (d[r[((Sint16)(Sint8)((*p & 0xFF000000) >> 24))+128]] << 24) |
(d[l[((Sint16)(Sint8)((*p & 0x00FF0000) >> 16))+128]] << 16) |
(d[r[((Sint16)(Sint8)((*p & 0x0000FF00) >> 8))+128]] << 8) |
(d[l[((Sint16)(Sint8)((*p & 0x000000FF) ))+128]] ) ;
592
#endif
Jul 21, 2007
Jul 21, 2007
593
++p;
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
}
}
/* !!! FIXME : Optimize the code for 16-bit samples? */
static void _Eff_position_u16lsb(int chan, void *stream, int len, void *udata)
{
volatile position_args *args = (volatile position_args *) udata;
Uint16 *ptr = (Uint16 *) stream;
int i;
for (i = 0; i < len; i += sizeof (Uint16) * 2) {
Feb 21, 2003
Feb 21, 2003
609
610
Sint16 sampl = (Sint16) (SDL_SwapLE16(*(ptr+0)) - 32768);
Sint16 sampr = (Sint16) (SDL_SwapLE16(*(ptr+1)) - 32768);
Dec 27, 2002
Dec 27, 2002
611
612
613
614
615
616
Uint16 swapl = (Uint16) ((Sint16) (((float) sampl * args->left_f)
* args->distance_f) + 32768);
Uint16 swapr = (Uint16) ((Sint16) (((float) sampr * args->right_f)
* args->distance_f) + 32768);
Aug 21, 2004
Aug 21, 2004
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
if (args->room_angle == 180) {
*(ptr++) = (Uint16) SDL_SwapLE16(swapr);
*(ptr++) = (Uint16) SDL_SwapLE16(swapl);
}
else {
*(ptr++) = (Uint16) SDL_SwapLE16(swapl);
*(ptr++) = (Uint16) SDL_SwapLE16(swapr);
}
}
}
static void _Eff_position_u16lsb_c4(int chan, void *stream, int len, void *udata)
{
volatile position_args *args = (volatile position_args *) udata;
Uint16 *ptr = (Uint16 *) stream;
int i;
for (i = 0; i < len; i += sizeof (Uint16) * 4) {
Sint16 sampl = (Sint16) (SDL_SwapLE16(*(ptr+0)) - 32768);
Sint16 sampr = (Sint16) (SDL_SwapLE16(*(ptr+1)) - 32768);
Sint16 samplr = (Sint16) (SDL_SwapLE16(*(ptr+2)) - 32768);
Sint16 samprr = (Sint16) (SDL_SwapLE16(*(ptr+3)) - 32768);
Uint16 swapl = (Uint16) ((Sint16) (((float) sampl * args->left_f)
* args->distance_f) + 32768);
Uint16 swapr = (Uint16) ((Sint16) (((float) sampr * args->right_f)
* args->distance_f) + 32768);
Jun 23, 2006
Jun 23, 2006
643
Uint16 swaplr = (Uint16) ((Sint16) (((float) samplr * args->left_rear_f)
Aug 21, 2004
Aug 21, 2004
644
* args->distance_f) + 32768);
Jun 23, 2006
Jun 23, 2006
645
Uint16 swaprr = (Uint16) ((Sint16) (((float) samprr * args->right_rear_f)
Aug 21, 2004
Aug 21, 2004
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
* args->distance_f) + 32768);
switch (args->room_angle) {
case 0:
*(ptr++) = (Uint16) SDL_SwapLE16(swapl);
*(ptr++) = (Uint16) SDL_SwapLE16(swapr);
*(ptr++) = (Uint16) SDL_SwapLE16(swaplr);
*(ptr++) = (Uint16) SDL_SwapLE16(swaprr);
break;
case 90:
*(ptr++) = (Uint16) SDL_SwapLE16(swapr);
*(ptr++) = (Uint16) SDL_SwapLE16(swaprr);
*(ptr++) = (Uint16) SDL_SwapLE16(swapl);
*(ptr++) = (Uint16) SDL_SwapLE16(swaplr);
break;
case 180:
*(ptr++) = (Uint16) SDL_SwapLE16(swaprr);
*(ptr++) = (Uint16) SDL_SwapLE16(swaplr);
*(ptr++) = (Uint16) SDL_SwapLE16(swapr);
*(ptr++) = (Uint16) SDL_SwapLE16(swapl);
break;
case 270:
*(ptr++) = (Uint16) SDL_SwapLE16(swaplr);
*(ptr++) = (Uint16) SDL_SwapLE16(swapl);
*(ptr++) = (Uint16) SDL_SwapLE16(swaprr);
*(ptr++) = (Uint16) SDL_SwapLE16(swapr);
break;
}
}
}
static void _Eff_position_u16lsb_c6(int chan, void *stream, int len, void *udata)
{
volatile position_args *args = (volatile position_args *) udata;
Uint16 *ptr = (Uint16 *) stream;
int i;
for (i = 0; i < len; i += sizeof (Uint16) * 6) {
Sint16 sampl = (Sint16) (SDL_SwapLE16(*(ptr+0)) - 32768);
Sint16 sampr = (Sint16) (SDL_SwapLE16(*(ptr+1)) - 32768);
Sint16 samplr = (Sint16) (SDL_SwapLE16(*(ptr+2)) - 32768);
Sint16 samprr = (Sint16) (SDL_SwapLE16(*(ptr+3)) - 32768);
Sint16 sampce = (Sint16) (SDL_SwapLE16(*(ptr+4)) - 32768);
Sint16 sampwf = (Sint16) (SDL_SwapLE16(*(ptr+5)) - 32768);
Jun 23, 2006
Jun 23, 2006
689
Aug 21, 2004
Aug 21, 2004
690
691
692
693
Uint16 swapl = (Uint16) ((Sint16) (((float) sampl * args->left_f)
* args->distance_f) + 32768);
Uint16 swapr = (Uint16) ((Sint16) (((float) sampr * args->right_f)
* args->distance_f) + 32768);
Jun 23, 2006
Jun 23, 2006
694
Uint16 swaplr = (Uint16) ((Sint16) (((float) samplr * args->left_rear_f)
Aug 21, 2004
Aug 21, 2004
695
* args->distance_f) + 32768);
Jun 23, 2006
Jun 23, 2006
696
Uint16 swaprr = (Uint16) ((Sint16) (((float) samprr * args->right_rear_f)
Aug 21, 2004
Aug 21, 2004
697
* args->distance_f) + 32768);
Jun 23, 2006
Jun 23, 2006
698
Uint16 swapce = (Uint16) ((Sint16) (((float) sampce * args->center_f)
Aug 21, 2004
Aug 21, 2004
699
* args->distance_f) + 32768);
Jun 23, 2006
Jun 23, 2006
700
Uint16 swapwf = (Uint16) ((Sint16) (((float) sampwf * args->lfe_f)
Aug 21, 2004
Aug 21, 2004
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
* args->distance_f) + 32768);
switch (args->room_angle) {
case 0:
*(ptr++) = (Uint16) SDL_SwapLE16(swapl);
*(ptr++) = (Uint16) SDL_SwapLE16(swapr);
*(ptr++) = (Uint16) SDL_SwapLE16(swaplr);
*(ptr++) = (Uint16) SDL_SwapLE16(swaprr);
*(ptr++) = (Uint16) SDL_SwapLE16(swapce);
*(ptr++) = (Uint16) SDL_SwapLE16(swapwf);
break;
case 90:
*(ptr++) = (Uint16) SDL_SwapLE16(swapr);
*(ptr++) = (Uint16) SDL_SwapLE16(swaprr);
*(ptr++) = (Uint16) SDL_SwapLE16(swapl);
*(ptr++) = (Uint16) SDL_SwapLE16(swaplr);
*(ptr++) = (Uint16) SDL_SwapLE16(swapr)/2 + (Uint16) SDL_SwapLE16(swaprr)/2;
*(ptr++) = (Uint16) SDL_SwapLE16(swapwf);
break;
case 180:
*(ptr++) = (Uint16) SDL_SwapLE16(swaprr);
*(ptr++) = (Uint16) SDL_SwapLE16(swaplr);
*(ptr++) = (Uint16) SDL_SwapLE16(swapr);
*(ptr++) = (Uint16) SDL_SwapLE16(swapl);
*(ptr++) = (Uint16) SDL_SwapLE16(swaprr)/2 + (Uint16) SDL_SwapLE16(swaplr)/2;
*(ptr++) = (Uint16) SDL_SwapLE16(swapwf);
break;
case 270:
*(ptr++) = (Uint16) SDL_SwapLE16(swaplr);
*(ptr++) = (Uint16) SDL_SwapLE16(swapl);
*(ptr++) = (Uint16) SDL_SwapLE16(swaprr);
*(ptr++) = (Uint16) SDL_SwapLE16(swapr);
*(ptr++) = (Uint16) SDL_SwapLE16(swapl)/2 + (Uint16) SDL_SwapLE16(swaplr)/2;
*(ptr++) = (Uint16) SDL_SwapLE16(swapwf);
break;
}
737
738
739
740
741
742
743
744
745
746
}
}
static void _Eff_position_s16lsb(int chan, void *stream, int len, void *udata)
{
/* 16 signed bits (lsb) * 2 channels. */
volatile position_args *args = (volatile position_args *) udata;
Sint16 *ptr = (Sint16 *) stream;
int i;
Aug 21, 2004
Aug 21, 2004
747
748
749
750
751
752
753
#if 0
if (len % (sizeof(Sint16) * 2)) {
fprintf(stderr,"Not an even number of frames! len=%d\n", len);
return;
}
#endif
754
for (i = 0; i < len; i += sizeof (Sint16) * 2) {
Nov 10, 2003
Nov 10, 2003
755
Sint16 swapl = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+0))) *
756
args->left_f) * args->distance_f);
Nov 10, 2003
Nov 10, 2003
757
Sint16 swapr = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+1))) *
758
args->right_f) * args->distance_f);
Aug 21, 2004
Aug 21, 2004
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
if (args->room_angle == 180) {
*(ptr++) = (Sint16) SDL_SwapLE16(swapr);
*(ptr++) = (Sint16) SDL_SwapLE16(swapl);
}
else {
*(ptr++) = (Sint16) SDL_SwapLE16(swapl);
*(ptr++) = (Sint16) SDL_SwapLE16(swapr);
}
}
}
static void _Eff_position_s16lsb_c4(int chan, void *stream, int len, void *udata)
{
/* 16 signed bits (lsb) * 4 channels. */
volatile position_args *args = (volatile position_args *) udata;
Sint16 *ptr = (Sint16 *) stream;
int i;
for (i = 0; i < len; i += sizeof (Sint16) * 4) {
Sint16 swapl = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+0))) *
args->left_f) * args->distance_f);
Sint16 swapr = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+1))) *
args->right_f) * args->distance_f);
Sint16 swaplr = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+1))) *
args->left_rear_f) * args->distance_f);
Sint16 swaprr = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+2))) *
args->right_rear_f) * args->distance_f);
switch (args->room_angle) {
case 0:
*(ptr++) = (Sint16) SDL_SwapLE16(swapl);
*(ptr++) = (Sint16) SDL_SwapLE16(swapr);
*(ptr++) = (Sint16) SDL_SwapLE16(swaplr);
*(ptr++) = (Sint16) SDL_SwapLE16(swaprr);
break;
case 90:
*(ptr++) = (Sint16) SDL_SwapLE16(swapr);
*(ptr++) = (Sint16) SDL_SwapLE16(swaprr);
*(ptr++) = (Sint16) SDL_SwapLE16(swapl);
*(ptr++) = (Sint16) SDL_SwapLE16(swaplr);
break;
case 180:
*(ptr++) = (Sint16) SDL_SwapLE16(swaprr);
*(ptr++) = (Sint16) SDL_SwapLE16(swaplr);
*(ptr++) = (Sint16) SDL_SwapLE16(swapr);
*(ptr++) = (Sint16) SDL_SwapLE16(swapl);
break;
case 270:
*(ptr++) = (Sint16) SDL_SwapLE16(swaplr);
*(ptr++) = (Sint16) SDL_SwapLE16(swapl);
*(ptr++) = (Sint16) SDL_SwapLE16(swaprr);
*(ptr++) = (Sint16) SDL_SwapLE16(swapr);
break;
}
}
}
static void _Eff_position_s16lsb_c6(int chan, void *stream, int len, void *udata)
{
/* 16 signed bits (lsb) * 6 channels. */
volatile position_args *args = (volatile position_args *) udata;
Sint16 *ptr = (Sint16 *) stream;
int i;
for (i = 0; i < len; i += sizeof (Sint16) * 6) {
Sint16 swapl = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+0))) *
args->left_f) * args->distance_f);
Sint16 swapr = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+1))) *
args->right_f) * args->distance_f);
Sint16 swaplr = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+2))) *
args->left_rear_f) * args->distance_f);
Sint16 swaprr = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+3))) *
args->right_rear_f) * args->distance_f);
Sint16 swapce = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+4))) *
args->center_f) * args->distance_f);
Sint16 swapwf = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+5))) *
args->lfe_f) * args->distance_f);
switch (args->room_angle) {
case 0:
*(ptr++) = (Sint16) SDL_SwapLE16(swapl);
*(ptr++) = (Sint16) SDL_SwapLE16(swapr);
*(ptr++) = (Sint16) SDL_SwapLE16(swaplr);
*(ptr++) = (Sint16) SDL_SwapLE16(swaprr);
*(ptr++) = (Sint16) SDL_SwapLE16(swapce);
*(ptr++) = (Sint16) SDL_SwapLE16(swapwf);
break;
case 90:
*(ptr++) = (Sint16) SDL_SwapLE16(swapr);
*(ptr++) = (Sint16) SDL_SwapLE16(swaprr);
*(ptr++) = (Sint16) SDL_SwapLE16(swapl);
*(ptr++) = (Sint16) SDL_SwapLE16(swaplr);
*(ptr++) = (Sint16) SDL_SwapLE16(swapr)/2 + (Sint16) SDL_SwapLE16(swaprr)/2;
*(ptr++) = (Sint16) SDL_SwapLE16(swapwf);
break;
case 180:
*(ptr++) = (Sint16) SDL_SwapLE16(swaprr);
*(ptr++) = (Sint16) SDL_SwapLE16(swaplr);
*(ptr++) = (Sint16) SDL_SwapLE16(swapr);
*(ptr++) = (Sint16) SDL_SwapLE16(swapl);
*(ptr++) = (Sint16) SDL_SwapLE16(swaprr)/2 + (Sint16) SDL_SwapLE16(swaplr)/2;
*(ptr++) = (Sint16) SDL_SwapLE16(swapwf);
break;
case 270:
*(ptr++) = (Sint16) SDL_SwapLE16(swaplr);
*(ptr++) = (Sint16) SDL_SwapLE16(swapl);
*(ptr++) = (Sint16) SDL_SwapLE16(swaprr);
*(ptr++) = (Sint16) SDL_SwapLE16(swapr);
*(ptr++) = (Sint16) SDL_SwapLE16(swapl)/2 + (Sint16) SDL_SwapLE16(swaplr)/2;
*(ptr++) = (Sint16) SDL_SwapLE16(swapwf);
break;
}
868
869
870
871
872
873
874
875
876
877
878
}
}
static void _Eff_position_u16msb(int chan, void *stream, int len, void *udata)
{
/* 16 signed bits (lsb) * 2 channels. */
volatile position_args *args = (volatile position_args *) udata;
Uint16 *ptr = (Uint16 *) stream;
int i;
for (i = 0; i < len; i += sizeof (Sint16) * 2) {
Feb 21, 2003
Feb 21, 2003
879
880
Sint16 sampl = (Sint16) (SDL_SwapBE16(*(ptr+0)) - 32768);
Sint16 sampr = (Sint16) (SDL_SwapBE16(*(ptr+1)) - 32768);
Dec 27, 2002
Dec 27, 2002
881
882
883
884
885
886
Uint16 swapl = (Uint16) ((Sint16) (((float) sampl * args->left_f)
* args->distance_f) + 32768);
Uint16 swapr = (Uint16) ((Sint16) (((float) sampr * args->right_f)
* args->distance_f) + 32768);
Aug 21, 2004
Aug 21, 2004
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if (args->room_angle == 180) {
*(ptr++) = (Uint16) SDL_SwapBE16(swapr);
*(ptr++) = (Uint16) SDL_SwapBE16(swapl);
}
else {
*(ptr++) = (Uint16) SDL_SwapBE16(swapl);
*(ptr++) = (Uint16) SDL_SwapBE16(swapr);
}
}
}
static void _Eff_position_u16msb_c4(int chan, void *stream, int len, void *udata)
{
/* 16 signed bits (lsb) * 4 channels. */
volatile position_args *args = (volatile position_args *) udata;
Uint16 *ptr = (Uint16 *) stream;
int i;
for (i = 0; i < len; i += sizeof (Sint16) * 4) {
Sint16 sampl = (Sint16) (SDL_SwapBE16(*(ptr+0)) - 32768);
Sint16 sampr = (Sint16) (SDL_SwapBE16(*(ptr+1)) - 32768);
Sint16 samplr = (Sint16) (SDL_SwapBE16(*(ptr+2)) - 32768);
Sint16 samprr = (Sint16) (SDL_SwapBE16(*(ptr+3)) - 32768);
Uint16 swapl = (Uint16) ((Sint16) (((float) sampl * args->left_f)
* args->distance_f) + 32768);
Uint16 swapr = (Uint16) ((Sint16) (((float) sampr * args->right_f)
* args->distance_f) + 32768);
Uint16 swaplr = (Uint16) ((Sint16) (((float) samplr * args->left_rear_f)
* args->distance_f) + 32768);
Uint16 swaprr = (Uint16) ((Sint16) (((float) samprr * args->right_rear_f)
* args->distance_f) + 32768);
switch (args->room_angle) {
case 0:
*(ptr++) = (Uint16) SDL_SwapBE16(swapl);
*(ptr++) = (Uint16) SDL_SwapBE16(swapr);
*(ptr++) = (Uint16) SDL_SwapBE16(swaplr);
*(ptr++) = (Uint16) SDL_SwapBE16(swaprr);
break;
case 90:
*(ptr++) = (Uint16) SDL_SwapBE16(swapr);
*(ptr++) = (Uint16) SDL_SwapBE16(swaprr);
*(ptr++) = (Uint16) SDL_SwapBE16(swapl);
*(ptr++) = (Uint16) SDL_SwapBE16(swaplr);
break;
case 180:
*(ptr++) = (Uint16) SDL_SwapBE16(swaprr);
*(ptr++) = (Uint16) SDL_SwapBE16(swaplr);
*(ptr++) = (Uint16) SDL_SwapBE16(swapr);
*(ptr++) = (Uint16) SDL_SwapBE16(swapl);
break;
case 270:
*(ptr++) = (Uint16) SDL_SwapBE16(swaplr);
*(ptr++) = (Uint16) SDL_SwapBE16(swapl);
*(ptr++) = (Uint16) SDL_SwapBE16(swaprr);
*(ptr++) = (Uint16) SDL_SwapBE16(swapr);
break;
}
}
}
static void _Eff_position_u16msb_c6(int chan, void *stream, int len, void *udata)
{
/* 16 signed bits (lsb) * 6 channels. */
volatile position_args *args = (volatile position_args *) udata;
Uint16 *ptr = (Uint16 *) stream;
int i;
for (i = 0; i < len; i += sizeof (Sint16) * 6) {
Sint16 sampl = (Sint16) (SDL_SwapBE16(*(ptr+0)) - 32768);
Sint16 sampr = (Sint16) (SDL_SwapBE16(*(ptr+1)) - 32768);
Sint16 samplr = (Sint16) (SDL_SwapBE16(*(ptr+2)) - 32768);
Sint16 samprr = (Sint16) (SDL_SwapBE16(*(ptr+3)) - 32768);
Sint16 sampce = (Sint16) (SDL_SwapBE16(*(ptr+4)) - 32768);
Sint16 sampwf = (Sint16) (SDL_SwapBE16(*(ptr+5)) - 32768);
Uint16 swapl = (Uint16) ((Sint16) (((float) sampl * args->left_f)
* args->distance_f) + 32768);
Uint16 swapr = (Uint16) ((Sint16) (((float) sampr * args->right_f)
* args->distance_f) + 32768);
Uint16 swaplr = (Uint16) ((Sint16) (((float) samplr * args->left_rear_f)
* args->distance_f) + 32768);
Uint16 swaprr = (Uint16) ((Sint16) (((float) samprr * args->right_rear_f)
* args->distance_f) + 32768);
Uint16 swapce = (Uint16) ((Sint16) (((float) sampce * args->center_f)
* args->distance_f) + 32768);
Uint16 swapwf = (Uint16) ((Sint16) (((float) sampwf * args->lfe_f)
* args->distance_f) + 32768);
switch (args->room_angle) {
case 0:
*(ptr++) = (Uint16) SDL_SwapBE16(swapl);
*(ptr++) = (Uint16) SDL_SwapBE16(swapr);
*(ptr++) = (Uint16) SDL_SwapBE16(swaplr);
*(ptr++) = (Uint16) SDL_SwapBE16(swaprr);
*(ptr++) = (Uint16) SDL_SwapBE16(swapce);
*(ptr++) = (Uint16) SDL_SwapBE16(swapwf);
break;
case 90:
*(ptr++) = (Uint16) SDL_SwapBE16(swapr);
*(ptr++) = (Uint16) SDL_SwapBE16(swaprr);
*(ptr++) = (Uint16) SDL_SwapBE16(swapl);
*(ptr++) = (Uint16) SDL_SwapBE16(swaplr);
*(ptr++) = (Uint16) SDL_SwapBE16(swapr)/2 + (Uint16) SDL_SwapBE16(swaprr)/2;
*(ptr++) = (Uint16) SDL_SwapBE16(swapwf);
break;
case 180:
*(ptr++) = (Uint16) SDL_SwapBE16(swaprr);
*(ptr++) = (Uint16) SDL_SwapBE16(swaplr);
*(ptr++) = (Uint16) SDL_SwapBE16(swapr);
*(ptr++) = (Uint16) SDL_SwapBE16(swapl);
*(ptr++) = (Uint16) SDL_SwapBE16(swaprr)/2 + (Uint16) SDL_SwapBE16(swaplr)/2;
*(ptr++) = (Uint16) SDL_SwapBE16(swapwf);
break;
case 270: