Mercurial > SDL_sound_CoreAudio
annotate alt_audio_convert.c @ 420:5b8a07b5162e
Latest altcvt from Frank.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 26 Sep 2002 04:34:35 +0000 |
parents | b1e511c879d1 |
children | a65440b3a057 |
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 |
28 #include "alt_audio_convert.h" | |
29 #include <math.h> | |
30 | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
31 /* just to make sure this is defined... */ |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
32 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
33 #ifndef min |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
34 #define min(x, y) ( ((x) < (y)) ? (x) : (y) ) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
35 #endif |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
36 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
37 #ifndef max |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
38 #define max(x, y) ( ((x) > (y)) ? (x) : (y) ) |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
39 #endif |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
40 |
366
eda146d666d1
More patches from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
365
diff
changeset
|
41 #ifndef abs |
eda146d666d1
More patches from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
365
diff
changeset
|
42 #define abs(x) ( ((x) > (0)) ? (x) : -(x) ) |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
43 #endif |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
44 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
45 |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
46 /* some macros for "parsing" format */ |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
47 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
48 #define IS_8BIT(x) ((x).format & 0x0008) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
49 #define IS_16BIT(x) ((x).format & 0x0010) |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
50 #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
|
51 #define IS_SIGNED(x) ((x).format & 0x8000) |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
52 #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
|
53 #define SDL_MSB_POSITION_IN_SHORT ((0x1000 & AUDIO_U16SYS)>>12) |
338 | 54 |
55 | |
56 /*-------------------------------------------------------------------------*/ | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
57 /* 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
|
58 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
|
59 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
|
60 operation mode, two layouts for the RateConverterBuffer.inbuffer are |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
61 possible: |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
62 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
63 in the Loop Mode: |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
64 ... 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
|
65 | |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
66 linp, finp |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
67 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
68 in the Single Mode (non Loop): |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
69 ... 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
|
70 | | |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
71 linp finp |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
72 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
73 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
|
74 filters in the rate Converters. |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
75 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 movement is stored in flength, always positive. |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
84 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
85 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
|
86 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
|
87 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
|
88 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
|
89 the movement is stored in clength. |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
90 |
366
eda146d666d1
More patches from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
365
diff
changeset
|
91 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
|
92 flength, but in reverse order. |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
93 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
94 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
|
95 on direction of the rate conversion. |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
96 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
97 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
|
98 are refering to the input buffer */ |
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 typedef struct |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
101 { |
366
eda146d666d1
More patches from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
365
diff
changeset
|
102 Sint16 inbuffer[24*_fsize]; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
103 Sint16 *finp, *cinp, *linp; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
104 int flength, clength, llength; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
105 Sint16 *buffer; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
106 VarFilter *filter; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
107 } RateConverterBuffer; |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
108 |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
109 typedef struct |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
110 { |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
111 Sint16 carry; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
112 Sint16 pos; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
113 } RateAux; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
114 |
338 | 115 |
116 /* Mono (1 channel ) */ | |
117 #define Suffix(x) x##1 | |
118 #include "filter_templates.h" | |
119 #undef Suffix | |
120 | |
121 /* Stereo (2 channel ) */ | |
122 #define Suffix(x) x##2 | |
123 #include "filter_templates.h" | |
124 #undef Suffix | |
125 | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
126 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
127 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
128 int Sound_estimateBufferSize( Sound_AudioCVT *Data, int size ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
129 { |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
130 size *= Data->len_mult; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
131 size += Data->len_add; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
132 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
|
133 } |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
134 |
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 int Sound_AltConvertAudio( Sound_AudioCVT *Data, |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
137 Uint8* buffer, int length, int mode ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
138 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
139 AdapterC Temp; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
140 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
141 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
142 /* Make sure there's a converter */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
143 if( Data == NULL ) { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
144 SDL_SetError("No converter given"); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
145 return(-1); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
146 } |
338 | 147 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
148 /* Make sure there's data to convert */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
149 if( buffer == NULL ) { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
150 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
|
151 return(-1); |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
152 } |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
153 |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
154 if( length < 0 ) { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
155 SDL_SetError("Lenght < 0"); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
156 return(-1); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
157 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
158 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
159 /* Set up the conversion and go! */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
160 Temp.buffer = buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
161 Temp.mode = mode; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
162 Temp.filter = &Data->filter; |
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 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
|
165 length = (*Data->adapter[i])( Temp, length); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
166 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
167 return length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
168 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
169 |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
170 int Sound_ConvertAudio( Sound_AudioCVT *Data ) |
338 | 171 { |
371 | 172 int length; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
173 /* !!! 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
|
174 length = Sound_AltConvertAudio( Data, Data->buf, Data->len, 0 ); |
371 | 175 Data->len_cvt = length; |
176 return length; | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
177 } |
338 | 178 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
179 /*-------------------------------------------------------------------------*/ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
180 static int expand8BitTo16BitSys( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
181 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
182 int i; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
183 Uint8* inp = Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
184 Uint16* buffer = (Uint16*)Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
185 for( i = length + 1; --i; ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
186 buffer[i] = inp[i]<<8; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
187 return 2*length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
188 } |
338 | 189 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
190 static int expand8BitTo16BitWrong( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
191 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
192 int i; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
193 Uint8* inp = Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
194 Uint16* buffer = (Uint16*)Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
195 for( i = length + 1; --i; ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
196 buffer[i] = inp[i]; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
197 return 2*length; |
338 | 198 } |
199 | |
200 /*-------------------------------------------------------------------------*/ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
201 static int expand16BitToFloat( AdapterC Data, int length ) |
338 | 202 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
203 int i; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
204 Sint16* inp = (Sint16*)Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
205 float* buffer = (float*)Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
206 for( i = length>>1 + 1; --i; ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
207 buffer[i] = inp[i]*(1./32767); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
208 return 2*length; |
338 | 209 } |
210 | |
211 /*-------------------------------------------------------------------------*/ | |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
212 static int swapBytes( AdapterC Data, int length ) |
338 | 213 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
214 /* |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
215 * !!! FIXME !!! |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
216 * |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
217 * |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
218 * Use the faster SDL-Macros to swap |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
219 * - Frank |
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 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
222 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
223 Uint16 a,b; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
224 Uint16* buffer = (Uint16*) Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
225 for( i = length>>1 + 1; --i; ) |
360
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 a = b = buffer[i]; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
228 buffer[i] = ( a << 8 ) | ( b >> 8 ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
229 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
230 return length; |
338 | 231 } |
232 | |
233 /*-------------------------------------------------------------------------*/ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
234 static int cutFloatTo16Bit( AdapterC Data, int length ) |
338 | 235 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
236 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
237 float* inp = (float*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
238 Sint16* buffer = (Sint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
239 length>>=2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
240 for( i = 0; i < length; i++ ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
241 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
242 if( inp[i] > 1. ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
243 buffer[i] = 32767; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
244 else if( inp[i] < -1. ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
245 buffer[i] = -32768; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
246 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
247 buffer[i] = 32767 * inp[i]; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
248 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
249 return 2*length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
250 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
251 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
252 /*-------------------------------------------------------------------------*/ |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
253 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
|
254 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
255 int i; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
256 Uint8* inp = Data.buffer + off; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
257 Uint8* buffer = Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
258 length >>= 1; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
259 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
|
260 buffer[i] = inp[2*i]; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
261 return length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
262 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
263 |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
264 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
|
265 { |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
266 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
|
267 } |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
268 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
269 static int cut16BitWrongTo8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
270 { |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
271 return cut16BitTo8Bit( Data, length, 1-SDL_MSB_POSITION_IN_SHORT ); |
338 | 272 } |
273 | |
274 /*-------------------------------------------------------------------------*/ | |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
275 /* poor mans mmx :-) */ |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
276 static int changeSigned( AdapterC Data, int length, Uint32 XOR ) |
338 | 277 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
278 int i; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
279 Uint32* buffer = (Uint32*) Data.buffer - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
280 for( i = ( length + 7 ) >> 2; --i; ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
281 buffer[i] ^= XOR; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
282 return length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
283 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
284 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
285 static int changeSigned16BitSys( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
286 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
287 return changeSigned( Data, length, 0x80008000 ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
288 } |
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 static int changeSigned16BitWrong( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
291 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
292 return changeSigned( Data, length, 0x00800080 ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
293 } |
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 static int changeSigned8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
296 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
297 return changeSigned( Data, length, 0x80808080 ); |
338 | 298 } |
299 | |
300 /*-------------------------------------------------------------------------*/ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
301 static int convertStereoToMonoS16Bit( AdapterC Data, int length ) |
338 | 302 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
303 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
304 Sint16* buffer = (Sint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
305 Sint16* src = (Sint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
306 length >>= 2; |
371 | 307 for( i = 0; i < length; i++, src+=2 ) |
308 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
|
309 return 2*length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
310 } |
338 | 311 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
312 static int convertStereoToMonoU16Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
313 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
314 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
315 Uint16* buffer = (Uint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
316 Uint16* src = (Uint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
317 length >>= 2; |
371 | 318 for( i = 0; i < length; i++, src+=2 ) |
319 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
|
320 return 2*length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
321 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
322 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
323 static int convertStereoToMonoS8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
324 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
325 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
326 Sint8* buffer = (Sint8*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
327 Sint8* src = (Sint8*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
328 length >>= 1; |
371 | 329 for( i = 0; i < length; i++, src+=2 ) |
330 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
|
331 return length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
332 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
333 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
334 static int convertStereoToMonoU8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
335 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
336 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
337 Uint8* buffer = (Uint8*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
338 Uint8* src = (Uint8*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
339 length >>= 1; |
371 | 340 for( i = 0; i < length; i++, src+=2 ) |
341 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
|
342 return length; |
338 | 343 } |
344 | |
345 /*-------------------------------------------------------------------------*/ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
346 static int convertMonoToStereo16Bit( AdapterC Data, int length ) |
338 | 347 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
348 int i; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
349 length >>=1; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
350 Uint16* buffer = (Uint16*)Data.buffer - 1; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
351 Uint16* dst = (Uint16*)Data.buffer + 2*length - 2; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
352 for( i = length + 1; --i; dst-=2 ) |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
353 dst[0] = dst[1] = buffer[i]; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
354 return 4*length; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
355 } |
338 | 356 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
357 static int convertMonoToStereo8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
358 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
359 int i; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
360 Uint8* buffer = Data.buffer - 1; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
361 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
|
362 for( i = length + 1; --i; dst-=2 ) |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
363 dst[0] = dst[1] = buffer[i]; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
364 return 2*length; |
338 | 365 } |
366 | |
367 /*-------------------------------------------------------------------------*/ | |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
368 static int minus5dB( AdapterC Data, int length ) |
338 | 369 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
370 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
371 Sint16* buffer = (Sint16*) Data.buffer; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
372 for(i = length>>1 + 1; --i; ) |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
373 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
|
374 return length; |
338 | 375 } |
376 | |
377 /*-------------------------------------------------------------------------*/ | |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
378 const Fraction Half = {1, 2}; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
379 const Fraction Double = {2, 1}; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
380 const Fraction One = {1, 1}; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
381 |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
382 |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
383 static void initStraigthBuffer( RateConverterBuffer *rcb, |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
384 int length, Fraction r ) |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
385 { |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
386 int i, size, minsize; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
387 size = 8 * _fsize; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
388 minsize = min( size, length ); |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
389 |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
390 for( i = 0; i < minsize; i++ ) |
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 rcb->inbuffer[i] = rcb->buffer[length-size+i]; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
393 rcb->inbuffer[i+size] = 0; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
394 rcb->inbuffer[i+2*size] = rcb->buffer[i]; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
395 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
396 for( ; i < size; i++ ) |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
397 { |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
398 rcb->inbuffer[i] = 0; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
399 rcb->inbuffer[i+size] = 0; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
400 rcb->inbuffer[i+2*size] = 0; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
401 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
402 |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
403 length = max( length, size ); |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
404 rcb->flength = rcb->llength = size; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
405 rcb->clength = length - size; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
406 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
407 if( r.numerator < r.denominator ) |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
408 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
409 rcb->finp = rcb->inbuffer + 5*size/2; |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
410 rcb->cinp = rcb->buffer + length - size/2; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
411 rcb->linp = rcb->inbuffer + 3*size/2; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
412 rcb->buffer += ( 1 + r.denominator * ( length + size ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
413 / r.numerator ) & -2; |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
414 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
415 else |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
416 { |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
417 rcb->finp = rcb->inbuffer + size/2; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
418 rcb->cinp = rcb->buffer + size/2; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
419 rcb->linp = rcb->inbuffer + 3*size/2; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
420 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
421 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
422 |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
423 static void initLoopBuffer( RateConverterBuffer *rcb, |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
424 int length, Fraction r ) |
380
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 /* !!!FIXME: modulo length, take scale into account, |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
427 check against the Straight part -frank */ |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
428 int i, size; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
429 size = 8 * _fsize; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
430 for( i = 0; i < size; i++ ) |
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 rcb->inbuffer[i] = rcb->buffer[length-size+i]; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
433 rcb->inbuffer[i+size] = rcb->buffer[i]; |
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 rcb->finp = rcb->linp = rcb->inbuffer + size; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
436 if( size < 0 ) |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
437 rcb->buffer += r.numerator * ( length + 2 * size ) |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
438 / r.denominator; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
439 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
440 |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
441 static void initRateConverterBuffer( RateConverterBuffer *rcb, |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
442 AdapterC* Data, int length, Fraction ratio ) |
338 | 443 { |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
444 length >>= 1; |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
445 rcb->buffer = (Sint16*)( Data->buffer ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
446 rcb->filter = Data->filter; |
338 | 447 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
448 if( Data->mode & SDL_SOUND_Loop ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
449 initLoopBuffer( rcb, length, ratio ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
450 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
451 initStraigthBuffer( rcb, length, ratio ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
452 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
453 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
|
454 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
|
455 fprintf( stderr, " linp: %8x length: %8x\n", rcb->linp, rcb->llength ); |
338 | 456 } |
457 | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
458 static void nextRateConverterBuffer( RateConverterBuffer *rcb ) |
338 | 459 { |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
460 rcb->buffer++; |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
461 rcb->finp++; |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
462 rcb->cinp++; |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
463 rcb->linp++; |
338 | 464 } |
465 | |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
466 typedef Sint16* (*RateConverter)( Sint16*, Sint16*, int, |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
467 VarFilter*, RateAux* ); |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
468 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
469 static Sint16* doRateConversion( RateConverterBuffer* rcb, RateConverter rc ) |
338 | 470 { |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
471 RateAux aux = {0,0}; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
472 Sint16 *outp = rcb->buffer; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
473 VarFilter* filter = rcb->filter; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
474 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
475 outp = (*rc)( outp, rcb->finp, rcb->flength, filter, &aux ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
476 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
|
477 outp = (*rc)( outp, rcb->cinp, rcb->clength, filter, &aux ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
478 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
|
479 outp = (*rc)( outp, rcb->linp, rcb->llength, filter, &aux ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
480 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
|
481 return outp; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
482 } |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
483 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
484 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
485 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
486 static void clearSint16Buffer( Sint8* buffer, Sint16*r ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
487 { |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
488 while( r >= (Sint16*)buffer ) *r-- = 0; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
489 } |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
490 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
491 /*-------------------------------------------------------------------------*/ |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
492 static int doubleRateMono( AdapterC Data, int length ) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
493 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
494 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
495 RateConverterBuffer rcb; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
496 initRateConverterBuffer( &rcb, &Data, length, Half ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
497 r = 1 + doRateConversion( &rcb, doubleRate1 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
498 clearSint16Buffer( Data.buffer, r ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
499 return 2 * ( rcb.buffer - (Sint16*)Data.buffer + 2 ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
500 } |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
501 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
502 static int doubleRateStereo( AdapterC Data, int length ) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
503 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
504 Sint16* r; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
505 fprintf( stderr, "\n Buffer: %8x length: %8x\n", Data.buffer, length ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
506 RateConverterBuffer rcb; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
507 initRateConverterBuffer( &rcb, &Data, length, Half ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
508 doRateConversion( &rcb, doubleRate2 ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
509 nextRateConverterBuffer( &rcb ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
510 r = 2 + doRateConversion( &rcb, doubleRate2 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
511 clearSint16Buffer( Data.buffer, r ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
512 return 2 * ( rcb.buffer - (Sint16*)Data.buffer + 3 ); |
338 | 513 } |
514 | |
515 /*-------------------------------------------------------------------------*/ | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
516 static int halfRateMono( AdapterC Data, int length ) |
338 | 517 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
518 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
519 RateConverterBuffer rcb; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
520 initRateConverterBuffer( &rcb, &Data, length, Double ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
521 r = doRateConversion( &rcb, halfRate1 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
522 return 2 * ( r - (Sint16*)Data.buffer ); |
338 | 523 } |
524 | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
525 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
|
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 ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
530 doRateConversion( &rcb, halfRate2 ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
531 nextRateConverterBuffer( &rcb ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
532 r = doRateConversion( &rcb, halfRate2 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
533 return 2 * ( r - (Sint16*)Data.buffer ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
534 } |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
535 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
536 /*-------------------------------------------------------------------------*/ |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
537 static int increaseRateMono( AdapterC Data, int length ) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
538 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
539 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
540 RateConverterBuffer rcb; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
541 initRateConverterBuffer( &rcb, &Data, length, Data.filter->ratio ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
542 r = doRateConversion( &rcb, increaseRate1 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
543 clearSint16Buffer( Data.buffer, r ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
544 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
|
545 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
546 |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
547 static int increaseRateStereo( AdapterC Data, int length ) |
338 | 548 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
549 Sint16* r; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
550 fprintf( stderr, "\n Buffer: %8x length: %8x\n", Data.buffer, length ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
551 RateConverterBuffer rcb; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
552 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
|
553 doRateConversion( &rcb, increaseRate2 ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
554 nextRateConverterBuffer( &rcb ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
555 r = doRateConversion( &rcb, increaseRate2 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
556 clearSint16Buffer( Data.buffer, r ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
557 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
|
558 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
559 |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
560 /*-------------------------------------------------------------------------*/ |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
561 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
|
562 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
563 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
564 RateConverterBuffer rcb; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
565 initRateConverterBuffer( &rcb, &Data, length, Data.filter->ratio ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
566 r = doRateConversion( &rcb, decreaseRate1 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
567 return 2 * ( r - (Sint16*)Data.buffer ); |
338 | 568 } |
569 | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
570 static int decreaseRateStereo( AdapterC Data, int length ) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
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 ); |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
575 doRateConversion( &rcb, decreaseRate2 ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
576 nextRateConverterBuffer( &rcb ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
577 r = doRateConversion( &rcb, decreaseRate2 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
578 return 2 * ( r - (Sint16*)Data.buffer ); |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
579 } |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
580 |
338 | 581 /*-------------------------------------------------------------------------*/ |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
582 /* 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
|
583 static Fraction findFraction( float Value ) |
338 | 584 { |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
585 const Sint8 frac[95]={ |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
586 2, -1, /* /1 */ |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
587 1, 3, -1, /* /2 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
588 2, 4, 5, -1, /* /3 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
589 3, 5, 7, -1, /* /4 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
590 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
|
591 5, 7, 11, -1, /* /6 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
592 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
|
593 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
|
594 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
|
595 7, 9, 11, 13, -1, /* /10 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
596 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
|
597 7, 11, 13, -1, /* /12 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
598 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
|
599 9, 11, 13, 15, -1, /* /14 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
600 8, 11, 13, 14, 16, -1, /* /15 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
601 9, 11, 13, 15 }; /* /16 */ |
338 | 602 |
603 | |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
604 Fraction Result = {0,0}; |
371 | 605 int i,num,den=1; |
338 | 606 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
607 float RelErr, BestErr = 0; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
608 if( Value < 31/64. || Value > 64/31. ) return Result; |
338 | 609 |
371 | 610 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
|
611 { |
371 | 612 num = frac[i]; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
613 if( num < 0 ) den++; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
614 RelErr = Value * num / den; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
615 RelErr = min( RelErr, 1/RelErr ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
616 if( RelErr > BestErr ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
617 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
618 BestErr = RelErr; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
619 Result.denominator = den; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
620 Result.numerator = num; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
621 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
622 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
623 return Result; |
338 | 624 } |
625 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
626 /*-------------------------------------------------------------------------*/ |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
627 static float sinc( float x ) |
338 | 628 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
629 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
|
630 else return sin(x)/x; |
338 | 631 } |
632 | |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
633 static float calculateVarFilter( Sint16* dst, |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
634 float Ratio, float phase, float scale ) |
338 | 635 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
636 const Uint16 KaiserWindow7[]= { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
637 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
|
638 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
|
639 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
|
640 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
|
641 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
|
642 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
|
643 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
|
644 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
|
645 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
646 float w; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
647 const float fg = -.018 + .5 * Ratio; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
648 const float omega = 2 * M_PI * fg; |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
649 fprintf( stderr, " phase: %6g \n", phase ); |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
650 phase += 63; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
651 for( i = 0; i < 64; i++) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
652 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
653 w = scale * ( KaiserWindow7[i] * ( i + 1 )); |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
654 dst[i] = w * sinc( omega * (i-phase) ); |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
655 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
|
656 } |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
657 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
|
658 return fg; |
338 | 659 } |
660 | |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
661 static Fraction setupVarFilter( Sound_AudioCVT *Data, float Ratio ) |
371 | 662 { |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
663 int pos,n,d, incr, phase = 0; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
664 float Scale, rd, fg; |
371 | 665 Fraction IRatio; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
666 VarFilter* filter = &Data->filter; |
338 | 667 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
668 IRatio = findFraction( Ratio ); |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
669 // Scale = Ratio < 1. ? 0.0364733 : 0.0211952; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
670 Scale = 0.0084778; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
671 Ratio = min( Ratio, 0.97 ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
672 |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
673 filter->ratio = IRatio; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
674 n = IRatio.numerator; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
675 d = IRatio.denominator; |
371 | 676 rd = 1. / d; |
338 | 677 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
678 fprintf( stderr, "Filter:\n" ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
679 |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
680 for( pos = 0; pos < d; pos++ ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
681 { |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
682 fg = calculateVarFilter( filter->c[pos], Ratio, phase*rd, Scale ); |
371 | 683 phase += n; |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
684 filter->incr[pos] = phase / d; |
371 | 685 phase %= d; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
686 } |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
687 fprintf( stderr, " fg: %6g\n\n", fg ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
688 /* !!!FIXME: get rid of the inversion -Frank*/ |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
689 IRatio.numerator = d; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
690 IRatio.denominator = n; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
691 return IRatio; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
692 } |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
693 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
694 static void initAudioCVT( Sound_AudioCVT *Data ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
695 { |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
696 Data->len_ratio = 1.; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
697 Data->len_mult = 1; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
698 Data->add = 0; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
699 Data->len_add = 0; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
700 Data->filter_index = 0; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
701 } |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
702 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
703 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
|
704 { |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
705 double ratio = f.numerator / (double) f.denominator; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
706 Data->len_ratio *= ratio; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
707 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
|
708 Data->add = ratio * (Data->add + add); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
709 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
|
710 } |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
711 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
712 static Adapter* addAdapter( Sound_AudioCVT *Data, Adapter a ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
713 { |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
714 Data->adapter[Data->filter_index] = a; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
715 return &Data->adapter[Data->filter_index++]; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
716 } |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
717 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
718 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
|
719 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
720 adjustSize( Data, 0, Half ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
721 addAdapter( Data, a ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
722 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
723 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
724 static void addDAdapter( Sound_AudioCVT *Data, Adapter a ) |
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 adjustSize( Data, 0, Double ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
727 addAdapter( Data, a ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
728 } |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
729 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
730 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
731 /*-------------------------------------------------------------------------*/ |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
732 const Adapter doubleRate[2] = { doubleRateMono, doubleRateStereo }; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
733 const Adapter halfRate[2] = { halfRateMono, halfRateStereo }; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
734 const Adapter increaseRate[2] = { increaseRateMono, increaseRateStereo }; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
735 const Adapter decreaseRate[2] = { decreaseRateMono, decreaseRateStereo }; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
736 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
737 static int createRateConverter( Sound_AudioCVT *Data, |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
738 int SrcRate, int DestRate, int channel ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
739 { |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
740 const int c = channel - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
741 const int size = 16 * channel * _fsize; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
742 Adapter* AdapterPos; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
743 float Ratio = DestRate; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
744 Fraction f; |
338 | 745 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
746 if( SrcRate < 1 || SrcRate > 1<<18 || |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
747 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
|
748 Ratio /= SrcRate; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
749 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
750 AdapterPos = addAdapter( Data, minus5dB ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
751 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
752 while( Ratio > 64./31.) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
753 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
754 Ratio /= 2.; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
755 addAdapter( Data, doubleRate[c] ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
756 adjustSize( Data, size, Double ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
757 } |
338 | 758 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
759 while( Ratio < 31./64. ) |
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 Ratio *= 2; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
762 addAdapter( Data, halfRate[c] ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
763 adjustSize( Data, size, Half ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
764 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
765 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
766 if( Ratio > 1. ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
767 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
768 *AdapterPos = increaseRate[c]; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
769 f = setupVarFilter( Data, Ratio ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
770 adjustSize( Data, size, f ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
771 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
772 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
773 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
774 f = setupVarFilter( Data, Ratio ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
775 addAdapter( Data, decreaseRate[c]); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
776 adjustSize( Data, size, f ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
777 } |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
778 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
779 return 0; |
338 | 780 } |
781 | |
360
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 static void createFormatConverter16Bit(Sound_AudioCVT *Data, |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
784 SDL_AudioSpec src, SDL_AudioSpec dst ) |
338 | 785 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
786 if( src.channels == 2 && dst.channels == 1 ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
787 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
788 if( !IS_SYSENDIAN(src) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
789 addAdapter( Data, swapBytes ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
790 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
791 if( IS_SIGNED(src) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
792 addHAdapter( Data, convertStereoToMonoS16Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
793 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
794 addHAdapter( Data, convertStereoToMonoU16Bit ); |
338 | 795 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
796 if( !IS_SYSENDIAN(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
797 addAdapter( Data, swapBytes ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
798 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
799 else if( IS_SYSENDIAN(src) != IS_SYSENDIAN(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
800 addAdapter( Data, swapBytes ); |
338 | 801 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
802 if( IS_SIGNED(src) != IS_SIGNED(dst) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
803 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
804 if( IS_SYSENDIAN(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
805 addAdapter( Data, changeSigned16BitSys ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
806 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
807 addAdapter( Data, changeSigned16BitWrong ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
808 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
809 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
810 if( src.channels == 1 && dst.channels == 2 ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
811 addDAdapter( Data, convertMonoToStereo16Bit ); |
338 | 812 } |
813 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
814 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
815 static void createFormatConverter8Bit(Sound_AudioCVT *Data, |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
816 SDL_AudioSpec src, SDL_AudioSpec dst ) |
338 | 817 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
818 if( IS_16BIT(src) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
819 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
820 if( IS_SYSENDIAN(src) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
821 addHAdapter( Data, cut16BitSysTo8Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
822 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
823 addHAdapter( Data, cut16BitWrongTo8Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
824 } |
338 | 825 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
826 if( src.channels == 2 && dst.channels == 1 ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
827 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
828 if( IS_SIGNED(src) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
829 addHAdapter( Data, convertStereoToMonoS8Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
830 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
831 addHAdapter( Data, convertStereoToMonoU8Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
832 } |
338 | 833 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
834 if( IS_SIGNED(src) != IS_SIGNED(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
835 addDAdapter( Data, changeSigned8Bit ); |
360
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( src.channels == 1 && dst.channels == 2 ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
838 addDAdapter( Data, convertMonoToStereo8Bit ); |
338 | 839 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
840 if( !IS_8BIT(dst) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
841 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
842 if( IS_SYSENDIAN(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
843 addDAdapter( Data, expand8BitTo16BitSys ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
844 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
845 addDAdapter( Data, expand8BitTo16BitWrong ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
846 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
847 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
848 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
849 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
850 static void createFormatConverter(Sound_AudioCVT *Data, |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
851 SDL_AudioSpec src, SDL_AudioSpec dst ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
852 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
853 if( IS_FLOAT(src) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
854 addHAdapter( Data, cutFloatTo16Bit ); |
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 if( IS_8BIT(src) || IS_8BIT(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
857 createFormatConverter8Bit( Data, src, dst); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
858 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
859 createFormatConverter16Bit( Data, src, dst); |
338 | 860 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
861 if( IS_FLOAT(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
862 addDAdapter( Data, expand16BitToFloat ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
863 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
864 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
865 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
866 int Sound_AltBuildAudioCVT( Sound_AudioCVT *Data, |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
867 SDL_AudioSpec src, SDL_AudioSpec dst ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
868 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
869 SDL_AudioSpec im; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
870 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
871 if( Data == NULL ) return -1; |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
872 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
873 initAudioCVT( Data ); |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
874 Data->filter.ratio.denominator = 0; |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
875 Data->filter.mask = dst.size - 1; |
338 | 876 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
877 /* Check channels */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
878 if( src.channels < 1 || src.channels > 2 || |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
879 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
|
880 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
881 if( src.freq != dst.freq ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
882 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
883 /* Convert to intermidiate format: signed 16Bit System-Endian */ |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
884 im.format = AUDIO_S16SYS; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
885 im.channels = min( src.channels, dst.channels ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
886 createFormatConverter( Data, src, im ); |
338 | 887 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
888 /* Do rate conversion */ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
889 if( createRateConverter( Data, src.freq, dst.freq, im.channels ) ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
890 goto error_exit; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
891 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
892 src = im; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
893 } |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
894 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
895 /* Convert to final format */ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
896 createFormatConverter( Data, src, dst ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
897 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
898 /* Finalize adapter list */ |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
899 addAdapter( Data, NULL ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
900 /* !!! 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
|
901 Borland says no. -frank */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
902 return 0; |
338 | 903 |
904 error_exit: | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
905 /* !!! 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
|
906 Borland says no. -frank */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
907 Data->adapter[0] = NULL; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
908 return -1; |
338 | 909 } |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
910 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
911 /*-------------------------------------------------------------------------*/ |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
912 static char *fmt_to_str(Uint16 fmt) |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
913 { |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
914 switch (fmt) |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
915 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
916 case AUDIO_U8: return " U8"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
917 case AUDIO_S8: return " S8"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
918 case AUDIO_U16MSB: return "U16MSB"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
919 case AUDIO_S16MSB: return "S16MSB"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
920 case AUDIO_U16LSB: return "U16LSB"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
921 case AUDIO_S16LSB: return "S16LSB"; |
342
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 return "??????"; |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
924 } |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
925 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
926 #define AdapterDesc(x) { x, #x } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
927 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
928 static void show_AudioCVT( Sound_AudioCVT *Data ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
929 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
930 int i,j; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
931 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
|
932 AdapterDescription[] = { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
933 AdapterDesc(expand8BitTo16BitSys), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
934 AdapterDesc(expand8BitTo16BitWrong), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
935 AdapterDesc(expand16BitToFloat), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
936 AdapterDesc(swapBytes), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
937 AdapterDesc(cut16BitSysTo8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
938 AdapterDesc(cut16BitWrongTo8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
939 AdapterDesc(cutFloatTo16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
940 AdapterDesc(changeSigned16BitSys), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
941 AdapterDesc(changeSigned16BitWrong), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
942 AdapterDesc(changeSigned8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
943 AdapterDesc(convertStereoToMonoS16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
944 AdapterDesc(convertStereoToMonoU16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
945 AdapterDesc(convertStereoToMonoS8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
946 AdapterDesc(convertStereoToMonoU8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
947 AdapterDesc(convertMonoToStereo16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
948 AdapterDesc(convertMonoToStereo8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
949 AdapterDesc(minus5dB), |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
950 AdapterDesc(doubleRateMono), |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
951 AdapterDesc(doubleRateStereo), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
952 AdapterDesc(halfRateMono), |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
953 AdapterDesc(halfRateStereo), |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
954 AdapterDesc(increaseRateMono), |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
955 AdapterDesc(increaseRateStereo), |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
956 AdapterDesc(decreaseRateMono), |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
957 AdapterDesc(decreaseRateStereo), |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
958 { NULL, "----------NULL-----------\n" } |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
959 }; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
960 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
961 fprintf( stderr, "Sound_AudioCVT:\n" ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
962 fprintf( stderr, " needed: %8d\n", Data->needed ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
963 fprintf( stderr, " add: %8g\n", Data->add ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
964 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
|
965 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
|
966 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
|
967 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
|
968 fprintf( stderr, "\n" ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
969 |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
970 fprintf( stderr, "Adapter List: \n" ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
971 for( i = 0; i < 32; i++ ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
972 { |
366
eda146d666d1
More patches from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
365
diff
changeset
|
973 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
|
974 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
975 if( Data->adapter[i] == AdapterDescription[j].adapter ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
976 { |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
977 fprintf( stderr, " %s \n", AdapterDescription[j].name ); |
371 | 978 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
|
979 goto cont; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
980 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
981 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
982 fprintf( stderr, " Error: unknown adapter\n" ); |
371 | 983 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
984 cont: |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
985 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
986 fprintf( stderr, " Error: NULL adapter missing\n" ); |
371 | 987 sucess_exit: |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
988 if( Data->filter.ratio.denominator ) |
371 | 989 { |
990 fprintf( stderr, "Variable Rate Converter:\n" | |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
991 " numerator: %3d\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
992 " denominator: %3d\n", |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
993 Data->filter.ratio.denominator, |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
994 Data->filter.ratio.numerator ); |
371 | 995 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
996 fprintf( stderr, " increment sequence:\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
997 " " ); |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
998 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
|
999 fprintf( stderr, "%1d ", Data->filter.incr[i] ); |
371 | 1000 |
1001 fprintf( stderr, "\n" ); | |
1002 } | |
1003 else | |
1004 { | |
1005 fprintf( stderr, "No Variable Rate Converter\n" ); | |
1006 } | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1007 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1008 |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1009 |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1010 int Sound_BuildAudioCVT(Sound_AudioCVT *Data, |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
1011 Uint16 src_format, Uint8 src_channels, int src_rate, |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
1012 Uint16 dst_format, Uint8 dst_channels, int dst_rate ) |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1013 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1014 SDL_AudioSpec src, dst; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1015 int ret; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1016 |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1017 fprintf (stderr, |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1018 "Sound_BuildAudioCVT():\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1019 "-----------------------------\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1020 "format: %s -> %s\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1021 "channels: %6d -> %6d\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1022 "rate: %6d -> %6d\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1023 "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
|
1024 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
|
1025 src_channels, dst_channels, |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
1026 src_rate, dst_rate ); |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1027 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1028 src.format = src_format; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1029 src.channels = src_channels; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1030 src.freq = src_rate; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1031 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1032 dst.format = dst_format; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1033 dst.channels = dst_channels; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1034 dst.freq = dst_rate; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1035 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
1036 ret = Sound_AltBuildAudioCVT( Data, src, dst ); |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1037 Data->needed = 1; |
347
778cee61e1be
Mono-to-stereo fixes, more fprintf debugging output.
Ryan C. Gordon <icculus@icculus.org>
parents:
342
diff
changeset
|
1038 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1039 show_AudioCVT( Data ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1040 fprintf (stderr, "\n" |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1041 "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
|
1042 return ret; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1043 } |