Mercurial > SDL_sound_CoreAudio
annotate alt_audio_convert.c @ 360:c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 12 Jun 2002 08:35:23 +0000 |
parents | 778cee61e1be |
children | f61eadea1f44 |
rev | line source |
---|---|
338 | 1 /* |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
2 Extended Audio Converter for SDL (Simple DirectMedia Layer) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
3 Copyright (C) 2002 Frank Ranostaj |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
4 Institute of Applied Physik |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
5 Johann Wolfgang Goethe-Universität |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
6 Frankfurt am Main, Germany |
338 | 7 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
8 This library is free software; you can redistribute it and/or |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
9 modify it under the terms of the GNU Library General Public |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
10 License as published by the Free Software Foundation; either |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
11 version 2 of the License, or (at your option) any later version. |
338 | 12 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
13 This library is distributed in the hope that it will be useful, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
16 Library General Public License for more details. |
338 | 17 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
18 You should have received a copy of the GNU Library General Public |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
19 License along with this library; if not, write to the Free |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
338 | 21 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
22 Frank Ranostaj |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
23 ranostaj@stud.uni-frankfurt.de |
338 | 24 |
25 (This code blatantly abducted for SDL_sound. Thanks, Frank! --ryan.) | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
26 |
338 | 27 */ |
28 #include "alt_audio_convert.h" | |
29 #include <stdlib.h> | |
30 #include <math.h> | |
31 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
32 /* some macros for "parsing" format */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
33 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
34 #define IS_8BIT(x) ((x).format & 0x0008) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
35 #define IS_16BIT(x) ((x).format & 0x0010) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
36 #define IS_FLOAT(x) ((x).format & 0x0020) /* !!! FIXME: is this ok? */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
37 #define IS_SIGNED(x) ((x).format & 0x8000) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
38 #define IS_SYSENDIAN(x) ((AUDIO_U16SYS ^ (x).format) & 0x1000) |
338 | 39 |
40 | |
41 /*-------------------------------------------------------------------------*/ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
42 /* this filter (Kaiser-window beta=6.8) gives a decent -80dB attentuation */ |
338 | 43 static const int filter[_fsize/2] = { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
44 0, 20798, 0, -6764, 0, 3863, 0, -2560, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
45 0, 1800, 0, -1295, 0, 936, 0, -671, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
46 0, 474, 0, -326, 0, 217, 0, -138, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
47 0, 83, 0, -46, 0, 23, 0, -9 }; |
338 | 48 |
49 /* Mono (1 channel ) */ | |
50 #define Suffix(x) x##1 | |
51 #include "filter_templates.h" | |
52 #undef Suffix | |
53 | |
54 /* Stereo (2 channel ) */ | |
55 #define Suffix(x) x##2 | |
56 #include "filter_templates.h" | |
57 #undef Suffix | |
58 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
59 /*-------------------------------------------------------------------------*/ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
60 static int ConvertAudio( Sound_AudioCVT *Data, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
61 Uint8* buffer, int length, int mode ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
62 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
63 AdapterC Temp; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
64 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
65 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
66 /* Make sure there's a converter */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
67 if( Data == NULL ) { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
68 SDL_SetError("No converter given"); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
69 return(-1); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
70 } |
338 | 71 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
72 /* Make sure there's data to convert */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
73 if( buffer == NULL ) { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
74 SDL_SetError("No buffer allocated for conversion"); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
75 return(-1); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
76 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
77 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
78 /* Set up the conversion and go! */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
79 Temp.buffer = buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
80 Temp.mode = mode; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
81 Temp.filter = &Data->filter; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
82 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
83 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
|
84 length = (*Data->adapter[i])( Temp, length); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
85 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
86 return length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
87 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
88 |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
89 int Sound_ConvertAudio( Sound_AudioCVT *Data ) |
338 | 90 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
91 /* !!! FIXME: Try the looping stuff under certain circumstances? --ryan. */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
92 return ConvertAudio( Data, Data->buf, Data->len, 0 ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
93 } |
338 | 94 |
95 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
96 /*-------------------------------------------------------------------------*/ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
97 static int expand8BitTo16BitSys( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
98 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
99 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
100 Uint8* inp = Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
101 Uint16* buffer = (Uint16*)Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
102 for( i = length; i--; ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
103 buffer[i] = inp[i]<<8; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
104 return 2*length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
105 } |
338 | 106 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
107 static int expand8BitTo16BitWrong( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
108 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
109 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
110 Uint8* inp = Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
111 Uint16* buffer = (Uint16*)Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
112 for( i = length; i--; ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
113 buffer[i] = inp[i]; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
114 return 2*length; |
338 | 115 } |
116 | |
117 /*-------------------------------------------------------------------------*/ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
118 static int expand16BitToFloat( AdapterC Data, int length ) |
338 | 119 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
120 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
121 Sint16* inp = (Sint16*)Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
122 float* buffer = (float*)Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
123 for( i = length>>1; i--; ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
124 buffer[i] = inp[i]*(1./32767); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
125 return 2*length; |
338 | 126 } |
127 | |
128 /*-------------------------------------------------------------------------*/ | |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
129 static int swapBytes( AdapterC Data, int length ) |
338 | 130 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
131 /* |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
132 * !!! FIXME !!! |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
133 * |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
134 * |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
135 * Use the faster SDL-Macros to swap |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
136 * - Frank |
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 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
139 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
140 Uint16 a,b; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
141 Uint16* buffer = (Uint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
142 for( i = length>>1; i --; ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
143 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
144 a = b = buffer[i]; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
145 buffer[i] = ( a << 8 ) | ( b >> 8 ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
146 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
147 return length; |
338 | 148 } |
149 | |
150 /*-------------------------------------------------------------------------*/ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
151 static int cutFloatTo16Bit( AdapterC Data, int length ) |
338 | 152 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
153 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
154 float* inp = (float*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
155 Sint16* buffer = (Sint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
156 length>>=2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
157 for( i = 0; i < length; i++ ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
158 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
159 if( inp[i] > 1. ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
160 buffer[i] = 32767; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
161 else if( inp[i] < -1. ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
162 buffer[i] = -32768; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
163 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
164 buffer[i] = 32767 * inp[i]; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
165 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
166 return 2*length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
167 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
168 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
169 /*-------------------------------------------------------------------------*/ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
170 static int cut16BitSysTo8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
171 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
172 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
173 Uint16* inp = (Uint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
174 Uint8* buffer = Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
175 length >>= 1; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
176 for( i = 0; i < length; i++ ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
177 buffer[i] = inp[i]>>8; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
178 return length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
179 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
180 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
181 static int cut16BitWrongTo8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
182 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
183 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
184 Uint16* inp = (Uint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
185 Uint8* buffer = Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
186 length >>= 1; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
187 for( i = 0; i < length; i++ ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
188 buffer[i] = inp[i] & 0xff; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
189 return length; |
338 | 190 } |
191 | |
192 /*-------------------------------------------------------------------------*/ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
193 static int changeSigned( AdapterC Data, int length, int XOR ) |
338 | 194 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
195 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
196 Uint32* buffer = (Uint32*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
197 for( i = length>>2; i--; ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
198 buffer[i] ^= XOR; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
199 for( i = 4*(length>>2); i < length; i++) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
200 ((Uint8*)buffer)[i] ^= ((Uint8*)&XOR)[i&3]; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
201 return length; |
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 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
204 static int changeSigned16BitSys( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
205 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
206 return changeSigned( Data, length, 0x80008000 ); |
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 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
209 static int changeSigned16BitWrong( AdapterC Data, int length ) |
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 changeSigned( Data, length, 0x00800080 ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
212 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
213 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
214 static int changeSigned8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
215 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
216 return changeSigned( Data, length, 0x80808080 ); |
338 | 217 } |
218 | |
219 /*-------------------------------------------------------------------------*/ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
220 static int convertStereoToMonoS16Bit( AdapterC Data, int length ) |
338 | 221 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
222 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
223 Sint16* buffer = (Sint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
224 Sint16* src = (Sint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
225 length >>= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
226 for( i = 0; i < length; i++ ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
227 buffer[i] = ((int) *(src++) + *(src++) ) >> 1; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
228 return 2*length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
229 } |
338 | 230 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
231 static int convertStereoToMonoU16Bit( AdapterC Data, int length ) |
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 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
234 Uint16* buffer = (Uint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
235 Uint16* src = (Uint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
236 length >>= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
237 for( i = 0; i < length; i++ ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
238 buffer[i] = ((int) *(src++) + *(src++) ) >> 1; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
239 return 2*length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
240 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
241 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
242 static int convertStereoToMonoS8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
243 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
244 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
245 Sint8* buffer = (Sint8*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
246 Sint8* src = (Sint8*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
247 length >>= 1; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
248 for( i = 0; i < length; i++ ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
249 buffer[i] = ((int) *(src++) + *(src++) ) >> 1; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
250 return length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
251 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
252 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
253 static int convertStereoToMonoU8Bit( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
254 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
255 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
256 Uint8* buffer = (Uint8*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
257 Uint8* src = (Uint8*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
258 length >>= 1; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
259 for( i = 0; i < length; i++ ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
260 buffer[i] = ((int) *(src++) + *(src++) ) >> 1; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
261 return length; |
338 | 262 } |
263 | |
264 /*-------------------------------------------------------------------------*/ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
265 static int convertMonoToStereo16Bit( AdapterC Data, int length ) |
338 | 266 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
267 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
268 Uint16* buffer = (Uint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
269 Uint16* dst = (Uint16*)Data.buffer + length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
270 for( i = length>>1; i--; ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
271 *(--dst) = *(--dst) = buffer[i]; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
272 return 2*length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
273 } |
338 | 274 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
275 static int convertMonoToStereo8Bit( AdapterC Data, int length ) |
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 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
278 Uint8* buffer = Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
279 Uint8* dst = Data.buffer + 2*length; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
280 for( i = length; i--; ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
281 *(--dst) = *(--dst) = buffer[i]; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
282 return 2*length; |
338 | 283 } |
284 | |
285 /*-------------------------------------------------------------------------*/ | |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
286 static int minus5dB( AdapterC Data, int length ) |
338 | 287 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
288 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
289 Sint16* buffer = (Sint16*) Data.buffer; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
290 for(i = length>>1; i--; ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
291 buffer[i]= 38084 * buffer[i] >> 16; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
292 return length; |
338 | 293 } |
294 | |
295 /*-------------------------------------------------------------------------*/ | |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
296 static int doubleRateStereo( AdapterC Data, int length ) |
338 | 297 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
298 length >>= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
299 _doubleRate2( (Sint16*)Data.buffer, Data.mode, length ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
300 return 4*_doubleRate2( (Sint16*)Data.buffer+1, Data.mode, length ); |
338 | 301 } |
302 | |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
303 static int doubleRateMono( AdapterC Data, int length ) |
338 | 304 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
305 return 2*_doubleRate1( (Sint16*)Data.buffer, Data.mode, length>>1 ); |
338 | 306 } |
307 | |
308 /*-------------------------------------------------------------------------*/ | |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
309 static int halfRateStereo( AdapterC Data, int length ) |
338 | 310 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
311 length >>= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
312 _halfRate2( (Sint16*)Data.buffer, Data.mode, length ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
313 return 4*_halfRate2( (Sint16*)Data.buffer+1, Data.mode, length ); |
338 | 314 } |
315 | |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
316 static int halfRateMono( AdapterC Data, int length ) |
338 | 317 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
318 return 2*_halfRate2( (Sint16*)Data.buffer, Data.mode, length>>1 ); |
338 | 319 } |
320 | |
321 /*-------------------------------------------------------------------------*/ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
322 static int varRateUpStereo( AdapterC Data, int length ) |
338 | 323 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
324 length >>= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
325 _varRateUp2( (Sint16*)Data.buffer, Data.mode, Data.filter, length ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
326 return 4 * _varRateUp2( (Sint16*)Data.buffer+1, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
327 Data.mode, Data.filter, length ); |
338 | 328 } |
329 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
330 static int varRateUpMono( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
331 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
332 return 2 * _varRateUp1( (Sint16*)Data.buffer, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
333 Data.mode, Data.filter, length>>1 ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
334 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
335 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
336 static int varRateDownStereo( AdapterC Data, int length ) |
338 | 337 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
338 length >>= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
339 _varRateDown2( (Sint16*)Data.buffer, Data.mode, Data.filter, length ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
340 return 2 * _varRateDown2( (Sint16*)Data.buffer+1, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
341 Data.mode, Data.filter, length ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
342 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
343 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
344 static int varRateDownMono( AdapterC Data, int length ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
345 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
346 return _varRateDown1( (Sint16*)Data.buffer, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
347 Data.mode, Data.filter, length>>1 ); |
338 | 348 } |
349 | |
350 /*-------------------------------------------------------------------------*/ | |
351 typedef struct{ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
352 Sint16 denominator; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
353 Sint16 numerator; |
338 | 354 } Fraction; |
355 | |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
356 static Fraction findFraction( float Value ) |
338 | 357 { |
358 /* gives a maximal error of 3% and typical less than 0.2% */ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
359 const Uint8 frac[96]={ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
360 1, 2, -1, /* /1 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
361 1, 3, -1, /* /2 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
362 2, 4, 5, -1, /* /3 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
363 3, 5, 7, -1, /* /4 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
364 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
|
365 5, 7, 11, -1, /* /6 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
366 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
|
367 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
|
368 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
|
369 7, 9, 11, 13, -1, /* /10 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
370 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
|
371 7, 11, 13, -1, /* /12 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
372 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
|
373 9, 11, 13, 15, -1, /* /14 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
374 8, 11, 13, 14, 16, -1, /* /15 */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
375 9, 11, 13, 15 }; /* /16 */ |
338 | 376 |
377 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
378 Fraction Result = {0,0}; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
379 int n,num,den=1; |
338 | 380 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
381 float RelErr, BestErr = 0; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
382 if( Value < 31/64. || Value > 64/31. ) return Result; |
338 | 383 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
384 for( n = 0; n < sizeof(frac); num=frac[++n] ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
385 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
386 if( num < 0 ) den++; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
387 RelErr = Value * num / den; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
388 RelErr = min( RelErr, 1/RelErr ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
389 if( RelErr > BestErr ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
390 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
391 BestErr = RelErr; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
392 Result.denominator = den; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
393 Result.numerator = num; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
394 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
395 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
396 return Result; |
338 | 397 } |
398 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
399 /*-------------------------------------------------------------------------*/ |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
400 static float sinc( float x ) |
338 | 401 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
402 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
|
403 else return sin(x)/x; |
338 | 404 } |
405 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
406 static void calculateVarFilter( Sint16* dst, float Ratio, float phase, float scale ) |
338 | 407 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
408 const Uint16 KaiserWindow7[]= { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
409 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
|
410 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
|
411 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
|
412 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
|
413 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
|
414 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
|
415 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
|
416 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
|
417 int i; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
418 float w; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
419 const float fg = -.018 + .5 * Ratio; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
420 const float omega = 2 * M_PI * fg; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
421 phase -= 63; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
422 for( i = 0; i < 64; i++) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
423 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
424 w = scale * ( KaiserWindow7[i] * ( i + 1 )); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
425 dst[i] = w * sinc( omega * (i+phase) ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
426 dst[127-i] = w * sinc( omega * (127-i+phase) ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
427 } |
338 | 428 } |
429 | |
430 typedef struct{ | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
431 float scale; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
432 int incr; |
338 | 433 } VarFilterMode; |
434 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
435 const VarFilterMode Up = { 0.0211952, -1 }; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
436 const VarFilterMode Down = { 0.0364733, 1 }; |
338 | 437 |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
438 static void setupVarFilter( VarFilter* filter, |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
439 float Ratio, VarFilterMode Direction ) |
338 | 440 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
441 int i,n,d; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
442 Fraction IRatio; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
443 float phase; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
444 IRatio = findFraction( Ratio ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
445 Ratio = min( Ratio, 1/Ratio ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
446 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
447 n = IRatio.numerator; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
448 d = IRatio.denominator; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
449 filter->pos_mod = d; |
338 | 450 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
451 for( i = 0; i < d; i++ ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
452 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
453 if( phase >= n ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
454 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
455 phase -= d; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
456 filter->incr[i] = Direction.incr; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
457 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
458 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
459 filter->incr[i] = 1+Direction.incr; |
338 | 460 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
461 calculateVarFilter( filter->c[i], Ratio, phase/(float)n, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
462 Direction.scale ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
463 phase += d; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
464 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
465 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
466 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
467 /*-------------------------------------------------------------------------*/ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
468 static void createRateConverter( Sound_AudioCVT *Data, int* fip, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
469 int SrcRate, int DestRate, int Channel ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
470 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
471 int filter_index = *fip; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
472 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
473 int VarPos = 0; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
474 int Mono = 2 - Channel; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
475 float Ratio = DestRate; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
476 *fip = -1; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
477 |
338 | 478 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
479 if( SrcRate < 1 || SrcRate > 1<<18 || |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
480 DestRate < 1 || DestRate > 1<<18 ) return; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
481 Ratio /= SrcRate; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
482 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
483 if( Ratio > 1.) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
484 VarPos = filter_index++; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
485 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
486 Data->adapter[filter_index++] = minus5dB; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
487 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
488 while( Ratio > 64./31.) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
489 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
490 Data->adapter[filter_index++] = |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
491 Mono ? doubleRateMono : doubleRateStereo; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
492 Ratio /= 2.; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
493 Data->len_mult *= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
494 Data->add *= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
495 Data->add += _fsize; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
496 } |
338 | 497 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
498 while( Ratio < 31./64. ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
499 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
500 Data->adapter[filter_index++] = |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
501 Mono ? halfRateMono : halfRateStereo; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
502 Ratio *= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
503 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
504 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
505 if( Ratio > 1. ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
506 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
507 setupVarFilter( &Data->filter, Ratio, Up ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
508 Data->adapter[VarPos] = |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
509 Mono ? varRateUpMono : varRateUpStereo; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
510 Data->len_mult *= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
511 Data->add *= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
512 Data->add += _fsize; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
513 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
514 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
515 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
516 setupVarFilter( &Data->filter, Ratio, Down ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
517 Data->adapter[filter_index++] = |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
518 Mono ? varRateDownMono : varRateDownStereo; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
519 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
520 *fip = filter_index; |
338 | 521 } |
522 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
523 /*-------------------------------------------------------------------------*/ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
524 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
|
525 SDL_AudioSpec src, SDL_AudioSpec dst ) |
338 | 526 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
527 int filter_index = *fip; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
528 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
529 if( src.channels == 2 && dst.channels == 1 ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
530 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
531 Data->add /= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
532 Data->len_mult /= 2; |
338 | 533 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
534 if( !IS_SYSENDIAN(src) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
535 Data->adapter[filter_index++] = swapBytes; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
536 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
537 if( IS_SIGNED(src) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
538 Data->adapter[filter_index++] = convertStereoToMonoS16Bit; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
539 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
540 Data->adapter[filter_index++] = convertStereoToMonoU16Bit; |
338 | 541 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
542 if( !IS_SYSENDIAN(dst) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
543 Data->adapter[filter_index++] = swapBytes; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
544 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
545 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
|
546 Data->adapter[filter_index++] = swapBytes; |
338 | 547 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
548 if( IS_SIGNED(src) != IS_SIGNED(dst) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
549 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
550 if( IS_SYSENDIAN(dst) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
551 Data->adapter[filter_index++] = changeSigned16BitSys; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
552 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
553 Data->adapter[filter_index++] = changeSigned16BitSys; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
554 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
555 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
556 if( src.channels == 1 && dst.channels == 2 ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
557 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
558 Data->add *= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
559 Data->len_mult *= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
560 Data->adapter[filter_index++] = convertMonoToStereo16Bit; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
561 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
562 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
563 *fip = filter_index; |
338 | 564 } |
565 | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
566 /*-------------------------------------------------------------------------*/ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
567 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
|
568 SDL_AudioSpec src, SDL_AudioSpec dst ) |
338 | 569 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
570 int filter_index = *fip; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
571 if( IS_16BIT(src) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
572 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
573 Data->add /= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
574 Data->len_mult /= 2; |
338 | 575 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
576 if( IS_SYSENDIAN(src) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
577 Data->adapter[filter_index++] = cut16BitSysTo8Bit; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
578 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
579 Data->adapter[filter_index++] = cut16BitWrongTo8Bit; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
580 } |
338 | 581 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
582 if( src.channels == 2 && dst.channels == 1 ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
583 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
584 Data->add /= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
585 Data->len_mult /= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
586 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
587 if( IS_SIGNED(src) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
588 Data->adapter[filter_index++] = convertStereoToMonoS8Bit; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
589 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
590 Data->adapter[filter_index++] = convertStereoToMonoU8Bit; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
591 } |
338 | 592 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
593 if( IS_SIGNED(src) != IS_SIGNED(dst) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
594 Data->adapter[filter_index++] = changeSigned8Bit; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
595 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
596 if( src.channels == 1 && dst.channels == 2 ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
597 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
598 Data->add *= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
599 Data->len_mult *= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
600 Data->adapter[filter_index++] = convertMonoToStereo8Bit; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
601 } |
338 | 602 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
603 if( !IS_8BIT(dst) ) |
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 Data->add *= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
606 Data->len_mult *= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
607 if( IS_SYSENDIAN(dst) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
608 Data->adapter[filter_index++] = expand8BitTo16BitSys; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
609 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
610 Data->adapter[filter_index++] = expand8BitTo16BitWrong; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
611 } |
338 | 612 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
613 *fip = filter_index; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
614 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
615 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
616 /*-------------------------------------------------------------------------*/ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
617 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
|
618 SDL_AudioSpec src, SDL_AudioSpec dst ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
619 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
620 int filter_index = *fip; |
338 | 621 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
622 if( IS_FLOAT(src) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
623 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
624 Data->adapter[filter_index++] = cutFloatTo16Bit; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
625 Data->len_mult /= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
626 Data->add /= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
627 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
628 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
629 if( IS_8BIT(src) || IS_8BIT(dst) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
630 createFormatConverter8Bit( Data, &filter_index, src, dst); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
631 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
632 createFormatConverter16Bit( Data, &filter_index, src, dst); |
338 | 633 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
634 if( IS_FLOAT(dst) ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
635 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
636 Data->adapter[filter_index++] = expand16BitToFloat; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
637 Data->len_mult *= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
638 Data->add *= 2; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
639 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
640 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
641 *fip = filter_index; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
642 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
643 |
338 | 644 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
645 /*-------------------------------------------------------------------------*/ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
646 DECLSPEC int BuildAudioCVT(Sound_AudioCVT *Data, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
647 SDL_AudioSpec src, SDL_AudioSpec dst ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
648 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
649 SDL_AudioSpec intrm; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
650 int filter_index = 0; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
651 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
652 if( Data == NULL ) return -1; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
653 Data->len_mult = 1.; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
654 Data->add = 0; |
338 | 655 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
656 /* Check channels */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
657 if( src.channels < 1 || src.channels > 2 || |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
658 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
|
659 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
660 /* 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
|
661 if( src.freq == dst.freq ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
662 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
663 createFormatConverter( Data, &filter_index, src, dst ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
664 goto sucess_exit; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
665 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
666 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
667 /* Convert to signed 16Bit System-Endian */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
668 intrm.format = AUDIO_S16SYS; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
669 intrm.channels = min( src.channels, dst.channels ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
670 createFormatConverter( Data, &filter_index, src, intrm ); |
338 | 671 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
672 /* Do rate conversion */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
673 if( src.channels == 2 && dst.channels == 2 ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
674 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
|
675 else |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
676 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
|
677 /* propagate error */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
678 if( filter_index < 0 ) goto error_exit; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
679 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
680 /* Convert to final format */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
681 createFormatConverter( Data, &filter_index, intrm, dst ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
682 |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
683 /* Set up the filter information */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
684 sucess_exit: |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
685 /* !!! 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
|
686 Borland says no. -frank */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
687 Data->adapter[filter_index] = NULL; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
688 return 0; |
338 | 689 |
690 error_exit: | |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
691 /* !!! 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
|
692 Borland says no. -frank */ |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
693 Data->adapter[0] = NULL; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
694 return -1; |
338 | 695 } |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
696 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
697 /*-------------------------------------------------------------------------*/ |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
698 static char *fmt_to_str(Uint16 fmt) |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
699 { |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
700 switch (fmt) |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
701 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
702 case AUDIO_U8: return " U8"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
703 case AUDIO_S8: return " S8"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
704 case AUDIO_U16MSB: return "U16MSB"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
705 case AUDIO_S16MSB: return "S16MSB"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
706 case AUDIO_U16LSB: return "U16LSB"; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
707 case AUDIO_S16LSB: return "S16LSB"; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
708 } |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
709 return "??????"; |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
710 } |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
711 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
712 #define AdapterDesc(x) { x, #x } |
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 static void show_AudioCVT( Sound_AudioCVT *Data ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
715 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
716 int i,j; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
717 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
|
718 AdapterDescription[] = { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
719 AdapterDesc(expand8BitTo16BitSys), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
720 AdapterDesc(expand8BitTo16BitWrong), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
721 AdapterDesc(expand16BitToFloat), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
722 AdapterDesc(swapBytes), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
723 AdapterDesc(cut16BitSysTo8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
724 AdapterDesc(cut16BitWrongTo8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
725 AdapterDesc(cutFloatTo16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
726 AdapterDesc(changeSigned16BitSys), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
727 AdapterDesc(changeSigned16BitWrong), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
728 AdapterDesc(changeSigned8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
729 AdapterDesc(convertStereoToMonoS16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
730 AdapterDesc(convertStereoToMonoU16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
731 AdapterDesc(convertStereoToMonoS8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
732 AdapterDesc(convertStereoToMonoU8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
733 AdapterDesc(convertMonoToStereo16Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
734 AdapterDesc(convertMonoToStereo8Bit), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
735 AdapterDesc(minus5dB), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
736 AdapterDesc(doubleRateStereo), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
737 AdapterDesc(doubleRateMono), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
738 AdapterDesc(halfRateStereo), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
739 AdapterDesc(halfRateMono), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
740 AdapterDesc(varRateUpStereo), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
741 AdapterDesc(varRateUpMono), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
742 AdapterDesc(varRateDownStereo), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
743 AdapterDesc(varRateDownMono), |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
744 { NULL, "----------NULL-----------" } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
745 }; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
746 const int AdapterDescMax = sizeof(AdapterDescription) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
747 / sizeof(*AdapterDescription); |
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 fprintf( stderr, "\nAdapter List: \n" ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
750 for( i = 0; i < 32; i++ ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
751 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
752 for( j = 0; j < AdapterDescMax; j++ ) |
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( Data->adapter[i] == AdapterDescription[j].adapter ) |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
755 { |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
756 fprintf( stderr, " %s\n", AdapterDescription[j].name ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
757 if( Data->adapter[i] == NULL ) return; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
758 goto cont; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
759 } |
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 fprintf( stderr, " Error: unknown adapter\n" ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
762 cont: |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
763 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
764 fprintf( stderr, " Error: NULL adapter missing\n" ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
765 } |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
766 |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
767 |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
768 int Sound_BuildAudioCVT(Sound_AudioCVT *Data, |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
769 Uint16 src_format, Uint8 src_channels, int src_rate, |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
770 Uint16 dst_format, Uint8 dst_channels, int dst_rate) |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
771 { |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
772 SDL_AudioSpec src, dst; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
773 int ret; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
774 |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
775 fprintf (stderr, |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
776 "Sound_BuildAudioCVT() :\n" |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
777 "-----------------------\n" |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
778 "format: %s -> %s\n" |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
779 "channels: %6d -> %6d\n" |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
780 "rate: %6d -> %6d\n", |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
781 fmt_to_str (src_format), fmt_to_str (dst_format), |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
782 src_channels, dst_channels, |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
783 src_rate, dst_rate); |
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
784 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
785 src.format = src_format; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
786 src.channels = src_channels; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
787 src.freq = src_rate; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
788 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
789 dst.format = dst_format; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
790 dst.channels = dst_channels; |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
791 dst.freq = dst_rate; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
792 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
793 ret = BuildAudioCVT( Data, src, dst ); |
347
778cee61e1be
Mono-to-stereo fixes, more fprintf debugging output.
Ryan C. Gordon <icculus@icculus.org>
parents:
342
diff
changeset
|
794 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
795 show_AudioCVT( Data ); |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
796 fprintf (stderr, "\n" |
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
797 "return value: %d \n", ret ); |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
798 |
360
c984aa6990f7
Fixes and enhancements from Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
799 return ret; |
342
fbbb1f25b944
Cleanups by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
338
diff
changeset
|
800 } |