annotate alt_audio_convert.c @ 371:1b463ef9bcc2

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