Mercurial > SDL_sound_CoreAudio
annotate alt_audio_convert.c @ 451:573eaefef003
Initial add.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 13 Sep 2003 20:28:55 +0000 |
parents | 5b00e43ec23c |
children | 636796aed4e2 |
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; |
421 | 349 Uint16* buffer; |
350 Uint16* dst; | |
351 | |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
352 length >>=1; |
421 | 353 buffer = (Uint16*)Data.buffer - 1; |
354 dst = (Uint16*)Data.buffer + 2*length - 2; | |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
355 for( i = length + 1; --i; dst-=2 ) |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
356 dst[0] = dst[1] = buffer[i]; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
357 return 4*length; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
358 } |
338 | 359 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
360 static int convertMonoToStereo8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
361 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
362 int i; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
363 Uint8* buffer = Data.buffer - 1; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
364 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
|
365 for( i = length + 1; --i; dst-=2 ) |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
366 dst[0] = dst[1] = buffer[i]; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
367 return 2*length; |
338 | 368 } |
369 | |
370 /*-------------------------------------------------------------------------*/ | |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
371 static int minus5dB( AdapterC Data, int length ) |
338 | 372 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
373 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
374 Sint16* buffer = (Sint16*) Data.buffer; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
375 for(i = length>>1 + 1; --i; ) |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
376 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
|
377 return length; |
338 | 378 } |
379 | |
380 /*-------------------------------------------------------------------------*/ | |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
381 const Fraction Half = {1, 2}; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
382 const Fraction Double = {2, 1}; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
383 const Fraction One = {1, 1}; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
384 |
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 static void initStraigthBuffer( RateConverterBuffer *rcb, |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
387 int length, Fraction r ) |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
388 { |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
389 int i, size, minsize; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
390 size = 8 * _fsize; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
391 minsize = min( size, length ); |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
392 |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
393 for( i = 0; i < minsize; i++ ) |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
394 { |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
395 rcb->inbuffer[i] = rcb->buffer[length-size+i]; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
396 rcb->inbuffer[i+size] = 0; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
397 rcb->inbuffer[i+2*size] = rcb->buffer[i]; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
398 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
399 for( ; i < size; i++ ) |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
400 { |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
401 rcb->inbuffer[i] = 0; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
402 rcb->inbuffer[i+size] = 0; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
403 rcb->inbuffer[i+2*size] = 0; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
404 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
405 |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
406 length = max( length, size ); |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
407 rcb->flength = rcb->llength = size; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
408 rcb->clength = length - size; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
409 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
410 if( r.numerator < r.denominator ) |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
411 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
412 rcb->finp = rcb->inbuffer + 5*size/2; |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
413 rcb->cinp = rcb->buffer + length - size/2; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
414 rcb->linp = rcb->inbuffer + 3*size/2; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
415 rcb->buffer += ( 1 + r.denominator * ( length + size ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
416 / r.numerator ) & -2; |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
417 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
418 else |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
419 { |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
420 rcb->finp = rcb->inbuffer + size/2; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
421 rcb->cinp = rcb->buffer + size/2; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
422 rcb->linp = rcb->inbuffer + 3*size/2; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
423 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
424 } |
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 static void initLoopBuffer( RateConverterBuffer *rcb, |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
427 int length, Fraction r ) |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
428 { |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
429 /* !!!FIXME: modulo length, take scale into account, |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
430 check against the Straight part -frank */ |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
431 int i, size; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
432 size = 8 * _fsize; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
433 for( i = 0; i < size; 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->inbuffer[i] = rcb->buffer[length-size+i]; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
436 rcb->inbuffer[i+size] = rcb->buffer[i]; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
437 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
438 rcb->finp = rcb->linp = rcb->inbuffer + size; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
439 if( size < 0 ) |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
440 rcb->buffer += r.numerator * ( length + 2 * size ) |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
441 / r.denominator; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
442 } |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
443 |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
444 static void initRateConverterBuffer( RateConverterBuffer *rcb, |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
445 AdapterC* Data, int length, Fraction ratio ) |
338 | 446 { |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
447 length >>= 1; |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
448 rcb->buffer = (Sint16*)( Data->buffer ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
449 rcb->filter = Data->filter; |
338 | 450 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
451 if( Data->mode & SDL_SOUND_Loop ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
452 initLoopBuffer( rcb, length, ratio ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
453 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
454 initStraigthBuffer( rcb, length, ratio ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
455 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
456 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
|
457 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
|
458 fprintf( stderr, " linp: %8x length: %8x\n", rcb->linp, rcb->llength ); |
338 | 459 } |
460 | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
461 static void nextRateConverterBuffer( RateConverterBuffer *rcb ) |
338 | 462 { |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
463 rcb->buffer++; |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
464 rcb->finp++; |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
465 rcb->cinp++; |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
466 rcb->linp++; |
338 | 467 } |
468 | |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
469 typedef Sint16* (*RateConverter)( Sint16*, Sint16*, int, |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
470 VarFilter*, RateAux* ); |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
471 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
472 static Sint16* doRateConversion( RateConverterBuffer* rcb, RateConverter rc ) |
338 | 473 { |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
474 RateAux aux = {0,0}; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
475 Sint16 *outp = rcb->buffer; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
476 VarFilter* filter = rcb->filter; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
477 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
478 outp = (*rc)( outp, rcb->finp, rcb->flength, filter, &aux ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
479 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
|
480 outp = (*rc)( outp, rcb->cinp, rcb->clength, filter, &aux ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
481 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
|
482 outp = (*rc)( outp, rcb->linp, rcb->llength, filter, &aux ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
483 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
|
484 return outp; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
485 } |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
486 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
487 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
488 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
489 static void clearSint16Buffer( Sint8* buffer, Sint16*r ) |
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 while( r >= (Sint16*)buffer ) *r-- = 0; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
492 } |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
493 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
494 /*-------------------------------------------------------------------------*/ |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
495 static int doubleRateMono( AdapterC Data, int length ) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
496 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
497 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
498 RateConverterBuffer rcb; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
499 initRateConverterBuffer( &rcb, &Data, length, Half ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
500 r = 1 + doRateConversion( &rcb, doubleRate1 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
501 clearSint16Buffer( Data.buffer, r ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
502 return 2 * ( rcb.buffer - (Sint16*)Data.buffer + 2 ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
503 } |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
504 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
505 static int doubleRateStereo( AdapterC Data, int length ) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
506 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
507 Sint16* r; |
421 | 508 RateConverterBuffer rcb; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
509 fprintf( stderr, "\n Buffer: %8x length: %8x\n", Data.buffer, length ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
510 initRateConverterBuffer( &rcb, &Data, length, Half ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
511 doRateConversion( &rcb, doubleRate2 ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
512 nextRateConverterBuffer( &rcb ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
513 r = 2 + doRateConversion( &rcb, doubleRate2 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
514 clearSint16Buffer( Data.buffer, r ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
515 return 2 * ( rcb.buffer - (Sint16*)Data.buffer + 3 ); |
338 | 516 } |
517 | |
518 /*-------------------------------------------------------------------------*/ | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
519 static int halfRateMono( AdapterC Data, int length ) |
338 | 520 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
521 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
522 RateConverterBuffer rcb; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
523 initRateConverterBuffer( &rcb, &Data, length, Double ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
524 r = doRateConversion( &rcb, halfRate1 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
525 return 2 * ( r - (Sint16*)Data.buffer ); |
338 | 526 } |
527 | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
528 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
|
529 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
530 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
531 RateConverterBuffer rcb; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
532 initRateConverterBuffer( &rcb, &Data, length, Double ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
533 doRateConversion( &rcb, halfRate2 ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
534 nextRateConverterBuffer( &rcb ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
535 r = doRateConversion( &rcb, halfRate2 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
536 return 2 * ( r - (Sint16*)Data.buffer ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
537 } |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
538 |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
539 /*-------------------------------------------------------------------------*/ |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
540 static int increaseRateMono( AdapterC Data, int length ) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
541 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
542 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
543 RateConverterBuffer rcb; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
544 initRateConverterBuffer( &rcb, &Data, length, Data.filter->ratio ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
545 r = doRateConversion( &rcb, increaseRate1 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
546 clearSint16Buffer( Data.buffer, r ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
547 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
|
548 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
549 |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
550 static int increaseRateStereo( AdapterC Data, int length ) |
338 | 551 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
552 Sint16* r; |
421 | 553 RateConverterBuffer rcb; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
554 fprintf( stderr, "\n Buffer: %8x length: %8x\n", Data.buffer, length ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
555 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
|
556 doRateConversion( &rcb, increaseRate2 ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
557 nextRateConverterBuffer( &rcb ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
558 r = doRateConversion( &rcb, increaseRate2 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
559 clearSint16Buffer( Data.buffer, r ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
560 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
|
561 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
562 |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
563 /*-------------------------------------------------------------------------*/ |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
564 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
|
565 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
566 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
567 RateConverterBuffer rcb; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
568 initRateConverterBuffer( &rcb, &Data, length, Data.filter->ratio ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
569 r = doRateConversion( &rcb, decreaseRate1 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
570 return 2 * ( r - (Sint16*)Data.buffer ); |
338 | 571 } |
572 | |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
573 static int decreaseRateStereo( AdapterC Data, int length ) |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
574 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
575 Sint16* r; |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
576 RateConverterBuffer rcb; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
577 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
|
578 doRateConversion( &rcb, decreaseRate2 ); |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
579 nextRateConverterBuffer( &rcb ); |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
580 r = doRateConversion( &rcb, decreaseRate2 ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
581 return 2 * ( r - (Sint16*)Data.buffer ); |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
582 } |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
583 |
338 | 584 /*-------------------------------------------------------------------------*/ |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
585 /* 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
|
586 static Fraction findFraction( float Value ) |
338 | 587 { |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
588 const Sint8 frac[95]={ |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
589 2, -1, /* /1 */ |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
590 1, 3, -1, /* /2 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
591 2, 4, 5, -1, /* /3 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
592 3, 5, 7, -1, /* /4 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
593 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
|
594 5, 7, 11, -1, /* /6 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
595 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
|
596 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
|
597 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
|
598 7, 9, 11, 13, -1, /* /10 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
599 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
|
600 7, 11, 13, -1, /* /12 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
601 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
|
602 9, 11, 13, 15, -1, /* /14 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
603 8, 11, 13, 14, 16, -1, /* /15 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
604 9, 11, 13, 15 }; /* /16 */ |
338 | 605 |
606 | |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
607 Fraction Result = {0,0}; |
371 | 608 int i,num,den=1; |
338 | 609 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
610 float RelErr, BestErr = 0; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
611 if( Value < 31/64. || Value > 64/31. ) return Result; |
338 | 612 |
371 | 613 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
|
614 { |
371 | 615 num = frac[i]; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
616 if( num < 0 ) den++; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
617 RelErr = Value * num / den; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
618 RelErr = min( RelErr, 1/RelErr ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
619 if( RelErr > BestErr ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
620 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
621 BestErr = RelErr; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
622 Result.denominator = den; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
623 Result.numerator = num; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
624 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
625 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
626 return Result; |
338 | 627 } |
628 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
629 /*-------------------------------------------------------------------------*/ |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
630 static float sinc( float x ) |
338 | 631 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
632 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
|
633 else return sin(x)/x; |
338 | 634 } |
635 | |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
636 static float calculateVarFilter( Sint16* dst, |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
637 float Ratio, float phase, float scale ) |
338 | 638 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
639 const Uint16 KaiserWindow7[]= { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
640 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
|
641 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
|
642 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
|
643 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
|
644 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
|
645 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
|
646 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
|
647 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
|
648 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
649 float w; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
650 const float fg = -.018 + .5 * Ratio; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
651 const float omega = 2 * M_PI * fg; |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
652 fprintf( stderr, " phase: %6g \n", phase ); |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
653 phase += 63; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
654 for( i = 0; i < 64; i++) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
655 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
656 w = scale * ( KaiserWindow7[i] * ( i + 1 )); |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
657 dst[i] = w * sinc( omega * (i-phase) ); |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
658 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
|
659 } |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
660 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
|
661 return fg; |
338 | 662 } |
663 | |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
664 static Fraction setupVarFilter( Sound_AudioCVT *Data, float Ratio ) |
371 | 665 { |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
666 int pos,n,d, incr, phase = 0; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
667 float Scale, rd, fg; |
371 | 668 Fraction IRatio; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
669 VarFilter* filter = &Data->filter; |
338 | 670 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
671 IRatio = findFraction( Ratio ); |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
672 // Scale = Ratio < 1. ? 0.0364733 : 0.0211952; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
673 Scale = 0.0084778; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
674 Ratio = min( Ratio, 0.97 ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
675 |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
676 filter->ratio = IRatio; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
677 n = IRatio.numerator; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
678 d = IRatio.denominator; |
371 | 679 rd = 1. / d; |
338 | 680 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
681 fprintf( stderr, "Filter:\n" ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
682 |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
683 for( pos = 0; pos < d; pos++ ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
684 { |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
685 fg = calculateVarFilter( filter->c[pos], Ratio, phase*rd, Scale ); |
371 | 686 phase += n; |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
687 filter->incr[pos] = phase / d; |
371 | 688 phase %= d; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
689 } |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
690 fprintf( stderr, " fg: %6g\n\n", fg ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
691 /* !!!FIXME: get rid of the inversion -Frank*/ |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
692 IRatio.numerator = d; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
693 IRatio.denominator = n; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
694 return IRatio; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
695 } |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
696 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
697 static void initAudioCVT( Sound_AudioCVT *Data ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
698 { |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
699 Data->len_ratio = 1.; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
700 Data->len_mult = 1; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
701 Data->add = 0; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
702 Data->len_add = 0; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
703 Data->filter_index = 0; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
704 } |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
705 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
706 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
|
707 { |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
708 double ratio = f.numerator / (double) f.denominator; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
709 Data->len_ratio *= ratio; |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
710 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
|
711 Data->add = ratio * (Data->add + add); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
712 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
|
713 } |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
714 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
715 static Adapter* addAdapter( Sound_AudioCVT *Data, Adapter a ) |
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 Data->adapter[Data->filter_index] = a; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
718 return &Data->adapter[Data->filter_index++]; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
719 } |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
720 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
721 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
|
722 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
723 adjustSize( Data, 0, Half ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
724 addAdapter( Data, a ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
725 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
726 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
727 static void addDAdapter( Sound_AudioCVT *Data, Adapter 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 adjustSize( Data, 0, Double ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
730 addAdapter( Data, a ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
731 } |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
732 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
733 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
734 /*-------------------------------------------------------------------------*/ |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
735 const Adapter doubleRate[2] = { doubleRateMono, doubleRateStereo }; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
736 const Adapter halfRate[2] = { halfRateMono, halfRateStereo }; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
737 const Adapter increaseRate[2] = { increaseRateMono, increaseRateStereo }; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
738 const Adapter decreaseRate[2] = { decreaseRateMono, decreaseRateStereo }; |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
739 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
740 static int createRateConverter( Sound_AudioCVT *Data, |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
741 int SrcRate, int DestRate, int channel ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
742 { |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
743 const int c = channel - 1; |
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
744 const int size = 16 * channel * _fsize; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
745 Adapter* AdapterPos; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
746 float Ratio = DestRate; |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
747 Fraction f; |
338 | 748 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
749 if( SrcRate < 1 || SrcRate > 1<<18 || |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
750 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
|
751 Ratio /= SrcRate; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
752 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
753 AdapterPos = addAdapter( Data, minus5dB ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
754 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
755 while( Ratio > 64./31.) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
756 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
757 Ratio /= 2.; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
758 addAdapter( Data, doubleRate[c] ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
759 adjustSize( Data, size, Double ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
760 } |
338 | 761 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
762 while( Ratio < 31./64. ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
763 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
764 Ratio *= 2; |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
765 addAdapter( Data, halfRate[c] ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
766 adjustSize( Data, size, Half ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
767 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
768 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
769 if( Ratio > 1. ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
770 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
771 *AdapterPos = increaseRate[c]; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
772 f = setupVarFilter( Data, Ratio ); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
773 adjustSize( Data, size, f ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
774 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
775 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
776 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
777 f = setupVarFilter( Data, Ratio ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
778 addAdapter( Data, decreaseRate[c]); |
403
b1e511c879d1
More altcvt updates and fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
380
diff
changeset
|
779 adjustSize( Data, size, f ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
780 } |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
781 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
782 return 0; |
338 | 783 } |
784 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
785 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
786 static void createFormatConverter16Bit(Sound_AudioCVT *Data, |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
787 SDL_AudioSpec src, SDL_AudioSpec dst ) |
338 | 788 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
789 if( src.channels == 2 && dst.channels == 1 ) |
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_SYSENDIAN(src) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
792 addAdapter( Data, swapBytes ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
793 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
794 if( IS_SIGNED(src) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
795 addHAdapter( Data, convertStereoToMonoS16Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
796 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
797 addHAdapter( Data, convertStereoToMonoU16Bit ); |
338 | 798 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
799 if( !IS_SYSENDIAN(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
800 addAdapter( Data, swapBytes ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
801 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
802 else if( IS_SYSENDIAN(src) != IS_SYSENDIAN(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
803 addAdapter( Data, swapBytes ); |
338 | 804 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
805 if( IS_SIGNED(src) != IS_SIGNED(dst) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
806 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
807 if( IS_SYSENDIAN(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
808 addAdapter( Data, changeSigned16BitSys ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
809 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
810 addAdapter( Data, changeSigned16BitWrong ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
811 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
812 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
813 if( src.channels == 1 && dst.channels == 2 ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
814 addDAdapter( Data, convertMonoToStereo16Bit ); |
338 | 815 } |
816 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
817 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
818 static void createFormatConverter8Bit(Sound_AudioCVT *Data, |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
819 SDL_AudioSpec src, SDL_AudioSpec dst ) |
338 | 820 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
821 if( IS_16BIT(src) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
822 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
823 if( IS_SYSENDIAN(src) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
824 addHAdapter( Data, cut16BitSysTo8Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
825 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
826 addHAdapter( Data, cut16BitWrongTo8Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
827 } |
338 | 828 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
829 if( src.channels == 2 && dst.channels == 1 ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
830 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
831 if( IS_SIGNED(src) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
832 addHAdapter( Data, convertStereoToMonoS8Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
833 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
834 addHAdapter( Data, convertStereoToMonoU8Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
835 } |
338 | 836 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
837 if( IS_SIGNED(src) != IS_SIGNED(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
838 addDAdapter( Data, changeSigned8Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
839 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
840 if( src.channels == 1 && dst.channels == 2 ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
841 addDAdapter( Data, convertMonoToStereo8Bit ); |
338 | 842 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
843 if( !IS_8BIT(dst) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
844 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
845 if( IS_SYSENDIAN(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
846 addDAdapter( Data, expand8BitTo16BitSys ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
847 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
848 addDAdapter( Data, expand8BitTo16BitWrong ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
849 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
850 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
851 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
852 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
853 static void createFormatConverter(Sound_AudioCVT *Data, |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
854 SDL_AudioSpec src, SDL_AudioSpec dst ) |
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_FLOAT(src) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
857 addHAdapter( Data, cutFloatTo16Bit ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
858 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
859 if( IS_8BIT(src) || IS_8BIT(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
860 createFormatConverter8Bit( Data, src, dst); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
861 else |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
862 createFormatConverter16Bit( Data, src, dst); |
338 | 863 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
864 if( IS_FLOAT(dst) ) |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
865 addDAdapter( Data, expand16BitToFloat ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
866 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
867 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
868 /*-------------------------------------------------------------------------*/ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
869 int Sound_AltBuildAudioCVT( Sound_AudioCVT *Data, |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
870 SDL_AudioSpec src, SDL_AudioSpec dst ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
871 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
872 SDL_AudioSpec im; |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
873 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
874 if( Data == NULL ) return -1; |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
875 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
876 initAudioCVT( Data ); |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
877 Data->filter.ratio.denominator = 0; |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
878 Data->filter.mask = dst.size - 1; |
338 | 879 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
880 /* Check channels */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
881 if( src.channels < 1 || src.channels > 2 || |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
882 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
|
883 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
884 if( src.freq != dst.freq ) |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
885 { |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
886 /* Convert to intermidiate format: signed 16Bit System-Endian */ |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
887 im.format = AUDIO_S16SYS; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
888 im.channels = min( src.channels, dst.channels ); |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
889 createFormatConverter( Data, src, im ); |
338 | 890 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
891 /* Do rate conversion */ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
892 if( createRateConverter( Data, src.freq, dst.freq, im.channels ) ) |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
893 goto error_exit; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
894 |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
895 src = im; |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
896 } |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
897 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
898 /* Convert to final format */ |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
899 createFormatConverter( Data, src, dst ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
900 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
901 /* Finalize adapter list */ |
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
902 addAdapter( Data, NULL ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
903 /* !!! 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
|
904 Borland says no. -frank */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
905 return 0; |
338 | 906 |
907 error_exit: | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
908 /* !!! 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
|
909 Borland says no. -frank */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
910 Data->adapter[0] = NULL; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
911 return -1; |
338 | 912 } |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
913 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
914 /*-------------------------------------------------------------------------*/ |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
915 static char *fmt_to_str(Uint16 fmt) |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
916 { |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
917 switch (fmt) |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
918 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
919 case AUDIO_U8: return " U8"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
920 case AUDIO_S8: return " S8"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
921 case AUDIO_U16MSB: return "U16MSB"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
922 case AUDIO_S16MSB: return "S16MSB"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
923 case AUDIO_U16LSB: return "U16LSB"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
924 case AUDIO_S16LSB: return "S16LSB"; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
925 } |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
926 return "??????"; |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
927 } |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
928 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
929 #define AdapterDesc(x) { x, #x } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
930 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
931 static void show_AudioCVT( Sound_AudioCVT *Data ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
932 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
933 int i,j; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
934 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
|
935 AdapterDescription[] = { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
936 AdapterDesc(expand8BitTo16BitSys), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
937 AdapterDesc(expand8BitTo16BitWrong), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
938 AdapterDesc(expand16BitToFloat), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
939 AdapterDesc(swapBytes), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
940 AdapterDesc(cut16BitSysTo8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
941 AdapterDesc(cut16BitWrongTo8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
942 AdapterDesc(cutFloatTo16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
943 AdapterDesc(changeSigned16BitSys), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
944 AdapterDesc(changeSigned16BitWrong), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
945 AdapterDesc(changeSigned8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
946 AdapterDesc(convertStereoToMonoS16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
947 AdapterDesc(convertStereoToMonoU16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
948 AdapterDesc(convertStereoToMonoS8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
949 AdapterDesc(convertStereoToMonoU8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
950 AdapterDesc(convertMonoToStereo16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
951 AdapterDesc(convertMonoToStereo8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
952 AdapterDesc(minus5dB), |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
953 AdapterDesc(doubleRateMono), |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
954 AdapterDesc(doubleRateStereo), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
955 AdapterDesc(halfRateMono), |
365
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
956 AdapterDesc(halfRateStereo), |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
957 AdapterDesc(increaseRateMono), |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
958 AdapterDesc(increaseRateStereo), |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
959 AdapterDesc(decreaseRateMono), |
f61eadea1f44
More revisions from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
360
diff
changeset
|
960 AdapterDesc(decreaseRateStereo), |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
961 { NULL, "----------NULL-----------\n" } |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
962 }; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
963 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
964 fprintf( stderr, "Sound_AudioCVT:\n" ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
965 fprintf( stderr, " needed: %8d\n", Data->needed ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
966 fprintf( stderr, " add: %8g\n", Data->add ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
967 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
|
968 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
|
969 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
|
970 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
|
971 fprintf( stderr, "\n" ); |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
972 |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
973 fprintf( stderr, "Adapter List: \n" ); |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
974 for( i = 0; i < 32; i++ ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
975 { |
366
eda146d666d1
More patches from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
365
diff
changeset
|
976 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
|
977 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
978 if( Data->adapter[i] == AdapterDescription[j].adapter ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
979 { |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
980 fprintf( stderr, " %s \n", AdapterDescription[j].name ); |
371 | 981 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
|
982 goto cont; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
983 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
984 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
985 fprintf( stderr, " Error: unknown adapter\n" ); |
371 | 986 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
987 cont: |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
988 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
989 fprintf( stderr, " Error: NULL adapter missing\n" ); |
371 | 990 sucess_exit: |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
991 if( Data->filter.ratio.denominator ) |
371 | 992 { |
993 fprintf( stderr, "Variable Rate Converter:\n" | |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
994 " numerator: %3d\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
995 " denominator: %3d\n", |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
996 Data->filter.ratio.denominator, |
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
997 Data->filter.ratio.numerator ); |
371 | 998 |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
999 fprintf( stderr, " increment sequence:\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1000 " " ); |
380
44ed8bdeba74
More fixes from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
373
diff
changeset
|
1001 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
|
1002 fprintf( stderr, "%1d ", Data->filter.incr[i] ); |
371 | 1003 |
1004 fprintf( stderr, "\n" ); | |
1005 } | |
1006 else | |
1007 { | |
1008 fprintf( stderr, "No Variable Rate Converter\n" ); | |
1009 } | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1010 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1011 |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1012 |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1013 int Sound_BuildAudioCVT(Sound_AudioCVT *Data, |
441
5b00e43ec23c
Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
1014 Uint16 src_format, Uint8 src_channels, Uint32 src_rate, |
5b00e43ec23c
Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents:
421
diff
changeset
|
1015 Uint16 dst_format, Uint8 dst_channels, Uint32 dst_rate, Uint32 bufsize) |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1016 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1017 SDL_AudioSpec src, dst; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1018 int ret; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1019 |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1020 fprintf (stderr, |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1021 "Sound_BuildAudioCVT():\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1022 "-----------------------------\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1023 "format: %s -> %s\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1024 "channels: %6d -> %6d\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1025 "rate: %6d -> %6d\n" |
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1026 "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
|
1027 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
|
1028 src_channels, dst_channels, |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
1029 src_rate, dst_rate ); |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1030 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1031 src.format = src_format; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1032 src.channels = src_channels; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1033 src.freq = src_rate; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1034 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1035 dst.format = dst_format; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1036 dst.channels = dst_channels; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1037 dst.freq = dst_rate; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1038 |
420
5b8a07b5162e
Latest altcvt from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
403
diff
changeset
|
1039 ret = Sound_AltBuildAudioCVT( Data, src, dst ); |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1040 Data->needed = 1; |
347
778cee61e1be
Mono-to-stereo fixes, more fprintf debugging output.
Ryan C. Gordon <icculus@icculus.org>
parents:
342
diff
changeset
|
1041 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1042 show_AudioCVT( Data ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
1043 fprintf (stderr, "\n" |
373
24a610dfbbfd
More altcvt updates from Frank.
Ryan C. Gordon <icculus@icculus.org>
parents:
371
diff
changeset
|
1044 "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
|
1045 return ret; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
1046 } |