annotate alt_audio_convert.c @ 416:41412aa092d1

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