Mercurial > SDL_sound_CoreAudio
annotate alt_audio_convert.c @ 507:7f11a82e918e stable-1.0
Whoops, didn't actually fix the gcc4 warnings (backport from devbranch).
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 17 Dec 2005 18:50:17 +0000 |
parents | 636796aed4e2 |
children | 45ee760a6f5a |
rev | line source |
---|---|
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
1 /* |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
2 * Extended Audio Converter for SDL (Simple DirectMedia Layer) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
3 * Copyright (C) 2002 Frank Ranostaj |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
4 * Institute of Applied Physik |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
5 * Johann Wolfgang Goethe-Universität |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
6 * Frankfurt am Main, Germany |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
7 * |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
8 * This library is free software; you can redistribute it and/or |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
9 * modify it under the terms of the GNU Library General Public |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
10 * License as published by the Free Software Foundation; either |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
11 * version 2 of the License, or (at your option) any later version. |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
12 * |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
13 * This library is distributed in the hope that it will be useful, |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
16 * Library General Public License for more details. |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
17 * |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
18 * You should have received a copy of the GNU Library General Public |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
19 * License along with this library; if not, write to the Free |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
21 * |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
22 * Frank Ranostaj |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
23 * ranostaj@stud.uni-frankfurt.de |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
24 * |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
25 * (This code blatantly abducted for SDL_sound. Thanks, Frank! --ryan.) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
26 */ |
338 | 27 |
465
636796aed4e2
Build/packaging fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
441
diff
changeset
|
28 #if HAVE_CONFIG_H |
636796aed4e2
Build/packaging fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
441
diff
changeset
|
29 # include <config.h> |
636796aed4e2
Build/packaging fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
441
diff
changeset
|
30 #endif |
636796aed4e2
Build/packaging fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
441
diff
changeset
|
31 |
636796aed4e2
Build/packaging fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
441
diff
changeset
|
32 #if SOUND_USE_ALTCVT |
636796aed4e2
Build/packaging fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
441
diff
changeset
|
33 |
338 | 34 #include "alt_audio_convert.h" |
35 #include <math.h> | |
36 | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
37 /* just to make sure this is defined... */ |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
38 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
39 #ifndef min |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
40 #define min(x, y) ( ((x) < (y)) ? (x) : (y) ) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
41 #endif |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
42 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
43 #ifndef max |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
44 #define max(x, y) ( ((x) > (y)) ? (x) : (y) ) |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
45 #endif |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
46 |
366
eda146d666d1
More patches from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
365
diff
changeset
|
47 #ifndef abs |
eda146d666d1
More patches from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
365
diff
changeset
|
48 #define abs(x) ( ((x) > (0)) ? (x) : -(x) ) |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
49 #endif |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
50 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
51 |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
52 /* some macros for "parsing" format */ |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
53 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
54 #define IS_8BIT(x) ((x).format & 0x0008) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
55 #define IS_16BIT(x) ((x).format & 0x0010) |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
56 #define IS_FLOAT(x) ((x).format & 0x0020) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
57 #define IS_SIGNED(x) ((x).format & 0x8000) |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
58 #define IS_SYSENDIAN(x) ((~AUDIO_U16SYS ^ (x).format) & 0x1000) |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
59 #define SDL_MSB_POSITION_IN_SHORT ((0x1000 & AUDIO_U16SYS)>>12) |
338 | 60 |
61 | |
62 /*-------------------------------------------------------------------------*/ | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
63 /* the purpose of the RateConverterBuffer is to provide a continous storage |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
64 for head and tail of the (sample)-buffer. This allows a simple and |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
65 perfomant implemantation of the sample rate converters. Depending of the |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
66 operation mode, two layouts for the RateConverterBuffer.inbuffer are |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
67 possible: |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
68 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
69 in the Loop Mode: |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
70 ... T-4 T-3 T-2 T-1 H+0 H+1 H+2 H+3 H+4 ... |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
71 | |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
72 linp, finp |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
73 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
74 in the Single Mode (non Loop): |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
75 ... T-4 T-3 T-2 T-1 0 0 0 ... 0 0 0 H+0 H+1 H+2 H+3 H+4 ... |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
76 | | |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
77 linp finp |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
78 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
79 The RateConverterBuffer allows an accurate attack and decay of the |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
80 filters in the rate Converters. |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
81 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
82 The pointer finp are actually shifted against the depicted position so |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
83 that on the first invocation of the rate converter the input of the |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
84 filter is nearly complete in the zero region, only one input value is |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
85 used. After the calculation of the first output value, the pointer are |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
86 incremented or decremented depending on down or up conversion and the |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
87 first two input value are taken into account. This procedure repeats |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
88 until the filter has processed all zeroes. The distance of the pointer |
366
eda146d666d1
More patches from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
365
diff
changeset
|
89 movement is stored in flength, always positive. |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
90 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
91 Further a pointer cinp to the sample buffer itself is stored. The pointer |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
92 to the sample buffer is shifted too, so that on the first use of this |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
93 pointer the filter is complete in the sample buffer. The pointer moves |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
94 over the sample buffer until it reaches the other end. The distance of |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
95 the movement is stored in clength. |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
96 |
366
eda146d666d1
More patches from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
365
diff
changeset
|
97 Finally the decay of the filter is done by linp and llength like finp, |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
98 flength, but in reverse order. |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
99 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
100 buffer denotes the start or the end of the output buffer, depending |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
101 on direction of the rate conversion. |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
102 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
103 All pointer and length referring the buffer as Sint16. All length |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
104 are refering to the input buffer */ |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
105 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
106 typedef struct |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
107 { |
366
eda146d666d1
More patches from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
365
diff
changeset
|
108 Sint16 inbuffer[24*_fsize]; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
109 Sint16 *finp, *cinp, *linp; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
110 int flength, clength, llength; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
111 Sint16 *buffer; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
112 VarFilter *filter; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
113 } RateConverterBuffer; |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
114 |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
115 typedef struct |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
116 { |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
117 Sint16 carry; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
118 Sint16 pos; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
119 } RateAux; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
120 |
338 | 121 |
122 /* Mono (1 channel ) */ | |
123 #define Suffix(x) x##1 | |
124 #include "filter_templates.h" | |
125 #undef Suffix | |
126 | |
127 /* Stereo (2 channel ) */ | |
128 #define Suffix(x) x##2 | |
129 #include "filter_templates.h" | |
130 #undef Suffix | |
131 | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
132 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
133 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
134 int Sound_estimateBufferSize( Sound_AudioCVT *Data, int size ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
135 { |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
136 size *= Data->len_mult; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
137 size += Data->len_add; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
138 return ( size + 3 ) & -4; /* force Size in multipels of 4 Byte */ |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
139 } |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
140 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
141 /*-------------------------------------------------------------------------*/ |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
142 int Sound_AltConvertAudio( Sound_AudioCVT *Data, |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
143 Uint8* buffer, int length, int mode ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
144 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
145 AdapterC Temp; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
146 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
147 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
148 /* Make sure there's a converter */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
149 if( Data == NULL ) { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
150 SDL_SetError("No converter given"); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
151 return(-1); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
152 } |
338 | 153 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
154 /* Make sure there's data to convert */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
155 if( buffer == NULL ) { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
156 SDL_SetError("No buffer allocated for conversion"); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
157 return(-1); |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
158 } |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
159 |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
160 if( length < 0 ) { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
161 SDL_SetError("Lenght < 0"); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
162 return(-1); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
163 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
164 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
165 /* Set up the conversion and go! */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
166 Temp.buffer = buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
167 Temp.mode = mode; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
168 Temp.filter = &Data->filter; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
169 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
170 for( i = 0; Data->adapter[i] != NULL; i++ ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
171 length = (*Data->adapter[i])( Temp, length); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
172 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
173 return length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
174 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
175 |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
176 int Sound_ConvertAudio( Sound_AudioCVT *Data ) |
338 | 177 { |
371 | 178 int length; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
179 /* !!! FIXME: Try the looping stuff under certain circumstances? --ryan. */ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
180 length = Sound_AltConvertAudio( Data, Data->buf, Data->len, 0 ); |
371 | 181 Data->len_cvt = length; |
182 return length; | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
183 } |
338 | 184 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
185 /*-------------------------------------------------------------------------*/ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
186 static int expand8BitTo16BitSys( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
187 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
188 int i; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
189 Uint8* inp = Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
190 Uint16* buffer = (Uint16*)Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
191 for( i = length + 1; --i; ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
192 buffer[i] = inp[i]<<8; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
193 return 2*length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
194 } |
338 | 195 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
196 static int expand8BitTo16BitWrong( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
197 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
198 int i; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
199 Uint8* inp = Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
200 Uint16* buffer = (Uint16*)Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
201 for( i = length + 1; --i; ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
202 buffer[i] = inp[i]; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
203 return 2*length; |
338 | 204 } |
205 | |
206 /*-------------------------------------------------------------------------*/ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
207 static int expand16BitToFloat( AdapterC Data, int length ) |
338 | 208 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
209 int i; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
210 Sint16* inp = (Sint16*)Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
211 float* buffer = (float*)Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
212 for( i = length>>1 + 1; --i; ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
213 buffer[i] = inp[i]*(1./32767); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
214 return 2*length; |
338 | 215 } |
216 | |
217 /*-------------------------------------------------------------------------*/ | |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
218 static int swapBytes( AdapterC Data, int length ) |
338 | 219 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
220 /* |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
221 * !!! FIXME !!! |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
222 * |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
223 * |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
224 * Use the faster SDL-Macros to swap |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
225 * - Frank |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
226 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
227 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
228 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
229 Uint16 a,b; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
230 Uint16* buffer = (Uint16*) Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
231 for( i = length>>1 + 1; --i; ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
232 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
233 a = b = buffer[i]; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
234 buffer[i] = ( a << 8 ) | ( b >> 8 ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
235 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
236 return length; |
338 | 237 } |
238 | |
239 /*-------------------------------------------------------------------------*/ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
240 static int cutFloatTo16Bit( AdapterC Data, int length ) |
338 | 241 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
242 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
243 float* inp = (float*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
244 Sint16* buffer = (Sint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
245 length>>=2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
246 for( i = 0; i < length; i++ ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
247 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
248 if( inp[i] > 1. ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
249 buffer[i] = 32767; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
250 else if( inp[i] < -1. ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
251 buffer[i] = -32768; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
252 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
253 buffer[i] = 32767 * inp[i]; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
254 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
255 return 2*length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
256 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
257 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
258 /*-------------------------------------------------------------------------*/ |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
259 static int cut16BitTo8Bit( AdapterC Data, int length, int off ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
260 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
261 int i; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
262 Uint8* inp = Data.buffer + off; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
263 Uint8* buffer = Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
264 length >>= 1; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
265 for( i = 0; i < length; i++ ) |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
266 buffer[i] = inp[2*i]; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
267 return length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
268 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
269 |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
270 static int cut16BitSysTo8Bit( AdapterC Data, int length ) |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
271 { |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
272 return cut16BitTo8Bit( Data, length, SDL_MSB_POSITION_IN_SHORT ); |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
273 } |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
274 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
275 static int cut16BitWrongTo8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
276 { |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
277 return cut16BitTo8Bit( Data, length, 1-SDL_MSB_POSITION_IN_SHORT ); |
338 | 278 } |
279 | |
280 /*-------------------------------------------------------------------------*/ | |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
281 /* poor mans mmx :-) */ |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
282 static int changeSigned( AdapterC Data, int length, Uint32 XOR ) |
338 | 283 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
284 int i; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
285 Uint32* buffer = (Uint32*) Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
286 for( i = ( length + 7 ) >> 2; --i; ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
287 buffer[i] ^= XOR; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
288 return length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
289 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
290 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
291 static int changeSigned16BitSys( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
292 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
293 return changeSigned( Data, length, 0x80008000 ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
294 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
295 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
296 static int changeSigned16BitWrong( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
297 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
298 return changeSigned( Data, length, 0x00800080 ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
299 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
300 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
301 static int changeSigned8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
302 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
303 return changeSigned( Data, length, 0x80808080 ); |
338 | 304 } |
305 | |
306 /*-------------------------------------------------------------------------*/ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
307 static int convertStereoToMonoS16Bit( AdapterC Data, int length ) |
338 | 308 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
309 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
310 Sint16* buffer = (Sint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
311 Sint16* src = (Sint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
312 length >>= 2; |
371 | 313 for( i = 0; i < length; i++, src+=2 ) |
314 buffer[i] = ((int) src[0] + src[1] ) >> 1; | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
315 return 2*length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
316 } |
338 | 317 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
318 static int convertStereoToMonoU16Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
319 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
320 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
321 Uint16* buffer = (Uint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
322 Uint16* src = (Uint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
323 length >>= 2; |
371 | 324 for( i = 0; i < length; i++, src+=2 ) |
325 buffer[i] = ((int) src[0] + src[1] ) >> 1; | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
326 return 2*length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
327 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
328 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
329 static int convertStereoToMonoS8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
330 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
331 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
332 Sint8* buffer = (Sint8*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
333 Sint8* src = (Sint8*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
334 length >>= 1; |
371 | 335 for( i = 0; i < length; i++, src+=2 ) |
336 buffer[i] = ((int) src[0] + src[1] ) >> 1; | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
337 return length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
338 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
339 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
340 static int convertStereoToMonoU8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
341 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
342 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
343 Uint8* buffer = (Uint8*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
344 Uint8* src = (Uint8*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
345 length >>= 1; |
371 | 346 for( i = 0; i < length; i++, src+=2 ) |
347 buffer[i] = ((int) src[0] + src[1] ) >> 1; | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
348 return length; |
338 | 349 } |
350 | |
351 /*-------------------------------------------------------------------------*/ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
352 static int convertMonoToStereo16Bit( AdapterC Data, int length ) |
338 | 353 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
354 int i; |
421 | 355 Uint16* buffer; |
356 Uint16* dst; | |
357 | |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
358 length >>=1; |
421 | 359 buffer = (Uint16*)Data.buffer - 1; |
360 dst = (Uint16*)Data.buffer + 2*length - 2; | |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
361 for( i = length + 1; --i; dst-=2 ) |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
362 dst[0] = dst[1] = buffer[i]; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
363 return 4*length; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
364 } |
338 | 365 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
366 static int convertMonoToStereo8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
367 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
368 int i; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
369 Uint8* buffer = Data.buffer - 1; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
370 Uint8* dst = Data.buffer + 2*length - 2; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
371 for( i = length + 1; --i; dst-=2 ) |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
372 dst[0] = dst[1] = buffer[i]; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
373 return 2*length; |
338 | 374 } |
375 | |
376 /*-------------------------------------------------------------------------*/ | |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
377 static int minus5dB( AdapterC Data, int length ) |
338 | 378 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
379 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
380 Sint16* buffer = (Sint16*) Data.buffer; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
381 for(i = length>>1 + 1; --i; ) |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
382 buffer[i] = (38084 * (int)buffer[i]) >> 16; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
383 return length; |
338 | 384 } |
385 | |
386 /*-------------------------------------------------------------------------*/ | |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
387 const Fraction Half = {1, 2}; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
388 const Fraction Double = {2, 1}; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
389 const Fraction One = {1, 1}; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
390 |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
391 |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
392 static void initStraigthBuffer( RateConverterBuffer *rcb, |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
393 int length, Fraction r ) |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
394 { |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
395 int i, size, minsize; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
396 size = 8 * _fsize; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
397 minsize = min( size, length ); |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
398 |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
399 for( i = 0; i < minsize; i++ ) |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
400 { |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
401 rcb->inbuffer[i] = rcb->buffer[length-size+i]; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
402 rcb->inbuffer[i+size] = 0; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
403 rcb->inbuffer[i+2*size] = rcb->buffer[i]; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
404 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
405 for( ; i < size; i++ ) |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
406 { |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
407 rcb->inbuffer[i] = 0; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
408 rcb->inbuffer[i+size] = 0; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
409 rcb->inbuffer[i+2*size] = 0; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
410 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
411 |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
412 length = max( length, size ); |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
413 rcb->flength = rcb->llength = size; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
414 rcb->clength = length - size; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
415 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
416 if( r.numerator < r.denominator ) |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
417 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
418 rcb->finp = rcb->inbuffer + 5*size/2; |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
419 rcb->cinp = rcb->buffer + length - size/2; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
420 rcb->linp = rcb->inbuffer + 3*size/2; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
421 rcb->buffer += ( 1 + r.denominator * ( length + size ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
422 / r.numerator ) & -2; |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
423 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
424 else |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
425 { |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
426 rcb->finp = rcb->inbuffer + size/2; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
427 rcb->cinp = rcb->buffer + size/2; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
428 rcb->linp = rcb->inbuffer + 3*size/2; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
429 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
430 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
431 |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
432 static void initLoopBuffer( RateConverterBuffer *rcb, |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
433 int length, Fraction r ) |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
434 { |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
435 /* !!!FIXME: modulo length, take scale into account, |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
436 check against the Straight part -frank */ |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
437 int i, size; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
438 size = 8 * _fsize; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
439 for( i = 0; i < size; i++ ) |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
440 { |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
441 rcb->inbuffer[i] = rcb->buffer[length-size+i]; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
442 rcb->inbuffer[i+size] = rcb->buffer[i]; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
443 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
444 rcb->finp = rcb->linp = rcb->inbuffer + size; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
445 if( size < 0 ) |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
446 rcb->buffer += r.numerator * ( length + 2 * size ) |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
447 / r.denominator; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
448 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
449 |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
450 static void initRateConverterBuffer( RateConverterBuffer *rcb, |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
451 AdapterC* Data, int length, Fraction ratio ) |
338 | 452 { |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
453 length >>= 1; |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
454 rcb->buffer = (Sint16*)( Data->buffer ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
455 rcb->filter = Data->filter; |
338 | 456 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
457 if( Data->mode & SDL_SOUND_Loop ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
458 initLoopBuffer( rcb, length, ratio ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
459 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
460 initStraigthBuffer( rcb, length, ratio ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
461 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
462 fprintf( stderr, " finp: %8x length: %8x\n", rcb->finp, rcb->flength ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
463 fprintf( stderr, " cinp: %8x length: %8x\n", rcb->cinp, rcb->clength ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
464 fprintf( stderr, " linp: %8x length: %8x\n", rcb->linp, rcb->llength ); |
338 | 465 } |
466 | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
467 static void nextRateConverterBuffer( RateConverterBuffer *rcb ) |
338 | 468 { |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
469 rcb->buffer++; |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
470 rcb->finp++; |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
471 rcb->cinp++; |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
472 rcb->linp++; |
338 | 473 } |
474 | |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
475 typedef Sint16* (*RateConverter)( Sint16*, Sint16*, int, |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
476 VarFilter*, RateAux* ); |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
477 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
478 static Sint16* doRateConversion( RateConverterBuffer* rcb, RateConverter rc ) |
338 | 479 { |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
480 RateAux aux = {0,0}; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
481 Sint16 *outp = rcb->buffer; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
482 VarFilter* filter = rcb->filter; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
483 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
484 outp = (*rc)( outp, rcb->finp, rcb->flength, filter, &aux ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
485 fprintf( stderr, " outp: %8x aux.carry: %8x\n", outp, aux.carry ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
486 outp = (*rc)( outp, rcb->cinp, rcb->clength, filter, &aux ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
487 fprintf( stderr, " outp: %8x aux.carry: %8x\n", outp, aux.carry ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
488 outp = (*rc)( outp, rcb->linp, rcb->llength, filter, &aux ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
489 fprintf( stderr, " outp: %8x aux.carry: %8x\n", outp, aux.carry ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
490 return outp; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
491 } |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
492 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
493 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
494 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
495 static void clearSint16Buffer( Sint8* buffer, Sint16*r ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
496 { |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
497 while( r >= (Sint16*)buffer ) *r-- = 0; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
498 } |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
499 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
500 /*-------------------------------------------------------------------------*/ |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
501 static int doubleRateMono( AdapterC Data, int length ) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
502 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
503 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
504 RateConverterBuffer rcb; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
505 initRateConverterBuffer( &rcb, &Data, length, Half ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
506 r = 1 + doRateConversion( &rcb, doubleRate1 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
507 clearSint16Buffer( Data.buffer, r ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
508 return 2 * ( rcb.buffer - (Sint16*)Data.buffer + 2 ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
509 } |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
510 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
511 static int doubleRateStereo( AdapterC Data, int length ) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
512 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
513 Sint16* r; |
421 | 514 RateConverterBuffer rcb; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
515 fprintf( stderr, "\n Buffer: %8x length: %8x\n", Data.buffer, length ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
516 initRateConverterBuffer( &rcb, &Data, length, Half ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
517 doRateConversion( &rcb, doubleRate2 ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
518 nextRateConverterBuffer( &rcb ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
519 r = 2 + doRateConversion( &rcb, doubleRate2 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
520 clearSint16Buffer( Data.buffer, r ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
521 return 2 * ( rcb.buffer - (Sint16*)Data.buffer + 3 ); |
338 | 522 } |
523 | |
524 /*-------------------------------------------------------------------------*/ | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
525 static int halfRateMono( AdapterC Data, int length ) |
338 | 526 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
527 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
528 RateConverterBuffer rcb; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
529 initRateConverterBuffer( &rcb, &Data, length, Double ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
530 r = doRateConversion( &rcb, halfRate1 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
531 return 2 * ( r - (Sint16*)Data.buffer ); |
338 | 532 } |
533 | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
534 static int halfRateStereo( AdapterC Data, int length ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
535 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
536 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
537 RateConverterBuffer rcb; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
538 initRateConverterBuffer( &rcb, &Data, length, Double ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
539 doRateConversion( &rcb, halfRate2 ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
540 nextRateConverterBuffer( &rcb ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
541 r = doRateConversion( &rcb, halfRate2 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
542 return 2 * ( r - (Sint16*)Data.buffer ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
543 } |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
544 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
545 /*-------------------------------------------------------------------------*/ |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
546 static int increaseRateMono( AdapterC Data, int length ) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
547 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
548 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
549 RateConverterBuffer rcb; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
550 initRateConverterBuffer( &rcb, &Data, length, Data.filter->ratio ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
551 r = doRateConversion( &rcb, increaseRate1 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
552 clearSint16Buffer( Data.buffer, r ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
553 return 2 * ( rcb.buffer - (Sint16*)Data.buffer + 1 ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
554 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
555 |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
556 static int increaseRateStereo( AdapterC Data, int length ) |
338 | 557 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
558 Sint16* r; |
421 | 559 RateConverterBuffer rcb; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
560 fprintf( stderr, "\n Buffer: %8x length: %8x\n", Data.buffer, length ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
561 initRateConverterBuffer( &rcb, &Data, length, Data.filter->ratio ); |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
562 doRateConversion( &rcb, increaseRate2 ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
563 nextRateConverterBuffer( &rcb ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
564 r = doRateConversion( &rcb, increaseRate2 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
565 clearSint16Buffer( Data.buffer, r ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
566 return 2 * ( rcb.buffer - (Sint16*)Data.buffer + 1 ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
567 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
568 |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
569 /*-------------------------------------------------------------------------*/ |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
570 static int decreaseRateMono( AdapterC Data, int length ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
571 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
572 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
573 RateConverterBuffer rcb; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
574 initRateConverterBuffer( &rcb, &Data, length, Data.filter->ratio ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
575 r = doRateConversion( &rcb, decreaseRate1 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
576 return 2 * ( r - (Sint16*)Data.buffer ); |
338 | 577 } |
578 | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
579 static int decreaseRateStereo( AdapterC Data, int length ) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
580 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
581 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
582 RateConverterBuffer rcb; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
583 initRateConverterBuffer( &rcb, &Data, length, Data.filter->ratio ); |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
584 doRateConversion( &rcb, decreaseRate2 ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
585 nextRateConverterBuffer( &rcb ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
586 r = doRateConversion( &rcb, decreaseRate2 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
587 return 2 * ( r - (Sint16*)Data.buffer ); |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
588 } |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
589 |
338 | 590 /*-------------------------------------------------------------------------*/ |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
591 /* gives a maximal error of 3% and typical less than 0.2% */ |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
592 static Fraction findFraction( float Value ) |
338 | 593 { |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
594 const Sint8 frac[95]={ |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
595 2, -1, /* /1 */ |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
596 1, 3, -1, /* /2 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
597 2, 4, 5, -1, /* /3 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
598 3, 5, 7, -1, /* /4 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
599 3, 4, 6, 7, 8, 9, -1, /* /5 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
600 5, 7, 11, -1, /* /6 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
601 4, 5, 6, 8, 9, 10, 11, 12, 13, -1, /* /7 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
602 5, 7, 9, 11, 13, 15, -1, /* /8 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
603 5, 7, 8, 10, 11, 13, 14, 16, -1, /* /9 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
604 7, 9, 11, 13, -1, /* /10 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
605 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, -1, /* /11 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
606 7, 11, 13, -1, /* /12 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
607 7, 8, 9, 10, 11, 12, 14, 15, 16, -1, /* /13 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
608 9, 11, 13, 15, -1, /* /14 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
609 8, 11, 13, 14, 16, -1, /* /15 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
610 9, 11, 13, 15 }; /* /16 */ |
338 | 611 |
612 | |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
613 Fraction Result = {0,0}; |
371 | 614 int i,num,den=1; |
338 | 615 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
616 float RelErr, BestErr = 0; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
617 if( Value < 31/64. || Value > 64/31. ) return Result; |
338 | 618 |
371 | 619 for( i = 0; i < SDL_TABLESIZE(frac); i++ ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
620 { |
371 | 621 num = frac[i]; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
622 if( num < 0 ) den++; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
623 RelErr = Value * num / den; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
624 RelErr = min( RelErr, 1/RelErr ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
625 if( RelErr > BestErr ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
626 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
627 BestErr = RelErr; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
628 Result.denominator = den; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
629 Result.numerator = num; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
630 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
631 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
632 return Result; |
338 | 633 } |
634 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
635 /*-------------------------------------------------------------------------*/ |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
636 static float sinc( float x ) |
338 | 637 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
638 if( x > -1e-24 && x < 1e-24 ) return 1.; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
639 else return sin(x)/x; |
338 | 640 } |
641 | |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
642 static float calculateVarFilter( Sint16* dst, |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
643 float Ratio, float phase, float scale ) |
338 | 644 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
645 const Uint16 KaiserWindow7[]= { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
646 22930, 16292, 14648, 14288, 14470, 14945, 15608, 16404, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
647 17304, 18289, 19347, 20467, 21644, 22872, 24145, 25460, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
648 26812, 28198, 29612, 31052, 32513, 33991, 35482, 36983, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
649 38487, 39993, 41494, 42986, 44466, 45928, 47368, 48782, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
650 50165, 51513, 52821, 54086, 55302, 56466, 57575, 58624, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
651 59610, 60529, 61379, 62156, 62858, 63483, 64027, 64490, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
652 64870, 65165, 65375, 65498, 65535, 65484, 65347, 65124, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
653 64815, 64422, 63946, 63389, 62753, 62039, 61251, 60391 }; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
654 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
655 float w; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
656 const float fg = -.018 + .5 * Ratio; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
657 const float omega = 2 * M_PI * fg; |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
658 fprintf( stderr, " phase: %6g \n", phase ); |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
659 phase += 63; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
660 for( i = 0; i < 64; i++) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
661 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
662 w = scale * ( KaiserWindow7[i] * ( i + 1 )); |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
663 dst[i] = w * sinc( omega * (i-phase) ); |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
664 dst[127-i] = w * sinc( omega * (127-i-phase) ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
665 } |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
666 fprintf( stderr, " center: %6d %6d \n", dst[63], dst[64] ); |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
667 return fg; |
338 | 668 } |
669 | |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
670 static Fraction setupVarFilter( Sound_AudioCVT *Data, float Ratio ) |
371 | 671 { |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
672 int pos,n,d, incr, phase = 0; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
673 float Scale, rd, fg; |
371 | 674 Fraction IRatio; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
675 VarFilter* filter = &Data->filter; |
338 | 676 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
677 IRatio = findFraction( Ratio ); |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
678 // Scale = Ratio < 1. ? 0.0364733 : 0.0211952; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
679 Scale = 0.0084778; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
680 Ratio = min( Ratio, 0.97 ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
681 |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
682 filter->ratio = IRatio; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
683 n = IRatio.numerator; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
684 d = IRatio.denominator; |
371 | 685 rd = 1. / d; |
338 | 686 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
687 fprintf( stderr, "Filter:\n" ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
688 |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
689 for( pos = 0; pos < d; pos++ ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
690 { |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
691 fg = calculateVarFilter( filter->c[pos], Ratio, phase*rd, Scale ); |
371 | 692 phase += n; |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
693 filter->incr[pos] = phase / d; |
371 | 694 phase %= d; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
695 } |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
696 fprintf( stderr, " fg: %6g\n\n", fg ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
697 /* !!!FIXME: get rid of the inversion -Frank*/ |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
698 IRatio.numerator = d; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
699 IRatio.denominator = n; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
700 return IRatio; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
701 } |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
702 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
703 static void initAudioCVT( Sound_AudioCVT *Data ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
704 { |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
705 Data->len_ratio = 1.; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
706 Data->len_mult = 1; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
707 Data->add = 0; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
708 Data->len_add = 0; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
709 Data->filter_index = 0; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
710 } |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
711 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
712 static void adjustSize( Sound_AudioCVT *Data, int add, Fraction f ) |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
713 { |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
714 double ratio = f.numerator / (double) f.denominator; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
715 Data->len_ratio *= ratio; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
716 Data->len_mult = max( Data->len_mult, ceil(Data->len_ratio) ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
717 Data->add = ratio * (Data->add + add); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
718 Data->len_add = max( Data->len_add, ceil(Data->add) ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
719 } |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
720 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
721 static Adapter* addAdapter( Sound_AudioCVT *Data, Adapter a ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
722 { |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
723 Data->adapter[Data->filter_index] = a; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
724 return &Data->adapter[Data->filter_index++]; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
725 } |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
726 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
727 static void addHAdapter( Sound_AudioCVT *Data, Adapter a ) |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
728 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
729 adjustSize( Data, 0, Half ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
730 addAdapter( Data, a ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
731 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
732 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
733 static void addDAdapter( Sound_AudioCVT *Data, Adapter a ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
734 { |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
735 adjustSize( Data, 0, Double ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
736 addAdapter( Data, a ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
737 } |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
738 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
739 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
740 /*-------------------------------------------------------------------------*/ |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
741 const Adapter doubleRate[2] = { doubleRateMono, doubleRateStereo }; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
742 const Adapter halfRate[2] = { halfRateMono, halfRateStereo }; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
743 const Adapter increaseRate[2] = { increaseRateMono, increaseRateStereo }; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
744 const Adapter decreaseRate[2] = { decreaseRateMono, decreaseRateStereo }; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
745 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
746 static int createRateConverter( Sound_AudioCVT *Data, |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
747 int SrcRate, int DestRate, int channel ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
748 { |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
749 const int c = channel - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
750 const int size = 16 * channel * _fsize; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
751 Adapter* AdapterPos; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
752 float Ratio = DestRate; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
753 Fraction f; |
338 | 754 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
755 if( SrcRate < 1 || SrcRate > 1<<18 || |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
756 DestRate < 1 || DestRate > 1<<18 ) return -1; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
757 Ratio /= SrcRate; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
758 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
759 AdapterPos = addAdapter( Data, minus5dB ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
760 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
761 while( Ratio > 64./31.) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
762 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
763 Ratio /= 2.; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
764 addAdapter( Data, doubleRate[c] ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
765 adjustSize( Data, size, Double ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
766 } |
338 | 767 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
768 while( Ratio < 31./64. ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
769 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
770 Ratio *= 2; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
771 addAdapter( Data, halfRate[c] ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
772 adjustSize( Data, size, Half ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
773 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
774 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
775 if( Ratio > 1. ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
776 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
777 *AdapterPos = increaseRate[c]; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
778 f = setupVarFilter( Data, Ratio ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
779 adjustSize( Data, size, f ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
780 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
781 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
782 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
783 f = setupVarFilter( Data, Ratio ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
784 addAdapter( Data, decreaseRate[c]); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
785 adjustSize( Data, size, f ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
786 } |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
787 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
788 return 0; |
338 | 789 } |
790 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
791 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
792 static void createFormatConverter16Bit(Sound_AudioCVT *Data, |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
793 SDL_AudioSpec src, SDL_AudioSpec dst ) |
338 | 794 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
795 if( src.channels == 2 && dst.channels == 1 ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
796 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
797 if( !IS_SYSENDIAN(src) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
798 addAdapter( Data, swapBytes ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
799 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
800 if( IS_SIGNED(src) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
801 addHAdapter( Data, convertStereoToMonoS16Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
802 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
803 addHAdapter( Data, convertStereoToMonoU16Bit ); |
338 | 804 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
805 if( !IS_SYSENDIAN(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
806 addAdapter( Data, swapBytes ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
807 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
808 else if( IS_SYSENDIAN(src) != IS_SYSENDIAN(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
809 addAdapter( Data, swapBytes ); |
338 | 810 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
811 if( IS_SIGNED(src) != IS_SIGNED(dst) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
812 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
813 if( IS_SYSENDIAN(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
814 addAdapter( Data, changeSigned16BitSys ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
815 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
816 addAdapter( Data, changeSigned16BitWrong ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
817 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
818 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
819 if( src.channels == 1 && dst.channels == 2 ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
820 addDAdapter( Data, convertMonoToStereo16Bit ); |
338 | 821 } |
822 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
823 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
824 static void createFormatConverter8Bit(Sound_AudioCVT *Data, |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
825 SDL_AudioSpec src, SDL_AudioSpec dst ) |
338 | 826 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
827 if( IS_16BIT(src) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
828 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
829 if( IS_SYSENDIAN(src) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
830 addHAdapter( Data, cut16BitSysTo8Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
831 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
832 addHAdapter( Data, cut16BitWrongTo8Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
833 } |
338 | 834 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
835 if( src.channels == 2 && dst.channels == 1 ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
836 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
837 if( IS_SIGNED(src) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
838 addHAdapter( Data, convertStereoToMonoS8Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
839 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
840 addHAdapter( Data, convertStereoToMonoU8Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
841 } |
338 | 842 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
843 if( IS_SIGNED(src) != IS_SIGNED(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
844 addDAdapter( Data, changeSigned8Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
845 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
846 if( src.channels == 1 && dst.channels == 2 ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
847 addDAdapter( Data, convertMonoToStereo8Bit ); |
338 | 848 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
849 if( !IS_8BIT(dst) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
850 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
851 if( IS_SYSENDIAN(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
852 addDAdapter( Data, expand8BitTo16BitSys ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
853 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
854 addDAdapter( Data, expand8BitTo16BitWrong ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
855 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
856 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
857 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
858 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
859 static void createFormatConverter(Sound_AudioCVT *Data, |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
860 SDL_AudioSpec src, SDL_AudioSpec dst ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
861 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
862 if( IS_FLOAT(src) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
863 addHAdapter( Data, cutFloatTo16Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
864 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
865 if( IS_8BIT(src) || IS_8BIT(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
866 createFormatConverter8Bit( Data, src, dst); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
867 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
868 createFormatConverter16Bit( Data, src, dst); |
338 | 869 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
870 if( IS_FLOAT(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
871 addDAdapter( Data, expand16BitToFloat ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
872 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
873 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
874 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
875 int Sound_AltBuildAudioCVT( Sound_AudioCVT *Data, |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
876 SDL_AudioSpec src, SDL_AudioSpec dst ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
877 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
878 SDL_AudioSpec im; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
879 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
880 if( Data == NULL ) return -1; |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
881 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
882 initAudioCVT( Data ); |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
883 Data->filter.ratio.denominator = 0; |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
884 Data->filter.mask = dst.size - 1; |
338 | 885 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
886 /* Check channels */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
887 if( src.channels < 1 || src.channels > 2 || |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
888 dst.channels < 1 || dst.channels > 2 ) goto error_exit; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
889 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
890 if( src.freq != dst.freq ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
891 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
892 /* Convert to intermidiate format: signed 16Bit System-Endian */ |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
893 im.format = AUDIO_S16SYS; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
894 im.channels = min( src.channels, dst.channels ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
895 createFormatConverter( Data, src, im ); |
338 | 896 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
897 /* Do rate conversion */ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
898 if( createRateConverter( Data, src.freq, dst.freq, im.channels ) ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
899 goto error_exit; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
900 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
901 src = im; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
902 } |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
903 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
904 /* Convert to final format */ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
905 createFormatConverter( Data, src, dst ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
906 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
907 /* Finalize adapter list */ |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
908 addAdapter( Data, NULL ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
909 /* !!! FIXME: Is it okay to assign NULL to a function pointer? |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
910 Borland says no. -frank */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
911 return 0; |
338 | 912 |
913 error_exit: | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
914 /* !!! FIXME: Is it okay to assign NULL to a function pointer? |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
915 Borland says no. -frank */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
916 Data->adapter[0] = NULL; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
917 return -1; |
338 | 918 } |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
919 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
920 /*-------------------------------------------------------------------------*/ |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
921 static char *fmt_to_str(Uint16 fmt) |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
922 { |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
923 switch (fmt) |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
924 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
925 case AUDIO_U8: return " U8"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
926 case AUDIO_S8: return " S8"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
927 case AUDIO_U16MSB: return "U16MSB"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
928 case AUDIO_S16MSB: return "S16MSB"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
929 case AUDIO_U16LSB: return "U16LSB"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
930 case AUDIO_S16LSB: return "S16LSB"; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
931 } |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
932 return "??????"; |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
933 } |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
934 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
935 #define AdapterDesc(x) { x, #x } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
936 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
937 static void show_AudioCVT( Sound_AudioCVT *Data ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
938 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
939 int i,j; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
940 const struct{ int (*adapter) ( AdapterC, int); Sint8 *name; } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
941 AdapterDescription[] = { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
942 AdapterDesc(expand8BitTo16BitSys), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
943 AdapterDesc(expand8BitTo16BitWrong), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
944 AdapterDesc(expand16BitToFloat), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
945 AdapterDesc(swapBytes), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
946 AdapterDesc(cut16BitSysTo8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
947 AdapterDesc(cut16BitWrongTo8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
948 AdapterDesc(cutFloatTo16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
949 AdapterDesc(changeSigned16BitSys), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
950 AdapterDesc(changeSigned16BitWrong), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
951 AdapterDesc(changeSigned8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
952 AdapterDesc(convertStereoToMonoS16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
953 AdapterDesc(convertStereoToMonoU16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
954 AdapterDesc(convertStereoToMonoS8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
955 AdapterDesc(convertStereoToMonoU8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
956 AdapterDesc(convertMonoToStereo16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
957 AdapterDesc(convertMonoToStereo8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
958 AdapterDesc(minus5dB), |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
959 AdapterDesc(doubleRateMono), |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
960 AdapterDesc(doubleRateStereo), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
961 AdapterDesc(halfRateMono), |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
962 AdapterDesc(halfRateStereo), |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
963 AdapterDesc(increaseRateMono), |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
964 AdapterDesc(increaseRateStereo), |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
965 AdapterDesc(decreaseRateMono), |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
966 AdapterDesc(decreaseRateStereo), |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
967 { NULL, "----------NULL-----------\n" } |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
968 }; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
969 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
970 fprintf( stderr, "Sound_AudioCVT:\n" ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
971 fprintf( stderr, " needed: %8d\n", Data->needed ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
972 fprintf( stderr, " add: %8g\n", Data->add ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
973 fprintf( stderr, " len_add: %8d\n", Data->len_add ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
974 fprintf( stderr, " len_ratio: %8g\n", Data->len_ratio ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
975 fprintf( stderr, " len_mult: %8d\n", Data->len_mult ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
976 fprintf( stderr, " filter->mask: %#7x\n", Data->filter.mask ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
977 fprintf( stderr, "\n" ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
978 |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
979 fprintf( stderr, "Adapter List: \n" ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
980 for( i = 0; i < 32; i++ ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
981 { |
366
eda146d666d1
More patches from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
365
diff
changeset
|
982 for( j = 0; j < SDL_TABLESIZE(AdapterDescription); j++ ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
983 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
984 if( Data->adapter[i] == AdapterDescription[j].adapter ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
985 { |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
986 fprintf( stderr, " %s \n", AdapterDescription[j].name ); |
371 | 987 if( Data->adapter[i] == NULL ) goto sucess_exit; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
988 goto cont; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
989 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
990 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
991 fprintf( stderr, " Error: unknown adapter\n" ); |
371 | 992 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
993 cont: |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
994 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
995 fprintf( stderr, " Error: NULL adapter missing\n" ); |
371 | 996 sucess_exit: |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
997 if( Data->filter.ratio.denominator ) |
371 | 998 { |
999 fprintf( stderr, "Variable Rate Converter:\n" | |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1000 " numerator: %3d\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1001 " denominator: %3d\n", |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
1002 Data->filter.ratio.denominator, |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
1003 Data->filter.ratio.numerator ); |
371 | 1004 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1005 fprintf( stderr, " increment sequence:\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1006 " " ); |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
1007 for( i = 0; i < Data->filter.ratio.denominator; i++ ) |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1008 fprintf( stderr, "%1d ", Data->filter.incr[i] ); |
371 | 1009 |
1010 fprintf( stderr, "\n" ); | |
1011 } | |
1012 else | |
1013 { | |
1014 fprintf( stderr, "No Variable Rate Converter\n" ); | |
1015 } | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1016 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1017 |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1018 |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1019 int Sound_BuildAudioCVT(Sound_AudioCVT *Data, |
441
5b00e43ec23c
Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
1020 Uint16 src_format, Uint8 src_channels, Uint32 src_rate, |
5b00e43ec23c
Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
1021 Uint16 dst_format, Uint8 dst_channels, Uint32 dst_rate, Uint32 bufsize) |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1022 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1023 SDL_AudioSpec src, dst; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1024 int ret; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1025 |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1026 fprintf (stderr, |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1027 "Sound_BuildAudioCVT():\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1028 "-----------------------------\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1029 "format: %s -> %s\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1030 "channels: %6d -> %6d\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1031 "rate: %6d -> %6d\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1032 "size: don't care -> %#7x\n\n", |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1033 fmt_to_str (src_format), fmt_to_str (dst_format), |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1034 src_channels, dst_channels, |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
1035 src_rate, dst_rate ); |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1036 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1037 src.format = src_format; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1038 src.channels = src_channels; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1039 src.freq = src_rate; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1040 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1041 dst.format = dst_format; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1042 dst.channels = dst_channels; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1043 dst.freq = dst_rate; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1044 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
1045 ret = Sound_AltBuildAudioCVT( Data, src, dst ); |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1046 Data->needed = 1; |
347
778cee61e1be
Mono-to-stereo fixes, more fprintf debugging output.
Ryan C. Gordon <icculus@icculus.org>
parents:
342
diff
changeset
|
1047 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1048 show_AudioCVT( Data ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1049 fprintf (stderr, "\n" |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1050 "return value: %d \n\n\n", ret ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1051 return ret; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1052 } |
465
636796aed4e2
Build/packaging fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
441
diff
changeset
|
1053 |
636796aed4e2
Build/packaging fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
441
diff
changeset
|
1054 #endif /* SOUND_USE_ALTCVT */ |
636796aed4e2
Build/packaging fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
441
diff
changeset
|
1055 |
636796aed4e2
Build/packaging fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
441
diff
changeset
|
1056 /* end of alt_audio_convert.c ... */ |
636796aed4e2
Build/packaging fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
441
diff
changeset
|
1057 |