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